Significance testing in R, determining if the proportion in one column is significantly different from the other column within the single variable
Asked Answered
M

2

7

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?

http://help.vovici.net/robohelp/robohelp/server/general/projects_fhpro/survey_workbench_MX/Significance_testing.htm

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!

Muticous answered 28/11, 2011 at 20:48 Comment(2)
It will be easier for folks to answer your question if you provide a reproducible example, including a small example data set.Claro
sorry about that. I just edited my question with an R exampleMuticous
B
5

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.

Bloodstock answered 28/11, 2011 at 21:53 Comment(0)
D
9

I think the function you're looking for is pairwise.prop.test(). See ?pairwise.prop.test for an example.

Dianthe answered 28/11, 2011 at 20:58 Comment(1)
Thanks John, but that isn't quite what I'm asking for. My fault, I should have been clearer in my question. I have now updated my question with an R example. I hope that helps clarify.Muticous
B
5

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.

Bloodstock answered 28/11, 2011 at 21:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.