# Shouldn't a weighted t-test and a weighted linear regression yield the same standard error on the estimated mean?

I have a vector of values and a vector of the reciprocal of their standard error. I'd like to estimate their mean and the standard error on the mean.

At first I used linear regression using the lm() function. Later I found out that the weights library provided a wtd.t.test() function for doing t-tests on weighted data. One side-effect of the test is an estimate of the mean of the data, with a standard error.

I expected both approaches to yield the same result, but they don't.

Here is a short but complete example:

library(weights)
test <- c(1,1,1,1,1,1,2,2,2,3,3,3,4,4)
weight <- c(.5,.5,.5,.5,.5,1,1,1,1,2,2,2,2,2)
wtd.t.test(test, weight=weight)
summary(lm(test~1, weights=weight))


The weighted t-test yields 2.64 +/- 0.27, whereas the linear regression yields 2.64 +/- 0.30. Which is correct (if any)?

• I wonder if the regression is using sampling weights (weights that denote the inverse of the probability that the observation is included because of the sampling design) and the t-test is using importance weights. That is what I get with Stata using your data. Commented Jun 18, 2014 at 21:59

Probably because the weight in wtd.t.test is treated as a frequency weight but in lm it is treated as an analytical/proportion weight.
If you try multiply the variable weight by 2 or 3 and refit the t-test and regression, you'll find that the SE of the regression model does not change, while the degrees of freedom in wtd.t.test keeps increasing (and SE shrinking.)
It is not clear what wtd.t.test really does when you give it only one set of data. The help page and the output indicates that it is doing a 2 sample test (with a default value of 0 for y). So it is really not doing the same test as lm.
I would expect more similarity if you do a 2 sample test for both. But there is still possibility of difference if wtd.t.test does not use a pooled variance (I could not find anything in the documentation that says whether it assumes equal variance or not, the lm approach does fit a pooled variance).