After completing a linear discriminant analysis in R using lda()
, is there a convenient way to extract the classification functions for each group?
From the link,
These are not to be confused with the discriminant functions. The classification functions can be used to determine to which group each case most likely belongs. There are as many classification functions as there are groups. Each function allows us to compute classification scores for each case for each group, by applying the formula:
Si = ci + wi1*x1 + wi2*x2 + ... + wim*xm
In this formula, the subscript i denotes the respective group; the subscripts 1, 2, ..., m denote the m variables; ci is a constant for the i'th group, wij is the weight for the j'th variable in the computation of the classification score for the i'th group; xj is the observed value for the respective case for the j'th variable. Si is the resultant classification score.
We can use the classification functions to directly compute classification scores for some new observations.
I can build them from scratch using textbook formulas, but that requires rebuilding a number of intermediate steps from the lda analysis. Is there a way to get them after the fact from the lda object?
Added:
Unless I'm still misunderstanding something in Brandon's answer (sorry for the confusion!), it appears the answer is no. Presumably the majority of users can get the information they need from predict()
, which provides classifications based on lda()
.
MASS:::predict.lda
. There are actually three different versions. The default method is to use "plug-in". There is an additional term oflog(priors)
that I'm not seeing represented above. There is also an exponentiation step, but distance measures should maintain their desired properties under a transformation by a convex function. I think such a step might be needed to maintain rowSums ==1 for the $posterior matrix that is part of the result. – IRTFM