Crosshairs is a program written in R. You may dowload it from CRAN and install it as a package. This vignette illustrates the use of the package. Installing and running the package is what you want if you are not familiar with programming in R. You may also retrieve the R code from GitHub and edit it to serve your own purpose. The following shows you the R code input and output. You can find original version of this file in my web site.
Download and install metaplotr
. Open R or RStudio, and call the library (see below). You may want to run the help files to see a description of the contents.
library(metaplotr)
You can read an overview of the package using help()
function.
help('metaplotr')
You can also see help content of crosshairs()
function.
help('crosshairs')
Before start experimenting with crosshairs()
function, let’s clean working environment that you are currently working.
rm(list = ls())
We are going to work with FergusonBrannick2012
data frame, so we will attach it. Attaching a data frame makes it easy to reach its variables.
attach(FergusonBrannick2012)
The lines below produces the graph below.
crosshairs(pub_z, dis_z, pub_z_se, dis_z_se)
Adjust the uncertainity represented by whisker length.
# confint option can control whiskers length.
crosshairs(pub_z, dis_z, pub_z_se, dis_z_se, confint = .7)
# You can see results of different whisker lengths.
crosshairs(pub_z, dis_z, pub_z_se, dis_z_se, confint = .95)
crosshairs(pub_z, dis_z, pub_z_se, dis_z_se, confint = .3)
You can turn whiskers off.
# use whis_on argument.
crosshairs(pub_z, dis_z, pub_z_se, dis_z_se, whis_on = FALSE)
You can create your own labels.
# Main and axes labels can be changed.
crosshairs(pub_z, dis_z, pub_z_se, dis_z_se,
main_lab = 'Published vs. Dissertation Effect Sizes',
x_lab = 'Published Studies',
y_lab = 'Dissertations')
Descriptives can be addet to the graph.
# We will use another data set by attaching it.
attach(Sweeney2015)
# You can find information regarding this data set as usual.
# help('Sweeney2015')
# Add descriptive statistics to graph.
crosshairs(inten_d, beh_d, inten_se, beh_se,
main_lab = 'Sweeney (2015) Data',
x_lab = 'Intentions',
y_lab = 'Behaviors',
annotate = TRUE) # use annotate argument
You can hide boxplots.
# Boxplots will be hidden.
crosshairs(inten_d, beh_d, inten_se, beh_se,
main_lab = 'Sweeney (2015) Data',
x_lab = 'Intentions',
y_lab = 'Behaviors',
annotate = TRUE,
bxplts = FALSE)
You can add a moderator and label it. The position of the label is indicated by two numbers (see the code). I adjust the position by trial and error, although more sophisticated users know how to find positions on the graph using R code.
# Add moderator and label.
attach(GenderDiff02) # attach dataframe to working environment
## The following objects are masked from Sweeney2015:
##
## author, year
# help('GenderDiff02')
crosshairs(men_z, women_z, men_se, women_se,
main_lab = 'Ali et al. Psychopathology and Parental Acceptance',
x_lab = 'Men',
y_lab = 'Women',
mdrtr = region,
mdrtr_lab = 'Region',
mdrtr_lab_pos = c(.1, .5))
To plot empirical Bayes estimates against the original effect sizes, you will need to run a program to generate the empirical Bayes values. I used the program metafor to do this.
# McLeod2007 data frame is used in this graph.
# help('McLeod2007')
attach(McLeod2007) # attach dataframe to working environment
## The following objects are masked from GenderDiff02:
##
## author, year
## The following objects are masked from Sweeney2015:
##
## author, year
# metafor package is needed for this graph. If you do not have this package use
# install.packages('metafor')
# and load metafor.
library(metafor)
## Loading required package: Matrix
## Loading 'metafor' package (version 1.9-8). For an overview
## and introduction to the package please type: help(metafor).
# using rma() function of metafor package.
res1 <- rma(yi = z, vi = var, method = 'DL', data = McLeod2007)
# Estimates best linear unbiased predictors.
res2 <- blup(res1)
# You can see the resuling data frame.
head(res2, 15)
## pred se pi.lb pi.ub
## 1 0.2695 0.0885 0.0960 0.4430
## 2 0.0913 0.0663 -0.0386 0.2213
## 3 0.1982 0.0660 0.0688 0.3275
## 4 0.2205 0.0681 0.0870 0.3540
## 5 0.1250 0.0777 -0.0274 0.2773
## 6 0.2169 0.0713 0.0771 0.3567
## 7 0.2398 0.0663 0.1099 0.3698
## 8 0.2075 0.0740 0.0624 0.3526
## 9 0.2795 0.0823 0.1182 0.4408
## 10 0.2184 0.0955 0.0312 0.4056
## 11 0.2761 0.0436 0.1907 0.3615
## 12 0.2520 0.0789 0.0973 0.4067
## 13 0.2305 0.0843 0.0652 0.3958
## 14 0.0879 0.0650 -0.0395 0.2153
## 15 0.1939 0.0681 0.0604 0.3274
# Assign data to x, standard error of x, y, standard error of y,
# variable name of a moderator (if any) here. Note how the names
# and values of the x variables come from the McLeod2007 dataset.
# The names and values of the shrunken estimates came from
# the output of the metafor program.
x1 <- McLeod2007$z
se.x1 <- sqrt(McLeod2007$var)
y1 <- res2$pred
se.y1 <- res2$se
# Create the plot.
crosshairs(x1, y1, se.x1, se.y1,
main_lab = 'Effects of Empirical Bayes Estimation',
x_lab = 'Parenting and Depression Correlations',
y_lab = 'Shrunken Estimates',
annotate = TRUE,
whis_on = FALSE)
That’s pretty much everything the program does at the moment.