# NOT RUN {
### copy data into 'dat' and examine data
dat <- dat.egger2001
### calculate log odds ratios and corresponding sampling variances (but remove ISIS-4 trial)
dat <- escalc(measure="OR", ai=ai, n1i=n1i, ci=ci, n2i=n2i, data=dat, subset=-16)
### fit random-effects model
res <- rma(yi, vi, data=dat)
res
### classical Egger test
regtest(res, model="lm")
### random/mixed-effects version of the Egger test
regtest(res)
### same tests, but passing outcomes directly
regtest(dat$yi, dat$vi, model="lm")
regtest(dat$yi, dat$vi)
### examples using the sample size (or a transformation thereof) as predictor
regtest(res, model="lm", predictor="ni")
regtest(res, model="lm", predictor="ninv")
regtest(res, model="rma", predictor="ni")
regtest(res, model="rma", predictor="ninv")
### if dat$yi is computed with escalc(), sample size information is stored in attributes
dat$yi
### then this will work
regtest(dat$yi, dat$vi, predictor="ni")
### otherwise have to supply sample sizes manually
dat$ni <- with(dat, n1i + n2i)
dat$yi <- c(dat$yi) # this removes the 'ni' attribute from 'yi'
regtest(dat$yi, dat$vi, ni=dat$ni, predictor="ni")
### standard funnel plot (with standard error on y-axis)
funnel(res, refline=0)
### regression test (by default the standard error is used as predictor)
reg <- regtest(res)
reg
### add regression line to funnel plot
se <- seq(0,1.8,length=100)
lines(coef(reg$fit)[1] + coef(reg$fit)[2]*se, se, lwd=2)
### regression test (using the sampling variance as predictor)
reg <- regtest(res, predictor="vi")
### add regression line to funnel plot (using the sampling variance as predictor)
lines(coef(reg$fit)[1] + coef(reg$fit)[2]*se^2, se, lwd=2)
### testing for asymmetry after accounting for the influence of a moderator
res <- rma(yi, vi, mods = ~ year, data=dat)
regtest(res, model="lm")
regtest(res)
# }
Run the code above in your browser using DataLab