tag:blogger.com,1999:blog-1275149608391671670.post265810547275224999..comments2023-09-28T06:13:40.704-04:00Comments on SAS and R: Example 8.39: calculating Cramer's VKen Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-1275149608391671670.post-70807355129906186442014-07-08T02:26:24.097-04:002014-07-08T02:26:24.097-04:00You could get similar results using a conversion t...You could get similar results using a conversion to Fisher Z and then back again. I.e.:<br /><br />#"mat" being a r x c matrix/table<br />chicalc <- chisq.test(mat)$statistic<br /><br /># calculate Cramer's v - <br />K <- min(nrow(mat),ncol(mat))<br />crv <- sqrt(chicalc / sum(mat)*(K-1))<br /><br /># convert the Cramer's V to a Fisher's Z<br />fz <- 0.5 * log((1 + crv)/(1 - crv))<br /><br /># calculate 95% conf.int around Fisher Z<br />conf.level <- 0.05<br />se <- 1/sqrt(sum(mat)-3) * qnorm(1-(conf.level/2))<br />cifz <- fz + c(-se,se)<br /><br /># convert it back to conf.int around Cramer's V<br />cicrv <- (exp(2 * cifz) - 1)/(1 + exp(2 * cifz))thelatemailhttps://www.blogger.com/profile/13449819504543410744noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-37369235439610383672014-04-25T08:03:08.702-04:002014-04-25T08:03:08.702-04:00It's easier than if you had to roll your own c...It's easier than if you had to roll your own code!<br /><br />My interpretation is that we observed a Cramer's V of 0.098 (very weak association). We're 95% confidence that the true V is captured by the interval 0.013 to 0.187. Nick Hortonhttps://www.blogger.com/profile/00242216324355342047noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-58643190224232682532014-04-25T07:42:37.221-04:002014-04-25T07:42:37.221-04:00you call that easy? and where is the interpretatio...you call that easy? and where is the interpretation?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-65129237621581718382013-07-31T08:43:32.340-04:002013-07-31T08:43:32.340-04:00This could certainly be done easily using a bootst...This could certainly be done easily using a bootstrapping procedure:<br /><br />require(mosaic)<br /><br />cv.test = function(x,y) {<br /> CV = sqrt(chisq.test(x, y, correct=FALSE)$statistic /<br /> (length(x) * (min(length(unique(x)),length(unique(y))) - 1)))<br /> print.noquote("Cramér V / Phi:")<br /> return(as.numeric(CV))<br />}<br /><br /><br /><br />helpdata = read.csv("http://www.math.smith.edu/r/data/help.csv")<br />with(helpdata, cv.test(female, homeless))<br /> <br />res = do(5000)* with(resample(helpdata), cv.test(female, homeless))<br />qdata(c(.025, .975), res$result)<br /><br />> with(helpdata, cv.test(female, homeless))<br />[1] Cramér V / Phi:<br />[1] 0.09765063<br /><br />> qdata(c(.025, .975), res$result)<br /> 2.5% 97.5% <br />0.01315987 0.18717591 <br /><br />Also note that the "vcd" package has an "assocstats()" function which calculates Cramer's V (and other statistics.<br /><br /><br />Nick Hortonhttps://www.blogger.com/profile/00242216324355342047noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-86517226655391232242013-07-29T08:35:58.840-04:002013-07-29T08:35:58.840-04:00be good to have ci's as well for Cramer's ...be good to have ci's as well for Cramer's VAnonymousnoreply@blogger.com