

kde2d(MASS)                                  R Documentation

_T_w_o_-_D_i_m_e_n_s_i_o_n_a_l _K_e_r_n_e_l _D_e_n_s_i_t_y _E_s_t_i_m_a_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n_:

     Two-dimensional kernel density estimation with an axis-
     aligned bivariate normal kernel, evaluated on a square
     grid.

_U_s_a_g_e_:

     kde2d(x, y, h, n=25, lims=c(range(x), range(y)))

_A_r_g_u_m_e_n_t_s_:

       x: x coordinate of data

       y: y coordinate of data

       h: vector of bandwidths for x and y directions.
          Defaults to normal reference bandwidth.

       n: Number of grid points in each direction.

    lims: The limits of the rectangle covered by the grid as
          `c(xl, xu, yl, yu)'.

_V_a_l_u_e_:

     A list of three components.

      x,: The x and y coordinates of the grid points, vec-
          tors of length `n'.

       z: An `n'  x  `n' matrix of the evaluated density.

_E_x_a_m_p_l_e_s_:

     data(geyser)
     attach(geyser)
     plot(duration, waiting, xlim=c(0.5,6), ylim=c(40,100))
     f1 <- kde2d(duration, waiting, n=50, lims=c(0.5,6,40,100))
     image(f1, zlim = c(0, 0.05))
     f2 <- kde2d(duration, waiting, n=50, lims=c(0.5,6,40,100),
        h = c(width.SJ(duration), width.SJ(waiting)) )
     image(f2, zlim = c(0, 0.05))
     persp(f2, phi=30, theta=20, d=5)

     plot(duration[-272], duration[-1], xlim=c(0.5, 6),
         ylim=c(1, 6),xlab="previous duration", ylab="duration")
     f1 <- kde2d(duration[-272], duration[-1],
        h=rep(1.5, 2), n=50, lims=c(0.5,6,0.5,6))
     contour(f1 ,xlab="previous duration",
         ylab="duration", levels = c(0.05, 0.1, 0.2, 0.4) )
     f1 <- kde2d(duration[-272], duration[-1],
        h=rep(0.6, 2), n=50, lims=c(0.5,6,0.5,6))
     contour(f1 ,xlab="previous duration",
         ylab="duration", levels = c(0.05, 0.1, 0.2, 0.4) )
     f1 <- kde2d(duration[-272], duration[-1],
        h=rep(0.4, 2), n=50, lims=c(0.5,6,0.5,6))
     contour(f1 ,xlab="previous duration",
         ylab="duration", levels = c(0.05, 0.1, 0.2, 0.4) )
     detach("geyser")

