predict.dalda: Classify Multivariate Observations Based on Discriminant...

Description Usage Arguments Details Value References See Also Examples

View source: R/dalda.R

Description

Classify multivariate observations in conjunction with dalda.

Usage

1
predict.dalda(object, newdata, ...)

Arguments

object

Object of class "dalda".

newdata

A data.frame of cases to be classified or, if object has a formula, a data.frame with columns of the same names as the variables used. A vector will be interpreted as a row vector. If newdata is missing, an attempt will be made to retrieve the data used to fit the dalda object.

...

Further arguments.

Details

This function is a method for the generic function predict() for class "dalda". It can be invoked by calling predict(x) for an object x of the appropriate class, or directly by calling predict.dalda(x) regardless of the class of the object.

Value

A list with components:

class

The predicted class labels (a factor).

posterior

Matrix of class posterior probabilities.

References

Hand, D. J., Vinciotti, V. (2003), Local versus global models for classification problems: Fitting models where it matters, The American Statistician, 57(2) 124–130.

See Also

dalda, wlda, dalr.

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
## comparison with lda:
library(MASS)
fit1 <- lda(Species ~ Sepal.Length + Sepal.Width, data = iris)
pred <- predict(fit1)
mean(pred$class != iris$Species)

fit2 <- dalda(Species ~ Sepal.Length + Sepal.Width, data = iris,
    wf = "gaussian", bw = 0.5)
pred <- predict(fit2)
mean(pred$class != iris$Species)

## plot of decision boundary (maximum posterior probabilities):
grid <- expand.grid(Sepal.Length = seq(4,8,0.1), Sepal.Width = seq(2,5,0.1)) 

predgrid1 <- predict(fit1, newdata = grid)$posterior
predgrid2 <- predict(fit2, newdata = grid)$posterior

par(mfrow = c(1,2))
contour(seq(4,8,0.1), seq(2,5,0.1), 
    matrix(as.numeric(apply(predgrid1, 1, max)), nrow = length(seq(4,8,0.1))))
contour(seq(4,8,0.1), seq(2,5,0.1), 
    matrix(as.numeric(apply(predgrid2, 1, max)), nrow = length(seq(4,8,0.1))))
points(iris$Sepal.Length, iris$Sepal.Width, pch = 19, 
    cex = fit2$weights[[3]]*2, col = as.numeric(iris$Species))

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