0

我正在进行荟萃分析,需要分析多个主持人。我正在使用 rma.uni 函数,并且代码对于我正在测试的所有版主都将保持不变:

res <- rma.uni(method = "HS", measure = "SMD", m1i = EXPM, m2i = CONM, sd1i = EXPSD, sd2i = CONSD, n1i = EXPN, n2i = CONN, slab=paste(AUTHOR, YEAR, sep=", "), data = outcomeData)

我想添加参数“mods = ~ x”,其中 x 是我正在测试的版主(例如 YEAR 或 AUTHOR),然后执行版主组合列表的 for 循环。

我尝试了几种不同的方法,但无法解释错误消息。

mod.test <- c("AUTHOR", "YEAR")

for (i in mod.test){
  res <- rma.uni(method = "HS", measure = "SMD", m1i = EXPM, m2i = CONM, sd1i = EXPSD, sd2i = CONSD, n1i = EXPN, n2i = CONN, slab=paste(AUTHOR, YEAR, sep=", "), mods = ~ i, data = outcomeData)
  print(res)
}

mod.test <- c("AUTHOR", "YEAR")

for (x in mod.test){
  i <- paste("mods = ~ ", x)
  res <- rma.uni(method = "HS", measure = "SMD", m1i = EXPM, m2i = CONM, sd1i = EXPSD, sd2i = CONSD, n1i = EXPN, n2i = CONN, slab=paste(AUTHOR, YEAR, sep=", "), mods = ~ i, data = outcomeData)
  print(res)
}

两者都给出错误:

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels

谢谢你的帮助。

4

2 回答 2

0

由于我不知道您使用的数据集,因此我使用了基础数据。

您需要使用直接索引而不是给出名称。在您的情况下,请尝试outcomeData[[i]]在循环内。我稍微更改了您的模型,因为我的数据中的列名与您的不匹配。

mod.test <- c("author", "year")

for (i in mod.test){
print(i)
res <- rma.uni(method = "HS", measure = "SMD",
 m1i = ablat, m2i = ablat, sd1i = ablat, sd2i = ablat,
 n1i = ablat, n2i = ablat, 
slab=paste(author, year, sep=", "),mods= ~dat.bcg[[i]],data = dat.bcg)

  print(res)
}

所以在你的情况下,试试这个。

mod.test <- c("AUTHOR", "YEAR")

for (i in mod.test){
  res <- rma.uni(method = "HS", measure = "SMD", m1i = EXPM, 
            m2i = CONM, sd1i = EXPSD, sd2i = CONSD, 
            n1i = EXPN, n2i = CONN, slab=paste(AUTHOR, YEAR, sep=", "), 
            mods = ~outcomeData[[i]], data = outcomeData)
  print(res)
}

您可以在问题中找到有关此的更多信息。

于 2018-07-23T08:43:18.680 回答
0

我按照 Maydin 的建议做了,这是我的固定代码。

mod.test <- c("YEAR", "TASK")

for (i in mod.test){
  res <- rma.uni(method = "HS", measure = "SMD", 
                 m1i = EXPM, m2i = CONM, sd1i = EXPSD, 
                 sd2i = CONSD, n1i = EXPN, n2i = CONN, 
                 slab=paste(AUTHOR, YEAR, sep=", "), 
                 mods = ~outcomeData[[i]], 
                 data = outcomeData)
  print(i)
  print(res)

一个困难是我使用“AUTHOR”作为测试版主,但这会导致错误:

Error in rma.uni(method = "HS", measure = "SMD", m1i = EXPM, m2i = CONM,  : 
  Number of parameters to be estimated is larger than the number of observations.
In addition: Warning message:
In rma.uni(method = "HS", measure = "SMD", m1i = EXPM, m2i = CONM,  :
  Redundant predictors dropped from the model.

我认为是因为每项研究在我的示例数据集中都有一个独特的作者。

于 2018-07-23T12:27:12.390 回答