R中的显着性检验,确定一列中的比例是否与单一变量中的另一列显着不同

Cap*_*phy 7 r significance crosstab

我确信在R中这是一个简单的命令,但由于某种原因,我很难找到解决方案.

我正在尝试在R中运行一堆交叉表(使用table()命令),每个选项卡有两列(处理和不处理).我想知道列之间的差异是否对于所有行而言彼此显着不同(行是调查中的一些答案选择).我对整体意义不感兴趣,只是在交叉表比较治疗与不治疗之间.

这种类型的分析在SPSS中很容易(下面链接说明我在说什么),但我似乎无法让它在R中工作.你知道我能做到吗?

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

编辑:以下是关于我的意思的R的一个例子:

 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
Run Code Online (Sandbox Code Playgroud)

我有像这样的表^(由treatmentVar上的列百分比),我想看看从治疗0到治疗1的每个问题选择(行)之间是否存在显着差异.所以在上面的例子中,我会想知道4和2(第1行),第3和第3行(第2行)以及第1和第3行(第3行)之间是否存在显着差异.所以在这个例子中,question1的选择对于选择1和3可能是显着不同的(因为差异是2)但是选择2的差异不是因为差异是零.最终,我试图确定这种重要性.我希望有所帮助.

谢谢!

Joh*_*lby 9

我认为你正在寻找的功能是pairwise.prop.test().请参阅?pairwise.prop.test示例.


Bri*_*ggs 5

使用您的示例,chisq.test或者prop.test(在这种情况下等效):

> 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
Run Code Online (Sandbox Code Playgroud)

注意警告; 这些测试不一定适合这么小的数字.