I am interested - mostly just for my own knowledge, and not for any real problem - in the use of weighted least squares to estimate a model on individual-level data and aggregated versions of those same data. Here's some simple R code to show what I'm talking about. Basically, I estimate a regression model lm1
on some data (old
), then I aggregate the data (to create new
) so that I only have one observation for each combination of $X1$, $X2$, and $Y$, and weight based on the number of observations at each combination of $X1$, $X2$, and $Y$.
The resulting coefficients in a regression (lm2
) on new
are the same as those in lm1
, but the standard errors are larger. But they are larger by a fixed amount (i.e., the SEs from lm1
are proportionate to one another). How do I figure out what that ratio is? I've searched around for calculations of SEs for weighted least squares, but that has proved unhelpful.
set.seed(1)
n <- 1000
old <- data.frame(x1=sample(1:3,n,TRUE), x2=sample(1:3,n,TRUE))
old$y <- old$x1 + old$x2 + sample(-3:3,n,TRUE)
old$i <- with(old, interaction(x1,x2,y, drop=TRUE))
levels(old$i) <- seq_along(levels(old$i))
s <- split(old, old$i)
new <- do.call(rbind, lapply(s, `[`, 1, 1:4))
new$w <- sapply(s, nrow)
lm1 <- lm(y ~ x1 + x2, data=old)
lm2 <- lm(y ~ x1 + x2, data=new, weights=w)
# coefficients equal?
all.equal(coef(lm1),coef(lm2))
## [1] TRUE
# ratio of SEs
summary(lm1)$coef[,2]/summary(lm2)$coef[,2]
## (Intercept) x1 x2
## 0.2453172 0.2453172 0.2453172
Why are the SEs from the aggregated model proportionate to those from the individual-level model? And how do I know what their ratio is?
Var(y)
, and maybe other things. $\endgroup$sample ()
take uniformly distributed values when you set the first input to an interval? Could you perhaps edit the question with a description of the model? $\endgroup$