7

我确信这是 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

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

谢谢!

4

2 回答 2

9

我认为您正在寻找的功能是pairwise.prop.test(). 参见?pairwise.prop.test示例。

于 2011-11-28T20:58:07.547 回答
5

使用您的示例,chisq.testor 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

注意警告;这些测试不一定适用于这么小的数字。

于 2011-11-28T21:53:48.153 回答