【问题标题】:Independent Sample T-Test After Weighting加权后的独立样本 T 检验
【发布时间】:2016-09-22 18:29:16
【问题描述】:

我正在尝试使用通过倾向得分计算的权重进行独立样本 t 检验。 Y 是结果变量(连续变量),sec 是具有两个类别(代码 0 和 1)的分组变量。我使用了以下命令:

          wtd.t.test(Ya1, sec1, weight=weights1T)

产生了以下结果。

         $test
         [1] "Two Sample Weighted T-Test (Welch)"

         $coefficients
           t.value        df   p.value 
         -25.14739 670.43022   0.00000 

         $additional
           Difference       Mean.x       Mean.y     Std. Err 
         -0.496466247  0.003533753  0.500000000  0.019742259 

现在这些结果还不清楚。我想知道两组的平均值。上述结果也没有说明差异是(第 1 组 - 第 0 组)还是(第 0 组 - 第 1 组)。简单的 t.test 不考虑权重。我该如何处理这个问题?

【问题讨论】:

  • 你应该指定你正在使用的包,因为wtd.t.test 不在基本统计中

标签: r weighting


【解决方案1】:

您没有指定 wtd.t.test 函数来自哪个包,所以我假设使用“weights”包中的函数。根据文档,前两个参数是来自两组的数据,第三和第四个参数是两组观察值的权重。如果未提供第四个参数,则给定的权重将用于两组。这意味着您编写的代码正在测试 Ya1 的加权平均值是否与 sec1 的加权平均值不同。这似乎不是您想要做的。我认为 lm 更适合您的用例:

# Make some example data
sec1 <- factor(sample(0:1, replace=TRUE, size=700))
Ya1 <- rnorm(700) + as.numeric(sec1)
weights1T <- 1.4^(rnorm(700))
# Use lm() to perform a weighted t-test
summary(lm(Ya1 ~ sec1, weights=weights1T))

给出:

> summary(lm(Ya1 ~ sec1, weights=weights1T))

Call:
lm(formula = Ya1 ~ sec1, weights = weights1T)

Weighted Residuals:
    Min      1Q  Median      3Q     Max 
-3.1921 -0.6672 -0.0374  0.7025  4.4411 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.92035    0.05376   17.12   <2e-16 ***
sec11        1.11120    0.07874   14.11   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.061 on 698 degrees of freedom
Multiple R-squared:  0.222, Adjusted R-squared:  0.2209 
F-statistic: 199.1 on 1 and 698 DF,  p-value: < 2.2e-16

如果你真的想使用wtd.t.test,你可以这样做:

library(weights)
ysplit <- split(Ya1, sec1)
wsplit <- split(weights1T, sec1)
wtd.t.test(y1split[[1]], y1split[[2]], w1split[[1]], w1split[[2]])

给你的答案几乎和lm()一样:

> wtd.t.test(x=ysplit[[1]], y=ysplit[[2]],
+            weight=wsplit[[1]], weighty=wsplit[[2]])
$test
[1] "Two Sample Weighted T-Test (Welch)"

$coefficients
  t.value        df   p.value 
-13.50571 697.25403   0.00000 

$additional
 Difference      Mean.x      Mean.y    Std. Err 
-1.00357229  1.04628894  2.04986124  0.07430724 

Warning message:
In wtd.t.test(y1split[[1]], y1split[[2]], w1split[[1]], w1split[[2]]) :
  Treating data for x and y separately because they are of different lengths

【讨论】:

    【解决方案2】:

    在我看来,结果就在你面前。

         $additional
           Difference       Mean.x       Mean.y     Std. Err 
         -0.496466247  0.003533753  0.500000000
    

    Mean.xMean.y 为您提供第一组和第二组的平均值(您在代码中称为组 0 和 1,或 Ya1sec1)。

    Difference 显然是 Mean.x 减去 Mean.y

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-26
      • 1970-01-01
      • 1970-01-01
      • 2020-05-21
      • 1970-01-01
      • 2018-05-17
      • 2020-02-13
      • 2014-05-01
      相关资源
      最近更新 更多