I'm sure this is an easy command in R, but for some reason, I'm having trouble finding a solution.
I'm trying to run a bunch of crosstabs (using the table() command) in R, and each tab has two columns (treatment and no treatment). I would like to know if the difference between the columns are significantly different for each other for all rows (the rows are a handful of answer choices from a survey). I'm not interested in overall significance, only within the crosstab comparing treatment vs. no treatment.
This type of analysis is very easy in SPSS (link below to illustrate what I'm talking about), but I can't seem to get it working in R. Do you know I can do this?
EDITED: Here is an example of in R about what I mean:
treatmentVar <-c(0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1) # treatment is 1 or 0
question1 <-c(1,2,2,3,1,1,2,2,3,1,1,2,2,3,1,3) #choices available are 1, 2, or 3
Questiontab <- table(question1, treatmentVar)
Questiontab
I have tables like this ^ (percentaged by column on the treatmentVar), and I would like to see if there is a significant difference between each question choice (rows) going from treatment 0 to treatment 1. So in the example above, I would want to know if there is a significant difference between 4 and 2 (row 1), 3 and 3 (row 2), and 1 and 3 (row 3). So in this example, the choices for question1 might be significantly difference for choices 1 and 3 (because the difference is 2) but the difference for choice 2 isn't because the difference is zero. Ultimately, I'm trying to determine this type of significance. I hope that helps.
Thanks!
Using your example, either the chisq.test
or prop.test
(equivalent in this case):
> chisq.test(Questiontab)
Pearson's Chi-squared test
data: Questiontab
X-squared = 1.6667, df = 2, p-value = 0.4346
Warning message:
In chisq.test(Questiontab) : Chi-squared approximation may be incorrect
> prop.test(Questiontab)
3-sample test for equality of proportions without continuity
correction
data: Questiontab
X-squared = 1.6667, df = 2, p-value = 0.4346
alternative hypothesis: two.sided
sample estimates:
prop 1 prop 2 prop 3
0.6666667 0.5000000 0.2500000
Warning message:
In prop.test(Questiontab) : Chi-squared approximation may be incorrect
Note the warning; these tests aren't necessarily appropriate for such small numbers.