FLXMCLmajorityGenerative: Common Components Model

Description Usage Arguments Value Note See Also Examples

View source: R/FLXMCLmajorityGenerative.R

Description

This is a model driver for flexmix from package flexmix implementing the Common Components Model.

Usage

1
2
3
4
5
FLXMCLmajorityGenerative(formula = . ~ ., ...)

## S4 method for signature 'FLXMCLmajorityGenerative'
FLXgetModelmatrix(model, data, formula,
  lhs = TRUE, ...)

Arguments

formula

A formula which is interpreted relative to the formula specified in the call to flexmix using update.formula. Only the left-hand side (response) of the formula is used. Default is to use the original flexmix model formula.

...

Further arguments to and from other methods, especially majorityGenerative.

Value

Returns an object of class FLXMCLmajorityGenerative inheriting from FLXMCL.

Note

This method internally calls function majorityGenerative. method = "ML" is hard-coded.

See Also

Other mixtures majority: FLXMCL-class, FLXMCLmajority

Other mixtures majority: FLXMCL-class, FLXMCLmajority

Examples

 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))

schiffner/locClass documentation built on May 29, 2019, 3:39 p.m.