predict() 无法从拟合模型中识别变量名称

predict() not recognizing a variable name from a fitted model

我是不是遗漏了什么导致predict.rma()找不到"factor(outcome)"

library(metafor)

dat <- read.csv("https://raw.githubusercontent.com/hkil/m/master/tst.csv")

fit <- rma.mv(d ~ factor(outcome)*time, V = SE^2, random= ~1|id, data = dat)

predict.rma(fit, addx=T, newmods = c("factor(outcome)"=1, time=1))

# Error: Could not find variable 'factor(outcome)' in the model.

鉴于 time 只有 4 个值而 outcome 只有 4 个值,您可以很容易地自动生成 4 x 4 = 16 组合的预测过程:

lvls <- 4   # for factor(outcome)
mat <- rbind(0, diag(lvls-1))
mat
#      [,1] [,2] [,3]
# [1,]    0    0    0
# [2,]    1    0    0
# [3,]    0    1    0
# [4,]    0    0    1
# Combinations of outcome * time
combos <- expand.grid(o=1:4, t=1:4)
vals <- t(with(combos, mapply(function(o, t) c(mat[o,], t, mat[o, ] * t), o, t)))
pvals <- predict.rma(fit, addx=TRUE, newmods = vals)

这给出了所有组合的预测值和置信区间。