```
# NOT RUN {
require(stats); require(graphics)
ns(women$height, df = 5)
summary(fm1 <- lm(weight ~ ns(height, df = 5), data = women))
## To see what knots were selected
attr(terms(fm1), "predvars")
## example of safe prediction
plot(women, xlab = "Height (in)", ylab = "Weight (lb)")
ht <- seq(57, 73, length.out = 200) ; nD <- data.frame(height = ht)
lines(ht, p1 <- predict(fm1, nD))
stopifnot(all.equal(p1, predict(update(fm1, . ~
splines::ns(height, df=5)), nD)))
# not true in R < 3.5.0
# }
```

Run the code above in your browser using DataCamp Workspace