FLXMCLqda: Mixtures of Quadratic Discriminant Analysis Models

Description Usage Arguments Value Note See Also Examples

View source: R/FLXMCLqda.R

Description

This is a model driver for flexmix from package flexmix implementing mixtures of Quadratic Discriminant Analysis Models.

Usage

1
2
3
4
FLXMCLqda(formula = . ~ ., ...)

## S4 method for signature 'FLXMCLqda'
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.

Value

Returns an object of class FLXMCLqda inheriting from FLXMCL.

Note

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

See Also

Other mixtures qda: FLXMCL-class

Other mixtures qda: FLXMCL-class

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

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