Hello,

Is this what you are looking for?


ci95 <- apply(my.data, 2, quantile, probs = c(0.025, 0.975))


Hope this helps,

Rui Barradas

Às 20:42 de 23/09/19, varin sacha via R-help escreveu:
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)

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

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to