s-news
[Top] [All Lists]

how to consctruct the formula argument for discrim() ?

To: s-news@lists.biostat.wustl.edu
Subject: how to consctruct the formula argument for discrim() ?
From: Gabriel Baud-Bovy <gabriel@shaker.med.umn.edu>
Date: Fri, 30 Nov 2001 20:41:44 +0100
Dear S-users,

Background: I need it to write a function to perform discriminant
analysis automatically on a large number of datasets and the number 
of dependent variables depend on the dataset. Although I found
a way of doing it, I encoutered a problem when I tried 
to specify the model formula for discrim() which
I would like to understand better [S+2000 Pro Rel. 3].

For example, in the following case,

data<-data.frame(y=round(runif(100,1,5)),x1=runif(100),x2=runif(100))
fit<-discrim(factor(y)~x1+x2,data=data)

works fine but 

form<-"factor(y)~x1+x2"
fit<-discrim(form,data=data)

and 

form<-as.formula(terms("factor(y)~x1+x2"))
fit<-discrim(form,data=data)

don't work. With lm() or VR's function lda() there is no
problem since: 

form<-"y~x1+x2"
fit<-lm(form,data=data)

and

form<-as.formula(terms("factor(y)~x1+x2"))
fit<-lda(form,data=data)

work. Besides, there is a partial work-around:

cols<-c("y","x1","x2")
fit<-discrim("factor(y)~.",data=data[,cols])

but is it possible to construct the formula in discrim() 
without tampering with the code of discrim()? If yes, how?

Thank you for your help,

Gabriel Baud-Bovy





<Prev in Thread] Current Thread [Next in Thread>
  • how to consctruct the formula argument for discrim() ?, Gabriel Baud-Bovy <=