I fitted a model using the metafor package with a moderator interaction for which there is no data for a combination of factor levels.
data(fish)
warm_dat <- fish
warm_dat$factor2<-as.factor(seq(c("A","B","C"),133) )
mod_fit <- metafor::rma.mv(yi = lnrr, V = lnrr_vi,
random = list(~1 | group_ID, ~1 | es_ID),
mods = ~ trait.type*factor2,
method = "REML", test = "t",
control=list(optimizer="optim", optmethod="Nelder-Mead"), data = warm_dat)
I wanted to use the orchaRd package to obtain mean effect sizes and confidence intervals but I get an error.
results1 <- mod_results(mod_fit, group = "group_ID", mod = "trait.type", by = "Measurement_cat")
results2 <- mod_results(mod_fit, group = "group_ID", mod = "trait.type")
Error in ref_grid(result, …) : Something went wrong:
Non-conformable elements in reference grid.
I had a look at the code used in mod_results and found that it relies on emmeans. I tried to adapt the code by manually adding the missing combination of factor levels to the reference grid but the results I obtained were identical to estimates provided by the summary function.
coef1<-mod_fit$b
coef1[12]<-NA
names(coef1)<-c(row.names(mod_fit$b),"trait.typelife-history:factor2C")
vcov1<-stats::vcov(mod_fit)
vcov1<- rbind(vcov1,rep(NA, times=11))
vcov1<- cbind(vcov1,rep(NA, times=12))
row.names(vcov1)<-c(row.names(vcov(mod_fit)),"trait.typelife-history:factor2C")
colnames(vcov1)<-row.names(vcov1)
grid <- emmeans::qdrg(formula = stats::formula(mod_fit),
data = warm_dat, coef = coef1, vcov = vcov1,
df = mod_fit$k - 1)
mm <- emmeans::emmeans(grid, specs =~trait.type * factor2, df = as.numeric(mod_fit$ddf[[1]]))
mm_pi <- pred_interval_esmeans(mod_fit, mm, mod = ESR_step)
Any suggestions as to how to obtain estimates and confidnece intervals in this instance would be much appreciated.