[R] plot.gam
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Fri Apr 7 21:00:39 CEST 2000
Thomas Lumley <thomas at biostat.washington.edu> writes:
> Suppose we fit
>
> model<-lm(y~sin(x)+ns(z,3))
>
>
> Given 'model' how can we extract x & z? We can't work them out from
> model.frame(model), which only contains transformed versions. Even
> assuming we can guess what the name of the variable is (not trivial --
> which is the variable in ns(z,df)? In ns(df=df,z)?), we don't know where
> to find it.
>
> It seems that we would have to assume that model$call$data contains the
> variables if evaluated in the calling frame. This means that plot.gam
> wouldn't necessarily work if called from inside a function, or if the
> original data set had been changed since the model was fitted, or if the
> default na.action had been changed or various other problems.
>
> Ideas?
The obvious one: Let the user do the thinking:
d<-data.frame(x=0, z=seq(-3, 3, .1))
evalq(plot(z, predict(model, new=d), type='l'), d)
or even (I think it works. Inefficiently, though.)
curve(predict(model, new=data.frame(x=0, z=x)))
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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