Description Usage Arguments Value Note See Also Examples
This is a model driver for flexmix
from package flexmix implementing mixtures of Quadratic Discriminant Analysis Models.
1 2 3 4 |
formula |
A formula which is interpreted relative to the formula specified in the call to |
... |
Further arguments to and from other methods. |
Returns an object of class FLXMCLqda
inheriting from FLXMCL
.
This method internally calls function wqda
. method = "ML"
is hard-coded.
Other mixtures qda: FLXMCL-class
Other mixtures qda: FLXMCL-class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | library(benchData)
data <- flashData(1000)
x1 <- seq(-6,6,0.2)
x2 <- seq(-4,4,0.2)
grid <- expand.grid(x.1 = x1, x.2 = x2)
cluster <- kmeans(data$x, center = 2)$cluster
model <- FLXMCLqda()
fit <- flexmix(y ~ ., data = as.data.frame(data), model = model, cluster = cluster, control = list(verb = 1))
## prediction for single component models without aggregation
pred.grid <- predict(fit, newdata = grid)
# joint density of predictors and class variable for class 1
image(x1, x2, matrix(pred.grid[[1]][,1], length(x1)))
contour(x1, x2, matrix(pred.grid[[1]][,1], length(x1)), add = TRUE)
points(data$x, pch = as.character(data$y))
image(x1, x2, matrix(pred.grid[[2]][,1], length(x1)))
contour(x1, x2, matrix(pred.grid[[2]][,1], length(x1)), add = TRUE)
points(data$x, pch = as.character(data$y))
# posterior probability of class 1
pred.grid <- lapply(pred.grid, function(x) x/rowSums(x))
image(x1, x2, matrix(pred.grid[[1]][,1], length(x1)))
contour(x1, x2, matrix(pred.grid[[1]][,1], length(x1)), add = TRUE)
points(data$x, pch = as.character(data$y))
image(x1, x2, matrix(pred.grid[[2]][,1], length(x1)))
contour(x1, x2, matrix(pred.grid[[2]][,1], length(x1)), add = TRUE)
points(data$x, pch = as.character(data$y))
## prediction with aggregation depending on membership in mixture components
pred.grid <- mypredict(fit, newdata = grid, aggregate = TRUE)
# joint density of predictors and class variable for class 1
image(x1, x2, matrix(pred.grid[[1]][,1], length(x1)))
contour(x1, x2, matrix(pred.grid[[1]][,1], length(x1)), add = TRUE)
points(data$x, pch = as.character(data$y))
# posterior of class 1
pred.grid <- lapply(pred.grid, function(x) x/rowSums(x))
image(x1, x2, matrix(pred.grid[[1]][,1], length(x1)))
contour(x1, x2, matrix(pred.grid[[1]][,1], length(x1)), add = TRUE)
points(data$x, pch = as.character(data$y))
## local membership
grid <- cbind(y = flashBayesClass(grid), grid)
loc.grid <- posterior(fit, newdata = grid)
contour(x1, x2, matrix(loc.grid[,1], length(x1)), add = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.