[R] fitting models with the subset argument

MUGGEO VITO vito.muggeo at giustizia.it
Mon Dec 3 13:08:51 CET 2001

Hi all,
I'd like to fit model where the terms both are in the data.frame, mydata
say, and are vectors *not in the data.frame*.
>obj<-glm(y~x, data=mydata) #works
>[1] TRUE
>update(obj,.~.+Z) #works

However for some subset it doesn't works:
>obj<-glm(y~x, data=mydata, subset=f==1) #works
>[1] TRUE
>update(obj,.~.+Z)  #DOESN'T WORK!!!
Error in model.frame(formula, rownames, variables, varnames, extras,
extranames, :
            variable lengths differ

Of course also the following doesn't work
>glm(y~x +Z, mydata, subset=f==1) #doesn't work

but the following works
>glm(y[mydata$f==1]~x[mydata$f==1] +Z, mydata)

How can I solve this problem?
Thank you very much for your attention!

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list