I am doing an analysis with complex survey data in R. However when I use svyttest from the survey package to preform a design base t-test, it is not providing the correct difference in mean
svyby(~preds,~SDDSRVYR,svymean, design=subset(data, age==2))
SDDSRVYR preds se
7 7 0.2340050 0.01161363
10 10 0.3159294 0.01076532
tt<-svyttest(preds~SDDSRVYR, design=subset(data, age==2))
> tt
Design-based t-test
data: preds ~ SDDSRVYR
t = 5.1734, df = 30, p-value = 1.428e-05
alternative hypothesis: true difference in mean is not equal to 0
95 percent confidence interval:
0.01696236 0.03765392
sample estimates:
difference in mean
0.02730814
As you can see, the difference in means is about 0.082, but the t test is showing its 0.03. Am I not understanding how the t-test is calculating the means? I can't imagine it would be any different than svymean...Or perhaps this is a coding issue?
I found the answer-SDDSRVYR was being treated as continuous (it takes the values 7 and 10). Not binary
svyttest(preds~factor(SDDSRVYR), design=subset(data, age==2))
Design-based t-test
data: preds ~ factor(SDDSRVYR)
t = 5.1734, df = 30, p-value = 1.428e-05
alternative hypothesis: true difference in mean is not equal to 0
95 percent confidence interval:
0.05088707 0.11296176
sample estimates:
difference in mean
0.08192442