[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
>Z<-pmax(mydata$x-20,0)
>(length(Z)==length(obj$y))
>[1] TRUE
>update(obj,.~.+Z) #works

However for some subset it doesn't works:
>obj<-glm(y~x, data=mydata, subset=f==1) #works
>Z<-pmax(mydata$x[mydata$f==1]-20,0)
>(length(Z)==length(obj$y))
>[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!
vito




-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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