Skip to content
Prev 377521 / 398502 Next

Bootstrapped CIs of MSE for (G)AM model

Hello,

There were several errors with your code. The following works but with 
the other CI types.


library(ISLR)
library(mgcv)
library(boot)

# function to obtain MSE
MSE <- function(data, indices, formula) {
   d <- data[indices, ] # allows boot to select sample
   fit <- gam(formula, data = d)
   ypred <- predict(fit)
   mean((d[["wage"]] - ypred)^2)
}

data(Wage)

# Make the results reproducible
set.seed(1234)

# bootstrapping with 1000 replications
results <- boot(data = Wage, statistic = MSE,
                 R = 1000, formula = wage ~ education + s(age, bs = 
"ps") + year))

# get 95% confidence intervals
# type = "bca" is throwing an error
ci.type <- c("norm","basic", "stud", "perc")
boot.ci(results, type = ci.type)



Hope this helps,

Rui Barradas

?s 20:36 de 22/11/2018, varin sacha via R-help escreveu: