```
# NOT RUN {
### copy BCG vaccine data into 'dat'
dat <- dat.bcg
### calculate log risk ratios and corresponding sampling variances
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat)
### fit random-effects model
res <- rma(yi, vi, data=dat, slab=paste(dat$author, dat$year, sep=", "))
### draw a standard funnel plot
funnel(res)
### show risk ratio values on x-axis (log scale)
funnel(res, atransf=exp)
### label points outside of the pseudo confidence interval region
funnel(res, atransf=exp, label="out")
### passing log risk ratios and sampling variances directly to the function
### note: same plot, except that reference line is centered at zero
funnel(dat$yi, dat$vi)
### can accomplish the same thing by setting refline=0
funnel(res, refline=0)
### adjust the position of the x-axis labels, number of digits, and y-axis limits
funnel(res, atransf=exp, at=log(c(.125, .25, .5, 1, 2)), digits=3L, ylim=c(0,.8))
### contour-enhanced funnel plot centered at 0 (see Peters et al., 2008)
funnel(res, level=c(90, 95, 99), shade=c("white", "gray55", "gray75"), refline=0, legend=TRUE)
### same, but show risk ratio values on the x-axis and some further adjustments
funnel(res, level=c(90, 95, 99), shade=c("white", "gray55", "gray75"), digits=3L, ylim=c(0,.8),
refline=0, legend=TRUE, atransf=exp, at=log(c(.125, .25, .5, 1, 2, 4, 8)))
### illustrate the use of vectors for 'pch' and 'col'
res <- rma(yi, vi, data=dat, subset=2:10)
funnel(res, pch=ifelse(dat$yi > -1, 19, 21), col=ifelse(sqrt(dat$vi) > .3, "red", "blue"))
### can add a second funnel via (undocumented) argument refline2
funnel(res, atransf=exp, at=log(c(.125, .25, .5, 1, 2, 4)), digits=3L, ylim=c(0,.8), refline2=0)
### mixed-effects model with absolute latitude in the model
res <- rma(yi, vi, mods = ~ ablat, data=dat)
### funnel plot of the residuals
funnel(res)
### simulate a large meta-analytic dataset (correlations with rho = 0.2)
### with no heterogeneity or publication bias; then try out different
### versions of the funnel plot
gencor <- function(rhoi, ni) {
x1 <- rnorm(ni, mean=0, sd=1)
x2 <- rnorm(ni, mean=0, sd=1)
x3 <- rhoi*x1 + sqrt(1-rhoi^2)*x2
cor(x1, x3)
}
set.seed(1234)
k <- 200 ### number of studies to simulate
ni <- round(rchisq(k, df=2) * 20 + 20) ### simulate sample sizes (skewed distribution)
ri <- mapply(gencor, rep(0.2,k), ni) ### simulate correlations
res <- rma(measure="ZCOR", ri=ri, ni=ni, method="FE") ### use r-to-z transformed correlations
funnel(res, yaxis="sei")
funnel(res, yaxis="vi")
funnel(res, yaxis="seinv")
funnel(res, yaxis="vinv")
funnel(res, yaxis="ni")
funnel(res, yaxis="ninv")
funnel(res, yaxis="sqrtni")
funnel(res, yaxis="sqrtninv")
funnel(res, yaxis="lni")
funnel(res, yaxis="wi")
# }
```

Run the code above in your browser using DataCamp Workspace