[This article was first published on ALSTAT R Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
To run the Cochran Q Test in R, we need to download the package of it first, since it is not built-in in R. The name of the package is RVAideMemoire authored by Maxime Hervé. Here’s how to do it.
< o:p>
Codes:
Here we are installing the package named RVAideMemoire.
Press ‘Enter/Return’ key then there will be a pop-up window asking you to choose your CRAN Mirror.
Select your country or any country you want, then hit ‘Ok’, and it will be downloaded and installed.
After installation, you can now run the package, and to do that you need to type the following code,
Note: Every time you use the Cochran Q Test function make sure you call the package first.
Note: Every time you use the Cochran Q Test function make sure you call the package first.
This time lets try and ask help for the function of it.
Example: Four methods (A, B, C, and D) of treating raw fabric to make it water repellent were tested for effectiveness on six types of fabric. A satisfactory result got a 1.
Method A< o:p> | Method B< o:p> | Method C< o:p> | Method D< o:p> |
1< o:p> | 1< o:p> | 0< o:p> | 0< o:p> |
1< o:p> | 1< o:p> | 0< o:p> | 1< o:p> |
1< o:p> | 0< o:p> | 0< o:p> | 0< o:p> |
1< o:p> | 1< o:p> | 1< o:p> | 0< o:p> |
1< o:p> | 1< o:p> | 0< o:p> | 1< o:p> |
1< o:p> | 1< o:p> | 0< o:p> | 1< o:p> |
Solution:
1. H0: The four treatments are equally effective.
H1: The four treatments are not equally effective.
2. Level of significance: alpha = 0.05
4. Rejection Region: Reject the null hypothesis if X^2 >= 7.185. Otherwise, do not reject it.
5. Computation:
Method A< o:p> | Method B< o:p> | Method C< o:p> | Method D< o:p> | Li< o:p> | (Li)^2< o:p> |
1< o:p> | 1< o:p> | 0< o:p> | 0< o:p> | 2< o:p> | 4< o:p> |
1< o:p> | 1< o:p> | 0< o:p> | 1< o:p> | 3< o:p> | 9< o:p> |
1< o:p> | 0< o:p> | 0< o:p> | 0< o:p> | 1< o:p> | 1< o:p> |
1< o:p> | 1< o:p> | 1< o:p> | 0< o:p> | 3< o:p> | 9< o:p> |
1< o:p> | 1< o:p> | 0< o:p> | 1< o:p> | 3< o:p> | 9< o:p> |
1< o:p> | 1< o:p> | 0< o:p> | 1< o:p> | 3< o:p> | 9< o:p> |
G1< o:p> | G2< o:p> | G3< o:p> | G4< o:p> | Li< o:p> | (Li)^2< o:p> |
6< o:p> | 5< o:p> | 1< o:p> | 3< o:p> | 15< o:p> | 41< o:p> |
6. Decision: Since 9.31579 is greater than 7.185, then we reject the null hypothesis
7. Conclusion: Therefore, we have sufficient statistical evidence to conclude that the effectiveness of at least two treatments differ.
Computations in R
Now lets try and solve the above example using Cochran Q Test in R. First thing we need to do is to input the data.
Now, its better to run the length function, so that we would know if we miss something.
This time lets make the four columns and the 6 rows, i.e., the four methods and the 6 different types of fabric, respectively.
Now, lets combine the rows and columns to make a table.
The output of this should look like this.
So, as you can see everything is the same with the given table in the example. Now, lets try and confirm the above computations.
Clearly in the result, that our test statistics Q is equal to 9.3158 and the p-value is 0.025374. And since the p-value is less than the alpha, then we reject the null hypothesis. That’s why, we have a pairwise comparisons by Wilcoxon sign test.
“Special Thanks to: Tal Galili and Maxime Hervé”
Example used: http://frank.mtsu.edu/~dwalsh/6604/6604COCH.pdf
To leave a comment for the author, please follow the link and comment on their blog: ALSTAT R Blog.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.