lda(x, …)# S3 method for formula
lda(formula, data, …, subset, na.action)
# S3 method for default
lda(x, grouping, prior = proportions, tol = 1.0e-4,
method, CV = FALSE, nu, …)
# S3 method for data.frame
lda(x, …)
# S3 method for matrix
lda(x, grouping, …, subset, na.action)
groups ~ x1 + x2 + …
That is, the
response is the grouping factor and the right hand side specifies
the (non-factor) discriminators.
formula
are
preferentially to be taken.
tol^2
.
NA
s are found.
The default action is for the procedure to fail. An alternative is
na.omit
, which leads to rejection of cases with missing values on
any required variable. (NOTE: If given, this argument must be named.)
"moment"
for standard estimators of the mean and variance,
"mle"
for MLEs, "mve"
to use cov.mve
, or
"t"
for robust estimates based on a \(t\) distribution.
method = "t"
.
CV = TRUE
the return value is a list with components
class
, the MAP classification (a factor), and posterior
,
posterior probabilities for the classes. Otherwise it is an object of class "lda"
containing the
following components:
tol^2
it will stop and report the variable as constant. This
could result from poor scaling of the problem, but is more
likely to result from constant variables. Specifying the prior
will affect the classification unless
over-ridden in predict.lda
. Unlike in most statistical packages, it
will also affect the rotation of the linear discriminants within their
space, as a weighted between-groups covariance matrix is used. Thus
the first few linear discriminants emphasize the differences between
groups with the weights given by the prior, which may differ from
their prevalence in the dataset. If one or more groups is missing in the supplied data, they are dropped
with a warning, but the classifications produced are with respect to the
original set of levels.predict.lda
, qda
, predict.qda
Iris <- data.frame(rbind(iris3[,,1], iris3[,,2], iris3[,,3]),
Sp = rep(c("s","c","v"), rep(50,3)))
train <- sample(1:150, 75)
table(Iris$Sp[train])
## your answer may differ
## c s v
## 22 23 30
z <- lda(Sp ~ ., Iris, prior = c(1,1,1)/3, subset = train)
predict(z, Iris[-train, ])$class
## [1] s s s s s s s s s s s s s s s s s s s s s s s s s s s c c c
## [31] c c c c c c c v c c c c v c c c c c c c c c c c c v v v v v
## [61] v v v v v v v v v v v v v v v
(z1 <- update(z, . ~ . - Petal.W.))
Run the code above in your browser using DataLab