[R] Cochrans Q Test

Torsten Hothorn Torsten.Hothorn at rzmail.uni-erlangen.de
Mon Sep 18 15:24:05 CEST 2006


[...]

>
>> cochranq.test(K)
>
>        Cochran's Q Test for Dependent Samples
>
> data:  K
> Cochran's Q = 23.9298, df = 11, p-value = 0.01303
>

Cochran's Q fits into the `coin' framework and thus:

>  K <- as.table(matrix(c(1,1,0,0, 1,1,0,1, 1,1,1,1, 1,1,1,1, 1,0,0,0,
+  1,1,1,1, 1,1,1,1, 0,0,0,0, 0,1,0,1, 1,1,1,1, 0,1,0,1, 0,1,0,1),ncol=12,
+  dimnames = list("Seating type" = c("I","II","III","IV"),"Test
+  subject"=c("A","B","C","D","E","F","G","H","I","J","K","L"))))
>
> df <- data.frame(success = as.vector(K),
+                  test = factor(rep(colnames(K), rep(4, 12))),
+                  subject = factor(rep(rownames(K), 12)))
>
> library("coin")
> symmetry_test(success ~ test | subject, data = df, teststat = "quad")

         Asymptotic General Independence Test

data:  success by
          groups A, B, C, D, E, F, G, H, I, J, K, L
          stratified by subject
chi-squared = 23.9298, df = 11, p-value = 0.01303

>

can be used to compute the test without additional coding and

> symmetry_test(success ~ test | subject, data = df, teststat = "quad",
                 distribution = approximate(10000))

         Approximative General Independence Test

data:  success by
          groups A, B, C, D, E, F, G, H, I, J, K, L
          stratified by subject
chi-squared = 23.9298, p-value = 0.006

>

approximates the p value by Monte-Carlo procedures.

Best wishes,

Torsten


>
> BTW, a quick Google search shows that the pcochran() function is in the
> 'outliers' package on CRAN, which also has a cochran.test() function
>
> HTH,
>
> Marc Schwartz
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



More information about the R-help mailing list