[R] plotting additive ns components

Bill.Venables at csiro.au Bill.Venables at csiro.au
Thu Jan 28 04:47:31 CET 2010


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.



More information about the R-help mailing list