如何解决predict() 无法识别拟合模型中的变量名称
我是否遗漏了导致 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)
这给出了所有组合的预测值和置信区间。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。