varin sacha
2015-Jul-23 19:50 UTC
[R] Confidence intervals of G&K gamma statistics using bootstrap
Dear R-Experts,
I am trying to calculate the confidence intervals of the Goodman & Kruskal
gamma statistics using bootstrap. There is no gamma function in the boot
package. There is a gamma function in the base package, but it is the usual
mathematical function.
So, I decide to try to calculate the confidence intervals using this site :
http://www.statmethods.net/advstats/bootstrapping.html
I get a "normal" warning message, but my R code is not working and I
don't understand where my mistake(s) is (are).
Here is the reproducible example with imaginary/fake data.
install.packages("ryouready")
library(ryouready)
a=c("satisfait", "pas satisfait", "tres
satisfait","satisfait","tres satisfait","pas
satisfait","satisfait","satisfait","tres
satisfait","pas satisfait")
b=c("grand", "petit", "petit", "grand",
"petit", "grand", "grand", "petit",
"petit", "grand")
x=table(a,b)
ord.gamma(x)
# calculate Goodman & Kruskal gamma using bootstrap
library(boot)
GK <- function(formula, data, indices) {
d <- data[indices,] # allows boot to select sample
tab <- xtabs(formula, data=d)
stat <- ord.gamma(tab)
return(stat)
}
# bootstrapping with 2000 replications
results <- boot(data=d, statistic=GK,R=2000)
# view results
results
plot(results)
# get 95% confidence interval
boot.ci(results, type="all")
Best Regards, thanks for your precious help!
SV