Meta-analysis in R: Part 1 – Installing the software
When I am teaching about meta-analysis on the EVIT course, I often moan about the inflexibility of Cochrane’s Revman software and am asked what I use to perform my meta-analyses.
My pechant for open-source software led me to use the R statistical environment. In this series of blog posts, that I will update over the coming weeks, I will run through the steps of installing R and associated tools and getting set-up for meta-analysis. I will also explain how to create attractive forest and funnel plots for publication, and use some of the more advanced features such as mixed effects meta-analysis and tests for publication bias.
What is R?
R is a statistical programming language, akin to Stata, SPSS and many other statistical software packages. It is based on the S statistical environment, and provides a wide variety of statistical methods and graphical tools which enable the production of publication standard graphics.
The major advantage of R is that it is “open-source” software – it is free to use and distribute unlike the very expensive commercial packages. It is also freely available for Windows, Mac OS X and Unix platforms, and is extensible with downloadable packages and user-defined functions.
Using R for meta-analysis
There are a number of packages available for R which provide functions for meta-analysis, including graphical capabilities such as forest plots and funnel plots, heterogeneity testing, meta-regression and mixed-effects analysis. The most useful of these are the “meta”, “rmeta” and “metafor” packages.
Using R for meta-analysis is slightly more involved than other solutions such as the Cochrane RevMan software, and involves the use of the command-line. However, the number of functions that the user needs to be familiar with is small, and R gives the advantages of much greater flexibility, numerous additional functions and greatly improved graphics suitable for presentations and publication in journals.
Installing the software
Today’s post is all about getting set-up and installing the necessary software and packages. R itself is a command-line programming language that can be installed alone on any platform. Binaries are available from http://cran.r-project.org/. For those of us used to graphical user interfaces (e.g. Windows, OSX) this can be a daunting prospect and for this reason a number of graphical user interfaces have been written that make basic functions such as opening and closing files, exporting graphics etc. much easier for the novice user.
Examples of GUIs for Windows and OSX include R Commander, RKWard, and RStudio. My preference is for RStudio, as it is available for Windows, OSX and Unix platforms and is very easy to install and use.
To install R:
- Download the correct base package for your operating system. These can be found at http://www.stats.bris.ac.uk/R/
- Once the download has completed, run the installer.
- Follow the instructions, leaving all settings as default.
To install RStudio:
Now you are ready to install the RStudio user interface. Visit the RStudio download page and select the Windows or OSX version of RStudio from the list to download.
Once the download is complete, run the installer and follow the instructions.
Running for the first time
In either the Windows program menu or the OSX Application Launchpad, you should now find an icon for RStudio:
Double-click to launch the software. You should now see the default home-screen:
The default panels are as follows:
Left panel: The R console. This is where you type commands and view responses from R.
Top right panel: The environment and history tabs. These show you current datasets and set variables, as well as your command history (commands you have run previously). Buttons here also allow you to import and save data.
Bottom right panel: Here is where you can access files, display plots/graphs, load packages and view help files.
Installing the meta-analysis packages
By default, R comes with just the basic statistical functions loaded. Specialist functions such as those for meta-analysis are available to be downloaded as add-on packages which can be installed and run as needed.
Installing from the RStudio interface
To install packages, select the “Packages” tab on the lower right-hand pane:
From the menu bar, select “Install”:
Enter “metafor” into the box, and click “Install”. You will see some code appear in the console pane as the package is downloaded and installed.
Repeat this for the “rmeta” and “meta” packages.
To load the packages ready for use, simply select each package from the list using the checkbox:
Again, you will see code pass in the console pane as the packages are loaded.
Installing from the command-line
To install the packages, we use the “install.packages()” command. Type the following into the command-line:
install.packages("meta")
The meta package will download and install.
Repeat this for the rmeta and metafor packages:
install.packages("rmeta") install.packages("metafor")
Once the packages are installed, they must be loaded for use in the current session. For this we use the “library()” command. This must be repeated each time you load RKWard, unless you are using a saved workspace in which they are already loaded. To load, type the following:
library ("meta") library ("rmeta") library ("metafor")
All of the necessary software is now loaded and you are ready to start your meta-analysis.
In the next part of this series, I will cover the basics of meta-analysis of binary data.