clubSandwich icon indicating copy to clipboard operation
clubSandwich copied to clipboard

Issue when a coefficient is just estimated by a single observation

Open wviechtb opened this issue 2 years ago • 1 comments

I recently came across a situation in the context of a meta-analysis where a model coefficient is just estimated by a single observation. Consider the following example:

library(metafor)
dat <- dat.bcg
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat, subset=-5)
res <- rma(yi, vi, data=dat, mods = ~ 0 + alloc)
res

The coefficient for allocalternate is just the observed effect for this level (i.e., dat[5,]). As a result, when using the sandwich method, the variance for this coefficient is equal to zero:

library(clubSandwich)
vcovCR(res, cluster=dat$trial, type="CR2")

Both coef_test() and conf_int() run and give NaN/NA where applicable:

coef_test(res, cluster=dat$trial, vcov="CR2")
conf_int(res, cluster=dat$trial, vcov="CR2")

But Wald_test() craps out:

Wald_test(res, cluster=dat$trial, vcov="CR2", constraints=constrain_zero(1:3))

Obviously, it can't actually run the test, but it might be nice if it handles this edge case a bit more gracefully.

wviechtb avatar Aug 28 '22 10:08 wviechtb

Thanks for this suggestion. I'll look into it.

jepusto avatar Aug 29 '22 13:08 jepusto