[R] 95% bootstrap CIs

varin sacha v@r|n@@ch@ @end|ng |rom y@hoo@|r
Mon Sep 23 21:42:10 CEST 2019


Dear R-Experts,

Here is my reproducible R code to get the Mean squared error of GAM and MARS after I = 50 iterations/replications.
If I want to get the 95% bootstrap CIs around the MSE of GAM and around the MSE of MARS, how can I complete/modify my R code ?

Many thanks for your precious help.

##################

library(mgcv) 
 library(earth)   
my.experiment <- function() { 
n<-500 
x <-runif(n, 0, 5) 
 z <- rnorm(n, 2, 3) 
a <- runif(n, 0, 5) 
y_model <- 0.1*x^3 - 0.5*z^2 - a + x*z + x*a + 3*x*a*z + 10 
 y_obs <- y_model +c( rnorm(n*0.97, 0, 0.1), rnorm(n*0.03, 0, 0.5) ) 
 gam_model<- gam(y_obs~s(x)+s(z)+s(a)) 
mars_model<-earth(y_obs~x+z+a) 
MSE_GAM<-mean((gam_model$fitted.values - y_model)^2) 
 MSE_MARS<-mean((mars_model$fitted.values - y_model)^2) 
 return( c(MSE_GAM, MSE_MARS) ) 
}   
my.data = t(replicate( 50, my.experiment() )) 
colnames(my.data) <- c("MSE_GAM", "MSE_MARS") 
summary(my.data) 

##################



More information about the R-help mailing list