在R中进行显着性测试,确定一个列中的比例是否与单个变量中的另一列显着不同

StackOverflow https://stackoverflow.com/questions/8302119

  •  25-10-2019
  •  | 
  •  

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

我试图在R中运行一堆Crosstab(使用Table()命令),每个标签都有两个列(治疗且无处理)。我想知道所有行的列之间的差异是否相互差异(行是调查中的少数答案选择)。我对总体意义不感兴趣,只有在比较治疗与无治疗的串联中。

这种类型的分析在SPSS中非常容易(下面的链接以说明我在说什么),但是我似乎无法在R中使用它。您知道我可以做到吗?

http://help.vovici.net/robohelp/robohelp/server/general/projects_fhpro/survey_workbench_mx/significance_testing.htm

编辑:这是我的意思的一个示例:

 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

我有这样的表格 ^(在处理视频上按列的百分比),我想看看每个问题选择(行)从治疗0到治疗1.想知道4和2(第1行),3和3(第2行)和1和3(第3行)之间是否存在显着差异。因此,在此示例中,问题1的选择可能是选择1和3的显着差异(因为差异为2),但是选择2的差异不是因为差为零。最终,我正在尝试确定这种意义。我希望这会有所帮助。

谢谢!

有帮助吗?

解决方案

使用您的示例,要么 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

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

其他提示

我认为您要寻找的功能是 pairwise.prop.test(). 。看 ?pairwise.prop.test 例如。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top