[R] help with predict.lda

Peter Ehlers ehlers at ucalgary.ca
Sun Jul 4 11:47:40 CEST 2010


On 2010-07-03 21:33, Changbin Du wrote:
> HI, Dear community,
>
> I am using the linear discriminant analysis to build model and make new
> predictions:
>
>> dim(train)  #training data
> [1] 1272   22
>> dim(valid)  # validation data
> [1] 140  22
>
>
> lda.fit<- lda(out ~ ., data=train, na.action="na.omit", CV=TRUE) # model
> fitting of linear discriminant analysis on training data
>
>> predict(lda.fit, valid)   # make prediction on validation data
> Error in UseMethod("predict") :
>    no applicable method for 'predict' applied to an object of class "list"
>
> Can anyone help with this?

Suggestions:

0. lda() is not a function in the base installation of R;
    I'll assume that you mean MASS::lda.

1. ask yourself what you expect from setting CV = TRUE.

2. *carefully* (re)read the help pages for lda (especially
    the Value section) and for predict.lda (the 'object'
    definition).

3. use CV = FALSE

4. whenever problems arise, *first* use str() on your
    objects to see what you've got.

5. finally, do provide *reproducible* code; here, you
    could have used the example on the help page.

   -Peter Ehlers

>
> Thanks so much!
>



More information about the R-help mailing list