######################################################################## ######### SBDM Course ######### ###### Dr. Ilaria Benedetti - Association among mixed variables ###### ######################################################################## #### chi square with R function tab<-matrix(c(30,11, 43,39, 1, 35,30, 19, 35),3,3,dimnames = list(c("French", "italian", "other"), c("none","French", "italian"))) chisq <- chisq.test(tab) chisq # Excersise to do: # compute chi2 and v-cramer. Provide an interpretation of the results tab <- matrix(c(14, 47, 160, 172, 12, 12 ),2,3,dimnames = list(c("yes", "no"), c("first y.","secondy.","third y."))) tab chisq <- chisq.test(tab) chisq chisq chisq<- #save the chisq value in an object n=nrow(Arthritis) h=2 #nrow of count k=3 #ncol of count # V - cramer chi.quad_MAX <- n * min(h - 1,k - 1) chi.quad_MAX chi.quad_NORM <- chisq / chi.quad_MAX chi.quad_NORM V <- sqrt(chi.quad_NORM) V ######################## Esecise to do ######################################## ## Load vcd package library(vcd) ## Load Arthritis dataset (data frame) data(Arthritis) str(Arthritis) summary(Arthritis) # 1- create a two way table for variables sex and Improved (improvement by gender) # 2- can we assume that a relationship between gender and improvment level exists? # 3- compute chi-2 indicator and V-cramer indicator (relative indicator of association) ################ Resolution #################### # 1- two way table count<-table(Arthritis$Sex, Arthritis$Improved) count # 2- chisq <- chisq.test(count) chisq chisq<-4.8407 #save in an object only the chisq value n=nrow(Arthritis) h=2 #nrow of count k=3 #ncol of count # V - cramer chi.quad_MAX <- n * min(h - 1,k - 1) chi.quad_MAX chi.quad_NORM <- chisq / chi.quad_MAX chi.quad_NORM V <- sqrt(chi.quad_NORM) V