With $K$ knots $(t_1, \ldots, t_k)$ the restricted cubic spline can be written as

$\beta_0 + \beta_1X + \beta_2(X-t_1)^3_+ + \beta_3(X-t_2)^3_+ + \ldots + \beta_{k+1}(X-t_k)^3_+,$


$\beta_k = [\beta_2(t_1-t_k) + \beta_3(t_2-t_k)+ \ldots +\beta_{k-1}(t_{k-2} -t_k)] / (t_k -t_{k-1}),$


$\beta_{k+1} = [\beta_2(t_1-t_{k-1}) + \beta_3(t_2-t_{k-1})+ \ldots +\beta_{k-1}(t_{k-2} -t_{k-1})] / (t_{k-1} -t_{k}).$

When I specify glm(y ~ ns(x, df=3, intercept=FALSE), data = data, family = binomial()) in R I obtain estimates for:

ns(x, df=3)1, ns(x, df=3)2, ns(x, df=3)3

since the intercept should not be included $\beta_0$ is removed. However which is the estimate for my linear term? $\beta_1$. Does the estimate for ns(x, df=3)1 correspond to $\beta_2$?


1 Answer 1


Function ns() from package splines indeed implements a natural cubic spline (aka restricted cubic spline) but using a B-splines basis representation. This provides an equivalent fit but it is not the same as the expansion you wrote in math. This expansion is implemented in function rcs() from the package rms.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.