【问题标题】:T test in a cross tabulated table交叉表中的 T 检验
【发布时间】:2017-10-20 02:13:55
【问题描述】:

我有一张这样的桌子:

 1   2   3   4   5
 10  22  15  14  3
 15  44  22  26  9
 ...more rows

我想在单行上运行测试,看看它的平均值是否小于 3。使用 t.test(table[x, ]) 不起作用,因为它假设我有兴趣在行中的值的平均值中,我不是:这些值仅表示对每个值的响应数,范围为 1-5。

怎么做?

【问题讨论】:

    标签: r


    【解决方案1】:

    您可以使用以下方法:

    1. 取消分组数据
    2. 对每一行应用 t.test

    apply(data, 1, function(data) {t.test( rep(1:5, times = data), alternative = "less", mu = 3)})

    将为每一行返回一个 t 检验,例如:

    [[1]]
    
    One Sample t-test
    
    data:  rep(1:5, times = data)
    t = -2.4337, df = 63, p-value = 0.008896
    alternative hypothesis: true mean is less than 3
    95 percent confidence interval:
      -Inf 2.892043
    sample estimates:
      mean of x 
    2.65625 
    
    
    [[2]]
    
    One Sample t-test
    
    data:  rep(1:5, times = data)
    t = -2.3745, df = 115, p-value = 0.009613
    alternative hypothesis: true mean is less than 3
    95 percent confidence interval:
      -Inf 2.921981
    sample estimates:
      mean of x 
    2.741379 
    

    如果您只想要 p 值,请添加 $p.value:

    apply(data, 1, function(data) {t.test( rep(1:5, times = data), alternative = "less", mu = 3)$p.value})
    
    [1] 0.008895887 0.009613075
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 2018-03-09
      • 2018-06-13
      • 2012-01-13
      • 2014-08-19
      相关资源
      最近更新 更多