[R] mgcv package plot superimposing smoothers
bt_jannis at yahoo.de
Mon Dec 6 21:22:33 CET 2010
I would extract the information about the smoothers and plot them using
standard plotting routines. After
Mtest <- gam(outcome ~ s(age, by=as.numeric(gender==0)) +
run something similar to:
smoothers <- predict(s,type='terms')
and you get the values for the smoothers saved to "smoothers" (See
?gam.predict). You may haave to tweak around a bit as I could not test
the function. Another solution may be (also untested):
Jef Vlegels schrieb:
> Dear R help list,
> I'm fitting a 'variable coefficient model' in the MGCV package and I want to
> plot the different smoothers I get for each factor level in one graph.
> So, I do something like this to fit the gam:
> Mtest <- gam(outcome ~ s(age, by=as.numeric(gender==0)) +
> Then I can plot the smoother for gender=0:
> And for gender=1:
> But the second plot superimposes the first one. Normally I use 'lines' to
> plot just the line from the second plot in the first plot, but this doesn't
> seem to work with the plot.gam function.
> Does someone have a solution to plot these two smoothers in one graph, each
> with a different color/line type?
> Thanks in advance,
> Jef Vlegels
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help