Skip to content

ipred and lda

5 messages · Stefan Böhringer, Martin Maechler, Brian Ripley +2 more

#
Dear all,

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

The R version is 1.7.1

Thanks in advance,

	Stefan

----------------
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);

Error-Message is :
Error: Object "predict.lda" not found
#
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			<><
#
On 9 Jan 2004, Stefan B?hringer wrote:

            
Precisely.  You should not be calling a method directly and in any case
that is not what is needed here.  ?errorest shows you a correct example,
so why not follow it?
You are overdue for an update then.  See what the posting guide asks you
to do if you find a problem and are not using the current version.

  
    
#
Stefan B?hringer wrote:

            
R-1.8.1 is recent.

predict.lda() is hidden in a namespace, so you cannot access it that 
way. Please use the generic (predict(), which calls the method) rather 
than calling methods directly.

However, predict.lda() won't work in errorest() (not errortest, BTW) as is.

Use an own function like mypredict.lda() which looks like:
   mypredict.lda <- function(object, newdata)
     predict(object, newdata = newdata)$class
which is given in the examples of ?errorest.

Uwe Ligges
#
I got also this problem and I solved it a couple of months ago.
Unfortunatelly, I do not have access to the machine with my code before
monday, so, I cannot give you the exact recipe... I am just recalling from
my poor memory!

If I remember, the problem occured when MASS moved to use namespace, so,
predict.lda was not visible externally any more, something that some ipred
function assumed in the version I used at that time. The solution was to
change the code of ipred to explicitly call the predict.lda function in
MASS, that is, something like:
MASS:::predict.lda

give it a try. Since you use an old version of R (1.7.1), you may face a
similar problem. I suppose the solution is to use latest versions of R, MASS
and ipred.
Best,

Philippe Grosjean

P.S.: Andrea and Thorsten: sorry for not having mentioned this when I got
the problem. I was in a rush,... and then I forgot! But I suppose the latest
version of ipred is OK now, isn't it?

.......................................................<?}))><....
 ) ) ) ) )
( ( ( ( (   Prof. Philippe Grosjean
\  ___   )
 \/ECO\ (   Numerical Ecology of Aquatic Systems
 /\___/  )  Mons-Hainaut University, Pentagone
/ ___  /(   8, Av. du Champ de Mars, 7000 Mons, Belgium
 /NUM\/  )
 \___/\ (   phone: + 32.65.37.34.97, fax: + 32.65.37.33.12
       \ )  email: Philippe.Grosjean at umh.ac.be
 ) ) ) ) )  SciViews project coordinator (http://www.sciviews.org)
( ( ( ( (
...................................................................

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Martin Maechler
Sent: Friday, 09 January, 2004 17:14
To: Stefan B?hringer
Cc: R Help
Subject: Re: [R] ipred and lda
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			<><

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html