随机效应元分析模拟:tau ^ 2的零估计

时间:2019-06-05 22:50:37

标签: r statistics simulation random-effects

我正在模拟一个随机效应模型,以比较R中的DerSimonian-Laird方法与Hartung-Knapp-Sidik-Jonkman方法。为此,我选择了mu的不同组合(真实处理)效应),tau ^ 2(研究间差异)和p1(第1组的基线风险)。对于这些参数的总共8个组合,我想运行2000组荟萃分析。 问题是:在80%到90%的情况下,tau ^ 2的估计量等于零,我只是不明白为什么。我不太确定我使用meta-package实现的两种方法是否正确。

我的代码可能无效,并且不够精确,但是我希望它很好阅读,并且就我的目的而言,它足够快。另外,我认为代码并不是什么大问题,因为上面的问题似乎是在执行metagen-function之后产生的。另外,metafor包中的rma函数返回的结果与metagen不同,但是解决方案(Differences between results from meta and metafor packages in R)对我没有帮助。 任何帮助将不胜感激,因为我完全受不了这个帮助。

# set szenario
k = c(5)  #number of studies
N = c(40, 40, 40, 40, 40) # total N for each study

#define dataframe for results
resultsHfin=data.frame()
resultsDfin=data.frame()

#alter mu (real risk difference), ttau (real between-study-variance) and 
p1 (baseline-risk of control group) 
for (i in 0:1){
mu = (i*2/3)
for (j in 1:2){
ttau = (j*0.05)
for (t in 1:2) {
  p1 = ((t^2)*0.05)

#repeat 1000 times (to keep it simple it is just 30 times       here)
for (r in 1:30) {

# simulate sample effect for each study
mui = rnorm(n=k, mean=mu, sd=sqrt(ttau))

##### Simulate Group 1 ##### 
# assume equal numbers in each treatment arm (so n1 is N/2)
n1 = floor(N/2)

# simulate a, number of successes in group 1

a = rbinom(n=k, size=n1, prob=p1)

##### Simulate Group 2 ##### 
# calculate n for this group
n2 = N - n1

# figure out p(success) in this group using log odds
p2 = p1/(p1-exp(mui)*p1+exp(mui))

# simulate c, number of successes in group 2
c = rbinom(n=k, size=n2, prob=p2)

##### Do Analysis #####
require(metafor)
require(meta)

# calculate descriptive statistics
desc = escalc(measure="OR", ai=a, bi=n1-a, ci=c, di=n2-c, to = "if0all", 
add = 1/2, drop00 = FALSE)

# get observed treatment effect and estimated within-study variances for 
each study
ote = desc$yi
ewsv = desc$vi

# compute DSL-method
DSL = rma(yi = ote, vi = ewsv, method = "DL", measure = "OR", to = 
"if0all", add = 1/2, drop00 = FALSE)
DSL1 = metagen(TE = ote, seTE = ewsv, comb.fixed = FALSE, comb.random = 
TRUE, 
method.tau = "DL", hakn = FALSE, prediction=TRUE, sm="OR")

# compute HKSJ-method
HKSJ = metagen(TE = ote, seTE = ewsv, comb.fixed = FALSE, comb.random = 
TRUE, method.tau = "SJ", hakn = TRUE, prediction=TRUE, sm="OR")

#extract tau, est. mu and CI from HKSJ
resultsHKSJ = data.frame(HKSJ$TE.random, HKSJ$seTE.random, 
HKSJ$lower.random, 
HKSJ$upper.random, (HKSJ$tau)^2, HKSJ$I2, HKSJ$pval.random)

#extract tau, est. mu and CI from DSL

resultsDSL = data.frame(DSL$b[1], DSL$se, DSL$ci.lb, DSL$ci.ub, DSL$tau2, 
DSL$I2, DSL$pval)

#add results

resultsHfin=rbind(resultsHfin, resultsHKSJ)

resultsDfin=rbind(resultsDfin, resultsDSL)

#here you can see my problem
print(resultsDfin); print(resultsHfin)
}

#then i addded some code to sum up the results and their means in a 
dataframe, as i did with resultsHfin and resultsDfin 
#and finally got to clean results for the next iteration 
resultsDfin=data.frame(); resultsHfin=data.frame()
}}}

0 个答案:

没有答案