I have an additive model of the following form : zmdlfit <- lm(z~ns(x,df=6)+ns(y,df=6)) I can get the fitted values and plot them against z easily enough, but I also want to both obtain and plot the two additive components (the estimates of the two additive terms on the RHS) I've been looking at manuals and searching on the internet and searching the archives, but I'm apparently incompetent because I can't locate it - how do I plot just the x and y splines (against x and y)? I've read the help on predict.lm, and on predict.ns (/predict.bs) but it only shows how to get the new columns for new values of x; I could multiply those by the coefficients of the spline fit, and I could also do it by holding each variable fixed while the other varies in predict (which is right up to an additive constant), but it seems like there would have to be a more straightforward that way I am missing. It looks like gam and mgcv do it for you, but can I do it with just lm and ns? -- View this message in context: http://n4.nabble.com/plotting-additive-ns-components-tp1312375p1312375.html Sent from the R help mailing list archive at Nabble.com.
On Jan 27, 2010, at 9:09 PM, GlenB wrote:> > > I have an additive model of the following form : > > zmdlfit <- lm(z~ns(x,df=6)+ns(y,df=6)) > > I can get the fitted values and plot them against z easily enough, > but I > also want to both obtain and plot the two additive components (the > estimates > of the two additive terms on the RHS) > > I've been looking at manuals and searching on the internet and > searching the > archives, but I'm apparently incompetent because I can't locate it - > how do > I plot just the x and y splines (against x and y)? > > I've read the help on predict.lm, and on predict.ns (/predict.bs) > but it > only shows how to get the new columns for new values of x; I could > multiply > those by the coefficients of the spline fit, and I could also do it by > holding each variable fixed while the other varies in predict (which > is > right up to an additive constant), but it seems like there would > have to be > a more straightforward that way I am missing. It looks like gam and > mgcv do > it for you, but can I do it with just lm and ns? >I don't know about lm and ns but in either the Design package or its successor, rms, you could have obtained the expression by using the Function function. You might look at the methods Harrell concocted if you don't want to switch over and do it the easy way. -- David.> -- > View this message in context: http://n4.nabble.com/plotting-additive-ns-components-tp1312375p1312375.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD Heritage Laboratories West Hartford, CT
Here is a rough example require(MASS) fm <- lm(medv ~ ns(dis, 3) + ns(nox, 4), Boston) termplot(fm, se = TRUE) ## produces the plots pv <- predict(fm, type = "terms") ## gets the two terms Bill Venables CSIRO/CMIS Cleveland Laboratories -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of GlenB Sent: Thursday, 28 January 2010 12:09 PM To: r-help at r-project.org Subject: [R] plotting additive ns components I have an additive model of the following form : zmdlfit <- lm(z~ns(x,df=6)+ns(y,df=6)) I can get the fitted values and plot them against z easily enough, but I also want to both obtain and plot the two additive components (the estimates of the two additive terms on the RHS) I've been looking at manuals and searching on the internet and searching the archives, but I'm apparently incompetent because I can't locate it - how do I plot just the x and y splines (against x and y)? I've read the help on predict.lm, and on predict.ns (/predict.bs) but it only shows how to get the new columns for new values of x; I could multiply those by the coefficients of the spline fit, and I could also do it by holding each variable fixed while the other varies in predict (which is right up to an additive constant), but it seems like there would have to be a more straightforward that way I am missing. It looks like gam and mgcv do it for you, but can I do it with just lm and ns? -- View this message in context: http://n4.nabble.com/plotting-additive-ns-components-tp1312375p1312375.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Dear GlenB, The allEffects() function in the effects package can make these plots. I hope this helps, John> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]On> Behalf Of GlenB > Sent: January-27-10 9:09 PM > To: r-help at r-project.org > Subject: [R] plotting additive ns components > > > > I have an additive model of the following form : > > zmdlfit <- lm(z~ns(x,df=6)+ns(y,df=6)) > > I can get the fitted values and plot them against z easily enough, but I > also want to both obtain and plot the two additive components (theestimates> of the two additive terms on the RHS) > > I've been looking at manuals and searching on the internet and searchingthe> archives, but I'm apparently incompetent because I can't locate it - howdo> I plot just the x and y splines (against x and y)? > > I've read the help on predict.lm, and on predict.ns (/predict.bs) but it > only shows how to get the new columns for new values of x; I couldmultiply> those by the coefficients of the spline fit, and I could also do it by > holding each variable fixed while the other varies in predict (which is > right up to an additive constant), but it seems like there would have tobe> a more straightforward that way I am missing. It looks like gam and mgcvdo> it for you, but can I do it with just lm and ns? > > -- > View this message in context: http://n4.nabble.com/plotting-additive-ns- > components-tp1312375p1312375.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
On Wed, 27 Jan 2010, David Winsemius wrote:> > On Jan 27, 2010, at 9:09 PM, GlenB wrote: > >> >> >> I have an additive model of the following form : >> >> zmdlfit <- lm(z~ns(x,df=6)+ns(y,df=6)) >> >> I can get the fitted values and plot them against z easily enough, but I >> also want to both obtain and plot the two additive components (the >> estimates >> of the two additive terms on the RHS) >>?termplot. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle