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
|