# Specify number of linear discriminants in R MASS lda function

I have a matrix with 1024 features and 10000 samples with a label vector of three different classes. I use R MASS library lda function to compute the model and get the coefficients for linear discriminants:

> library (MASS)
>
> ldamodel = lda(data$X, data$y)
> head (ldamodel$scaling) LD1 LD2 V5 -0.053074978 0.14565211 V6 -0.009618016 -0.11198306 V7 -0.003863230 0.28189459 V8 0.063191889 -0.26726050 V9 -0.029950632 0.16121364 V10 0.017988965 -0.01584389 ...  The model has two linear discriminants, which is ok. But I'd like to know, if it is possible make the lda function create more than two linear discriminants and how to do it in R? I'm not yet very faimiliar with LDA, so I'm sorry, if this question is a statistical nonsense. - add comment ## 2 Answers LDA finds at most$k - 1$linear discriminants, where$k$is the number of classes. In your data you state you have three classes hence only 2 linear discriminants can be resolved. - In addition, there are at most as many linear discriminants as there are predictors (features). – caracal May 29 '12 at 20:47 add comment I could easily produce more than two LD so I guess here the issue is your call lda(data$X, data$y) or your data. What are$X$and$y$in your case? To me it looks like you have 1024 classes and two predictors. If data is a 10,000 x$m$data.frame and C is your vector of classes (length 10,000) you have to call the function as follows ldamodel <- lda(data, C)  Then you should see$m$LD. I guess the problem is that your data$y has only two columns. Now if you have only two predictors, you cannot get more linear discriminants...

EDIT: Sorry about this answer, I got confused between the number of classes and the number of predictors. You should see as many LD as unique(C) - 1, and not $m$. The length of each of them should be $m$. And of course, you cannot get more linear discriminants as unique(C) - 1.

-
$X$ is a matrix with 10000 rows and 1024 columns. $y$ is a factor vector of length 10000 with three different values. What did you mean by guessing that $y$ has only two columns? –  Timo May 29 '12 at 20:24