I want to simulate a non linear regression model of the type
$$y_i = 1 + x_i + bs(x_i)+ e_i,$$
$i=1,...,1000$, where $bs(x_i)$ is a b-spline. I have tried to use the
splines R package but when I try to fit the non linear regression model, the estimate of one of the entries of the spline is
NA, and the rest of the estimates are far from the true value:
library(splines) n = 1000 set.seed(1234) x <- rnorm(n) bsx <- bs(x) eps <- rnorm(n,0,0.25) y = 1 + x + bsx[,1] + bsx[,2] + bsx[,3] + eps des <- cbind(x,bsx) lm(y~ des) Call: lm(formula = y ~ des) Coefficients: (Intercept) desx des1 des2 des3 1.6017 1.1633 0.5384 0.2188 NA
What am I doing wrong?