0

我是否错过了导致找不到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.
4

1 回答 1

2

鉴于它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)

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

于 2021-03-17T04:50:11.900 回答