R Splines – How to Translate Output from lm() Fit with Cubic Spline into Regression Equation

rsplines

I have some code and output, and I would like to construct a model. I don't know how to construct a model using this output:

 require("splines")
 x   <- c(0.2,   0.23,   0.26,   0.29,   0.33,   0.46,    0.53 )
 y   <- c(0.211, 0.2026, 0.2034, 0.2167, 0.2177, 0.19225, 0.182)
 fit <- lm(y ~ ns(x,3))
 summary(fit)

Note that ns() generates the B-spline basis matrix for a natural cubic spline. Thus this model regresses y against a B-spline for x using three degrees of freedom. What would the equation for such a model look like?

Best Answer

require(rms)
f <- ols(y ~ rcs(x, 3))  # 2 d.f. for x
Function(f)  # represent fitted function in simplest R form
latex(f)     # typeset algebraic representation of fit

rcs "restricted cublic spline" is another representation of a natural spline.

Related Question