R: function to calculate the mse from a model fit on bootstrapped samples from the Boston dataset
# data
data(Boston)
# function - calculate the mse from a model fit on bootstrapped samples from the Boston dataset
model.mse <- function(x) {
id <- sample(1:nrow(Boston), 200, replace = T)
mod <- lm(medv ~ ., data = Boston[id,])
mse <- mean((fitted.values(mod) - Boston$medv[id])^2)
return(mse)
}
# initialising the list to pass to the apply functions
x.list <- sapply(1:10000, list)
# detect the number of cores
n.cores <- detectCores()
n.cores