[R] regularized dfa rda (Klar): problems with predictions
Uwe Ligges
ligges at statistik.tu-dortmund.de
Mon Feb 28 18:27:56 CET 2011
On 27.02.2011 22:59, Daniel Stahl wrote:
> Dear all, I am trying to do a n-fold cross-validation for a regularized discrimant function analysis using rda from the package klaR. However, I have problems to predict the groups from the test/validation sample. The exmaples of the R documantation and some online webpage also do not work. Does anybody know what I have done wrong?
>
> Here my code
> # I want to use the first 6 observations for validationg the model, case 7 to 36 are
> # used for the trianing:
> n_fold<-sample(1:36,36)
> testset<- n_fold[1:6]
> trainset<- n_fold[-(1:6)]
> # regularized DFA with default setting (works fine)
> z<- rda(group ~ ., data=test[trainset,])
It is advisable to use a fixed set for lambda and gamma here. The
optimizer used for finding "optimal" values may fail easily.
> #Now the prediction:
> a<-predict(z,data=test[testset,])$class
In predict, you need to use "newdata" rather than "data".
Uwe Ligges
> Error in predict.rda(z, data = test[testset, ]) :
> A new data to predict must be supplied.
>
>
> Whatever I do I always get the same error message (including examples form help)
>
> Thanks a lot in advance!
> Best wishes, Daneil
>
>
More information about the R-help
mailing list