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 regressesy
against a B-spline forx
using three degrees of freedom. What would the equation for such a model look like?
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.
Attribution
Source : Link , Question Author : AmeliaBright , Answer Author : Frank Harrell