Re: [R] Question on lda and predict

From: Peter Flom <peterf_at_brainscope.com>
Date: Tue, 10 Jun 2008 08:53:07 -0700

I wrote
> Hello
>
> Using R 2.7.0 on Windows.
>
> I am running a linear discriminant analysis as follows
>
> <<<<
> discrim1 <- lda(normvar~ mafmahal+ mrfmahal+ mffmahal+ bafmahal+ brfmahal+
> cofmahal+ bmfmahal+ cfmahal+ fractmahal+ antmahal+ absmifmahal+ absifmahal, subset = train)
> prediction <- predict(discrim1, traintest1[-train,])$class
>
> When I do this, I get a warning message:
>
> <<<
> Warning message:
> 'newdata' had 795 rows but variable(s) found have 796 rows
>
> However, when I look at 'newdata' (i.e. traintest1) with dim, I find it has 796 rows:
>
> <<<

>> dim(traintest1)

> [1] 796 612
>

What happens when you do

dim(traintest1[-train,])

?

> So, I do not understand the warning.
>
> Thanks for any explanation or assistance
>

I still don't understand this, as I thought I was following the example in predict.lda; but I did figure out how to avoid it:

<<<
test <- traintest1[train == 0,]
prediction <- predict(discrim1, test)$class prediction <- prediction[train == 0]

table(prediction, normvar[train == 0])
>>>

Peter

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 10 Jun 2008 - 17:42:11 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 10 Jun 2008 - 18:30:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive