by Splinter
Last Updated August 13, 2019 22:19 PM

The R package `splines`

allows one to fit a non linear model using splines. For instance,

```
require(stats); require(graphics)
bs(women$height, df = 5)
summary(fm1 <- lm(weight ~ bs(height, df = 5), data = women))
## example of safe prediction
plot(women, xlab = "Height (in)", ylab = "Weight (lb)")
ht <- seq(57, 73, length.out = 200)
lines(ht, predict(fm1, data.frame(height = ht)))
```

This produces the following estimates

```
Call:
lm(formula = weight ~ bs(height, df = 5), data = women)
Residuals:
Min 1Q Median 3Q Max
-0.31764 -0.13441 0.03922 0.11096 0.35086
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 114.8799 0.2167 530.146 < 2e-16 ***
bs(height, df = 5)1 3.4657 0.4595 7.543 3.53e-05 ***
bs(height, df = 5)2 13.0300 0.3965 32.860 1.10e-10 ***
bs(height, df = 5)3 27.6161 0.4571 60.415 4.70e-13 ***
bs(height, df = 5)4 40.8481 0.3866 105.669 3.09e-15 ***
bs(height, df = 5)5 49.1296 0.3090 158.979 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.2276 on 9 degrees of freedom
Multiple R-squared: 0.9999, Adjusted R-squared: 0.9998
F-statistic: 1.298e+04 on 5 and 9 DF, p-value: < 2.2e-16
```

If I want to predict using these estimates, what should I put in the predictive model?

$$\hat{y} = \hat{\beta}^T \textbf{(?)}.$$

I know that I can obtain the predictions using the command `predict`

, but I want to understand what is this command doing. Is it $\textbf{(?)} = bs(x, df = 5)$?

Updated September 21, 2017 15:19 PM

Updated August 21, 2015 17:08 PM

- Serverfault Query
- Superuser Query
- Ubuntu Query
- Webapps Query
- Webmasters Query
- Programmers Query
- Dba Query
- Drupal Query
- Wordpress Query
- Magento Query
- Joomla Query
- Android Query
- Apple Query
- Game Query
- Gaming Query
- Blender Query
- Ux Query
- Cooking Query
- Photo Query
- Stats Query
- Math Query
- Diy Query
- Gis Query
- Tex Query
- Meta Query
- Electronics Query
- Stackoverflow Query
- Bitcoin Query
- Ethereum Query