Question 1. What would be the best way to calculate the standard error across subjects? Would it simply be to perform the fit for each subject, and then take the standard deviation of the fits?
Option 1: Use weighted least squares. The Gauss Markov theorem tells us that the inverse variance weighted standard error estimator will be the Best Linear Unbiased Estimator (BLUE). Note that although the mean model is correct, and consequently the unweighted estimate is unbiased, there is added efficiency of using the iterative generalized least squares estimator to provide a better estimate of the residuals. It helps to identify the appropriate degrees of freedom for the intracluster variance. For reference, I've included the two-stage estimate, but I have trouble identifying the correct degree of freedom correction.
One interesting result that I'm working on is the idea that off-the-box software with options for intracluster correlation can provide consistent estimates of heteroscedasticity. That is, regardless of whether a sample is highly intracorrelated or highly variable, the net effect is a downweighting of that sample, and so the same optimal standard error can be obtained in either case.
Using unweighted residuals to estimate cluster variance, I'm finding is that it's hard to identify the appropriate degree of freedom for the intracluster variance estimate. I'm adding my code below for others to verify. $n-1$ is too conservative, and $n-2$ is too conservative.
Option 2: Use the sandwich variance estimator (heteroscedasticity consistent) or bootstrap.
Question 2: What would the shape of the standard error of the fit look like, and what is the intuition behind that? Would it still be hyperbolic? I don't think it would, but actually really not sure.
The limiting distribution of the error distribution is still normal provided that the sample "grows faster" in terms of number of time points rather than in the number of subjects, or at least such that subject level heteroscedasticity is somewhat bounded. The intuition is that it is a result of the Lyapunov central limit theorem.
require(gee)
`%covers%` <- function(x, y) x[1] < y & y < x[2]
sse.df <-function(x, df=1) {
sum({x-mean(x)}^2)/{length(x)-df}
}
confint.gee <- function (object, parm, level = 0.95, ...)
{
cf <- coef(object)
pnames <- names(cf)
if (missing(parm))
parm <- pnames
else if (is.numeric(parm))
parm <- pnames[parm]
a <- (1 - level)/2
a <- c(a, 1 - a)
# pct <- format.perc(a, 3)
pct <- paste0(formatC(100*a, format='f', digits=1), '%')
fac <- qnorm(a)
ci <- array(NA, dim = c(length(parm), 2L), dimnames = list(parm,
pct))
# ses <- sqrt(diag(vcov(object)))[parm]
ses <- sqrt(diag(object$robust.variance))[parm]
ci[] <- cf[parm] + ses %o% fac
ci
}
do.one <- function() {
s1 <- 1
s2 <- 1
nc <- 8
nt <- 20
i <- rep(1:8, each=nt)
e <- rnorm(nc, 0, s1)[i] + rnorm(nc*nt, 0, s2)
x <- rep(seq(-3, 3, length.out = nt), times=nc)
y <- 2*x + e
r <- lm.fit(cbind(1,x), y)$residuals
wls <- lm(y ~ x, weights=rep(1/tapply(r^2, i, sse.df, df=1), each=nt))
gls <- gls(y ~ x, correlation=corCompSymm(form=~1|i))
gee <- gee(y ~ x, id = i)
c( ## coverage of 80% CIs
confint(wls, parm='x', level = .8) %covers% 2,
confint(gee, parm='x', level = .8) %covers% 2,
confint(gls, parm='x', level= 0.8) %covers% 2,
vcov(wls)[2,2]^.5,
gee$robust.variance[2,2]^.5,
vcov(gls)[2,2]^.5
)
}
set.seed(123)
out <- replicate(500, do.one())
## 80% coverage of CIs
rowMeans(out[1:3, ])
par(mfrow=c(1,3))
hist(out[4, ], xlab='Sigma two-pass', main='')
hist(out[5, ], xlab='Sigma GEE', main='')
hist(out[6, ], xlab='Sigma GLS', main='')
Gives us coverage of 70% for 2 degree of freedom WLS and 74% for the GEE. and 82.54% for GLS. Histograms of the standard error estimates show a closely normal distribution in all cases.
