View source: R/densityMclustBounded.R
predict.densityMclustBounded | R Documentation |
Compute density estimation for univariate and multivariate bounded data based on Gaussian finite mixture models estimated by densityMclustBounded
.
## S3 method for class 'densityMclustBounded' predict(object, newdata, what = c("dens", "cdens", "z"), logarithm = FALSE, ...)
object |
An object of class |
newdata |
A numeric vector, matrix, or data frame of observations. If missing the density is computed for the input data obtained from the call to |
what |
A character string specifying what to retrieve: |
logarithm |
A logical value indicating whether or not the logarithm of the densities/probabilities should be returned. |
... |
Further arguments passed to or from other methods. |
Returns a vector or a matrix of values evaluated at newdata
depending on the argument what
(see above).
Luca Scrucca
Scrucca L. (2019) A transformation-based approach to Gaussian mixture density estimation for bounded data. Biometrical Journal, 61:4, 873–888. https://doi.org/10.1002/bimj.201800174
densityMclustBounded
,
plot.densityMclustBounded
.
y <- sample(0:1, size = 200, replace = TRUE, prob = c(0.6, 0.4)) x <- y*rchisq(200, 3) + (1-y)*rchisq(200, 10) dens <- densityMclustBounded(x, lbound = 0) summary(dens) plot(dens, what = "density", data = x, breaks = 11) xgrid <- seq(0, max(x), length = 201) densx <- predict(dens, newdata = xgrid, what = "dens") cdensx <- predict(dens, newdata = xgrid, what = "cdens") cdensx <- sweep(cdensx, MARGIN = 2, FUN = "*", dens$parameters$pro) plot(xgrid, densx, type = "l", lwd = 2) matplot(xgrid, cdensx, type = "l", col = 3:4, lty = 2:3, lwd = 2, add = TRUE) z <- predict(dens, newdata = xgrid, what = "z") matplot(xgrid, z, col = 3:4, lty = 2:3, lwd = 2, ylab = "Posterior probabilities")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.