[R] ipred and lda

Martin Maechler maechler at stat.math.ethz.ch
Fri Jan 9 17:14:01 CET 2004


>>>>> "Stefan" == Stefan Böhringer <commercial at s-boehringer.de>
>>>>>     on 09 Jan 2004 16:46:23 +0100 writes:

    Stefan> Dear all, can anybody help me with the program
    Stefan> below? The function predict.lda seems to be defined
    Stefan> but cannot be used by errortest.

    Stefan> The R version is 1.7.1

  >>   library("MASS");
  >>   library("ipred");
  >> 
  >>   data(iris3);
  >>   tr <- sample(1:50, 25);
  >>   train <- rbind(iris3[tr,,1], iris3[tr,,2], iris3[tr,,3]);
  >>   test <- rbind(iris3[-tr,,1], iris3[-tr,,2], iris3[-tr,,3]);
  >>   cl <- factor(c(rep("s",25), rep("c",25), rep("v",25)));
  >>   z <- lda(train, cl);
  >>   predict(z, test)$class;
  >> 
  >>   data.frame(class=cl, train);
  >>   flowers <- data.frame(class=cl, train);
  >>   errorest(class ~ ., data=flowers, model=lda, estimator="cv",
  >>   predict=predict.lda);

    Stefan> Error-Message is : 
    Stefan> Error: Object "predict.lda" not found

predict.lda is not exported from new versions of MASS
since one should use  predict( <lda-fit> , ...).

i.e., I presume that

errorest(class ~ ., data=flowers, model=lda, estimator="cv", predict=predict)

will work.

BTW: Please, remove the  ";" at the end of lines.
     In S code, they are just plain ugly.

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><




More information about the R-help mailing list