2016-09-22 55 views
0

我想通過傾向得分計算權重來運行獨立樣本t檢驗。 Y是結果變量(連續變量),sec是具有兩個類別(代碼0和1)的分組變量。我使用了以下命令:加權後的獨立樣本T檢驗

  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不考慮權重。我如何處理這個問題?

+2

你應該指定你正在使用的軟件包,因爲'wtd.t.test'不在基本狀態 – C8H10N4O2

回答

0

在我看來,結果就在眼前。

 $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

0

你不指定wtd.t.test功能來自哪個包從,所以我會假設使用的函數從「權重」包。根據文件,前兩個參數是來自兩組的數據,第三和第四個參數是兩組觀測值的權重。如果未提供第四個參數,則給定的權重將用於兩個組。這意味着您編寫的代碼正在測試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