2016-09-22 3 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를 호출하는 것) 제 1 및 제 2 그룹의 평균을 제공합니다.

Difference 명확하게 Mean.x 마이너스 Mean.y

0

당신은 wtd.t.test 기능에서 제공하는 패키지를 지정하지 않는, 그래서는 "무게"패키지에서 기능을 사용하여 가정합니다입니다. 문서에 따르면 첫 번째 두 인수는 두 그룹의 데이터이며 세 번째 및 네 번째 인수는 두 그룹의 관측에 대한 가중치입니다. 네 번째 인수가 제공되지 않으면 주어진 가중치가 두 그룹에 사용됩니다. 즉, 작성한 코드는 Ya1의 가중 평균이 sec1의 가중 평균과 다른지 테스트하는 것입니다. 이것은 당신이 원하는 것처럼 보이지 않습니다.

# 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)) 

제공 : 당신이 정말로 wtd.t.test를 사용하려면

> 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 

, 당신은 다음과 같이 수행 할 수 있습니다 : 나는 필름이 사용 사례에 대한 더 적합하다고 생각

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