[R] Bootstrapped CIs of R-squared for ordinal regression

varin sacha varinsacha at yahoo.fr
Mon Aug 10 16:15:03 CEST 2015


Dear R-Experts,

I am trying to get the bootstrapped confidence intervals of R-squared (Nagelkerke) for an ordinal logistic regression. Something is going wrong at the end of my script. Many thanks for your help.

Here is my reproducible example.

install.packages("rms") 
library(rms)
x=c(1,2,3,2,3,1,2,3,3,3,2,2,1,2,1,2,3,2,1,2) 
y=c("math","eco","eco","lit","lit","eco","eco","math","math","lit","lit","math","eco","eco","math","lit","lit","math","eco","math") 
Dataset<-data.frame(x,y) 
h <- orm(x ~ y) 
h 
# Bootstrap 95% CI for R-Squared 
library(boot) 
# function to obtain R-Squared from the data 
rsq <- function(formula, data, indices) { 
d <- data[indices,] # allows boot to select sample 
fit <- orm(x ~ y, data=data[indices,]) 
return((fit)$r.square) 
} 
# bootstrapping with 1000 replications 
results <- boot(data=Dataset, statistic=rsq, R=1000, formula=x ~ y) 
# view results 
results 
plot(results) 
# get 95% confidence interval 
boot.ci(results, type="bca")



More information about the R-help mailing list