With regard to my other issue, where I described the case with multiply imputed data, I took the code from your package and changed it a little to allow for pooling emmeans rather than analysis objects.
This is especially helpful when we need to do a pooled analysis using some special features of the used modelling package, not handled out of the box by emmeans.
The function - adaptation of your emmeans:::emm_basis.mira code:
pool_emmeans <- function(emmeans_list) {
bas = emmeans_list[[1]]
k = length(emmeans_list)
V = 1/k * bas@V
allb = cbind(bas@bhat, matrix(0, nrow = length(bas@bhat), ncol = k - 1))
for (i in 1 + seq_len(k - 1)) {
basi = emmeans_list[[i]]
V = V + 1/k * basi@V
allb[, i] = basi@bhat
}
bas@bhat = apply(allb, 1, mean)
notna = which(!is.na(bas@bhat))
bas@dfargs$m = k
bas@dfargs$df1 = bas@dffun
bas@dfargs$B = cov(t(allb[notna, , drop = FALSE]))
bas@V = bas@dfargs$T = V + (k + 1)/k * bas@dfargs$B
bas@dffun = function(a, dfargs) {
dfcom = dfargs$df1(a, dfargs)
with(dfargs, {
b = sum(a * (B %*% a))
t = sum(a * (T %*% a))
lambda = (1 + 1/m) * b/t
dfold = (m - 1)/lambda^2
dfobs = (dfcom + 1)/(dfcom + 3) * dfcom * (1 - lambda)
ifelse(is.infinite(dfcom), dfold, dfold * dfobs/(dfold + dfobs))
})
}
return(bas)
}
With regard to my other issue, where I described the case with multiply imputed data, I took the code from your package and changed it a little to allow for pooling emmeans rather than analysis objects.
This is especially helpful when we need to do a pooled analysis using some special features of the used modelling package, not handled out of the box by emmeans.
The function - adaptation of your
emmeans:::emm_basis.mira
code:An exemplary use:
Would you consider adding this little "helper" to your package?