lda(formula, data, prior = proportions, tol = 1.0e-4, subset, na.action = na.fail, method, CV = F, nu) lda(x, grouping, prior = proportions, tol = 1.0e-4, subset, na.action = na.fail, method, CV = F, nu)
groups ~ x1 + x2 +
...
. That is, the response is the grouping factor and
the right hand side specifies the (non-factor)
discriminators. Note: Because of the strict rules of
pattern-matching in S4, this argument should not be named.
formula
are preferentially to be
taken. Note: Because of the strict rules of
pattern-matching in S4, this argument should not be named.
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"
.
"lda"
containing the
following slots:
unless
CV=T
, when the return value is a
list with components:
The function tries hard to detect if the within-class covariance
matrix is singular. If any variable has within-group variance less
than
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.
This function may be called giving either a formula and optional data
frame, or a matrix and grouping factor as the first two arguments.
All other arguments are optional, but
subset=
and
na.action=
, if required, must be fully named.
If a formula is given as the principal argument the object may be
modified using
update()
in the usual way.
Iris <- data.frame(rbind(iris[,,1], iris[,,2], iris[,,3]), Sp = rep(c("s","c","v"), rep(50,3))) train <- sample(1:150, 75) table(Iris$Sp[train]) z <- lda(Sp ~ ., Iris, prior = c(1,1,1)/3, subset = train) predict(z, Iris[-train, ])$class z1 <- update(z, . ~ . - Petal.W.)