library(ISLR)
Choosing a model based on any feature:
amodel <- lm(crim ~ poly(dat$zn, 3), data = Boston)
Works, returns a model. When I try to do this with every variable in a loop I get:
dat <- dplyr::select(Boston, -crim)
sapply(dat, function(x) {
mod <- lm(crim ~ poly(x, 3), data = Boston)
summary(mod)
})
Error in poly(x, 3) : 'degree' must be less than number of unique points
How can I get this to run within a loop? I would like to create a model for each poly(feature, 3)
in Boston (minus crim feature).