당신은 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
'wtd.t.test'가 기본 통계에 없으므로 사용중인 패키지를 지정해야합니다 – C8H10N4O2