density                package:mclust                R Documentation

_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:

     This is exactly the same function as in the 'stats' package but
     for the 'method' argument: if it is given and equals '"mclust"',
     the 'mclust' density estimation is used. Optionally, the number of
     gaussians to be considered can be given as well ('G').

_U_s_a_g_e:

     density(..., method, G)

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

     ...: Arguments to the 'density' function in the base package.

  method: If equal to "mclust", 'EMclust' is used to estimate the
          density.

       G: The number of gaussians to consider in the model-based
          density estimation. Default: 1:9. Ignored if method is not
          equal to "mclust".

_V_a_l_u_e:

     If 'give.Rkern' is true, the number R(K), otherwise an object with
     class '"density"' whose underlying structure is a list containing
     the following components. 

       x: the 'n' coordinates of the points where the density is
          estimated.

       y: the estimated density values.

      bw: the bandwidth used.

       N: the sample size after elimination of missing values.

    call: the call which produced the result.

data.name: the deparsed name of the 'x' argument.

  has.na: logical, for compatibility (always FALSE).

_R_e_f_e_r_e_n_c_e_s:

     Fraley, C. and Raftery, A.E. (2002) MCLUST: software for
     model-based clustering, density estimation and discriminant
     analysis. Technical Report No. 415, Dept. of Statistics,
     University of Washington.

     Scott, D. W. (1992) _Multivariate Density Estimation. Theory,
     Practice and Visualization_. New York: Wiley.

     Sheather, S. J. and Jones M. C. (1991) A reliable data-based
     bandwidth selection method for kernel density estimation. _J. Roy.
     Statist. Soc._ *B*, 683-690.

     Silverman, B. W. (1986) _Density Estimation_. London: Chapman and
     Hall.

     Venables, W. N. and Ripley, B. D. (1999) _Modern Applied
     Statistics with S-PLUS_. New York: Springer.

_S_e_e _A_l_s_o:

     'density' (base package), 'bw.nrd', 'plot.density', 'hist'.

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

     plot(density(c(-20,rep(0,98),20)), xlim = c(-4,4))# IQR = 0

     # The Old Faithful geyser data
     data(faithful)
     d <- density(faithful$eruptions, bw = "sj")
     d
     plot(d)
     dmc <- density(faithful$eruptions, method="mclust")
     plot(dmc, type = "n")
     polygon(dmc, col = "wheat")
     lines(d, col="red")

     ## Missing values:
     x <- xx <- faithful$eruptions
     x[i.out <- sample(length(x), 10)] <- NA
     doRmc <- density(x=x, method="mclust", na.rm = TRUE)
     lines(doRmc, col="blue")
     doR <- density(x, bw = 0.15, na.rm = TRUE)
     lines(doR, col = "green")
     rug(x)
     points(xx[i.out], rep(0.01, 10))

     ## function formals returns something different now the original
     ## density function is masked...
     base.density <- if(exists("density", envir = NULL)) {
       get("density", envir = NULL)
     } else if (methods::existsFunction("density.default",
                                       where = asNamespace("stats")))
                stats::density.default else stats::density

     (kernels <- eval(formals(base.density)$kernel))

     ## show the kernels in the R parametrization
     plot (density(0, bw = 1), xlab = "",
           main="R's density() kernels with bw = 1")
     for(i in 2:length(kernels))
        lines(density(0, bw = 1, kern =  kernels[i]), col = i)
     legend(1.5,.4, legend = kernels, col = seq(kernels),
            lty = 1, cex = .8, y.int = 1)

     data(precip)
     bw <- bw.SJ(precip) ## sensible automatic choice
     plot(density(precip, bw = bw, n = 2^13))
     lines(density(precip, G=2:5, method="mclust"), col="red")
     rug(precip)

