[R] bootstrap CI of the difference between 2 Cramer's V

varin sacha v@r|n@@ch@ @end|ng |rom y@hoo@|r
Sat May 28 20:21:22 CEST 2022


Dear R-experts,

While comparing groups, it is better to assess confidence intervals of those differences rather than comparing confidence intervals for each group.
I am trying to calculate the CIs of the difference between the two Cramer's V and not the CI to the estimate of each group’s Cramer's V.

Here below my toy R example. There are error messages. Any help would be highly appreciated.

##############################
library(questionr)
library(boot)

gender1<-c("M","F","F","F","M","M","F","F","F","M","M","F","M","M","F","M","M","F","M","F","F","F","M","M","M","F","F","M","M","M","F","M","F","F","F","M","M","F","M","F")
color1<-c("blue","green","black","black","green","green","blue","blue","green","black","blue","green","blue","black","black","blue","green","blue","green","black","blue","blue","black","black","green","green","blue","green","black","green","blue","black","black","blue","green","green","green","blue","blue","black")

gender2<-c("F","F","F","M","M","F","M","M","M","F","F","M","F","M","F","F","M","M","M","F","M","M","M","F","F","F","M","M","M","F","M","M","M","F","F","F","M","F","F","F")
color2<-c("green","blue","black","blue","blue","blue","green","blue","green","black","blue","black","blue","blue","black","blue","blue","green","blue","black","blue","blue","black","black","green","blue","black","green","blue","green","black","blue","black","blue","green","blue","green","green","blue","black")

f1=data.frame(gender1,color1)
tab1<-table(gender1,color1)
e1<-cramer.v(tab1)

f2=data.frame(gender2,color2)
tab2<-table(gender2,color2)
e2<-cramer.v(tab2)

f3<-data.frame(e1-e2)

cramerdiff=function(x,w){
y<-tapply(x[w,1], x[w,2],cramer.v)
y[1]-y[2]
}

results<-boot(data=f3,statistic=cramerdiff,R=2000)
results

boot.ci(results,type="all")
##############################

 



More information about the R-help mailing list