lda | R Documentation |
Probabilistic (parametric) linear and quadratic discriminant analysis.
For each observation to predict, the posterior probability to belong to a given class is estimated using the Bayes' formula, assuming priors (proportional or uniform) and a multivariate Normal distribution for the dependent variables X
. The prediction is the class with the highest posterior probability.
LDA assumes homogeneous X-
covariance matrices for the classes while QDA assumes different covariance matrices. The functions use dmnorm
for estimating the multivariate Normal densities.
lda(X, y, prior = c("unif", "prop"))
qda(X, y, prior = c("unif", "prop"))
## S3 method for class 'Lda'
predict(object, X, ...)
## S3 method for class 'Qda'
predict(object, X, ...)
X |
For the main functions: Training X-data ( |
y |
Training class membership ( |
prior |
The prior probabilities of the classes. Possible values are "unif" (default; probabilities are set equal for all the classes) or "prop" (probabilities are set equal to the observed proportions of the classes in |
object |
A fitted model, output of a call to the main functions. |
... |
Optional arguments. Not used. |
See the examples.
Saporta, G., 2011. Probabilités analyse des données et statistique. Editions Technip, Paris, France.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
data(iris)
X <- iris[, 1:4]
y <- iris[, 5]
N <- nrow(X)
m <- round(.25 * N) # Test
n <- N - m # Training
s <- sample(1:N, m)
Xtrain <- X[-s, ]
ytrain <- y[-s]
Xtest <- X[s, ]
ytest <- y[s]
prior <- "unif"
#prior <- "prop"
fm <- lda(Xtrain, ytrain, prior = prior)
res <- predict(fm, Xtest)
names(res)
headm(res$pred)
headm(res$ds)
headm(res$posterior)
err(res$pred, ytest)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.