Description Usage Arguments Value Note See Also Examples
View source: R/FLXMCLmajorityGenerative.R
This is a model driver for flexmix
from package flexmix implementing the Common Components Model.
1 2 3 4 5 |
formula |
A formula which is interpreted relative to the formula specified in the call to |
... |
Further arguments to and from other methods, especially |
Returns an object of class FLXMCLmajorityGenerative
inheriting from FLXMCL
.
This method internally calls function majorityGenerative
. method = "ML"
is hard-coded.
Other mixtures majority: FLXMCL-class
,
FLXMCLmajority
Other mixtures majority: FLXMCL-class
,
FLXMCLmajority
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 | 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 = 4)$cluster
model <- FLXMCLmajorityGenerative()
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))
image(x1, x2, matrix(pred.grid[[3]][,1], length(x1)))
contour(x1, x2, matrix(pred.grid[[3]][,1], length(x1)), add = TRUE)
points(data$x, pch = as.character(data$y))
image(x1, x2, matrix(pred.grid[[4]][,1], length(x1)))
contour(x1, x2, matrix(pred.grid[[4]][,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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.