[R] Bootstrap and average median squared error

varin sacha v@rin@@ch@ @ending from y@hoo@fr
Tue May 22 01:19:03 CEST 2018


Dear R-experts,

I am trying to bootstrap (and average) the median squared error evaluation metric for a robust regression. I can't get it. What is going wrong ? 

Here is the reproducible example.

#############################
install.packages( "quantreg" )
library(quantreg)

crp <-c(12,14,13,24,25,34,45,56,25,34,47,44,35,24,53,44,55,46,36,67)
bmi <-c(34,32,12,76,54,34,21,18,92,32,11,13,45,46,56,57,67,87,12,13)
glucose <-c(23,54,11,12,13,21,32,12,45,54,65,87,21,23,12,12,23,23,43,54)

# Create a list to store the results
lst<-list()

# Numbers of bootstrap samples
nboot=100 
bootstrap.MedAESQ =rep(NA,nboot)

for(i in 1 :nboot)
{

fit <- rq( crp ~ bmi+glucose, tau = 0.5)
ypred=predict(fit)
y=new$crp
bootstrap.MedAESQ [i]=median(y-ypred)^2
lst[i]<-bootstrap.MedAESQ 

}
mean(unlist(lst))
###################################

 



More information about the R-help mailing list