{"id":301,"date":"2014-08-05T16:01:05","date_gmt":"2014-08-05T16:01:05","guid":{"rendered":"https:\/\/www.transplantevidence.com\/blog\/?p=301"},"modified":"2014-08-05T16:01:05","modified_gmt":"2014-08-05T16:01:05","slug":"meta-analysis-in-r-part-2-binary-data","status":"publish","type":"post","link":"https:\/\/www.transplantevidence.com\/news\/2014\/08\/05\/meta-analysis-in-r-part-2-binary-data\/","title":{"rendered":"Meta-analysis in R: Part 2 &#8211; Binary data"},"content":{"rendered":"<p>In <a title=\"Meta-analysis in R: Part 1 \u2013 Installing the software\" href=\"https:\/\/www.transplantevidence.com\/blog\/2014\/07\/meta-analysis-in-r-part-1-installing-the-software\/\">part 1<\/a>, I discussed how to get set up for meta-analysis in R, by installing the necessary software and libraries.<\/p>\n<p>In this post, I will take the reader through the steps for performing meta-analysis of binary data in R.<\/p>\n<p><!--more--><\/p>\n<p><strong>Required data format<\/strong><\/p>\n<p>Binary outcomes are those in which study participants either experience an outcome, or do not. Examples are acute rejection and delayed graft function. The data required for meta-analysis is as follows:<\/p>\n<p>[table th=0]<br \/>\n<strong>\u00a0n.s<\/strong>, The total number of participants in the study group<br \/>\n<strong>\u00a0n.c<\/strong>, The total number of participants in the control group<br \/>\n<strong>\u00a0event.s<\/strong>, The number of participants experiencing the outcome in the study group<br \/>\n<strong>\u00a0event.c<\/strong>, The number of participants experiencing the outcome in the control group<br \/>\n[\/table]<\/p>\n<p>In order to label the studies, it is recommended that a study name and year of publication are used.<\/p>\n<p>An example spreadsheet looking at the incidence of hypercholesterolaemia in patients withdrawn from or avoiding steroids is shown below:<\/p>\n<p>[table]<br \/>\nname,year,event.s,n.s,event.c,n.c<br \/>\nVincenti,2008,101,227,57,109<br \/>\nLaftavi,2005,4,14,11,16<br \/>\nPonticelli,1997,86,114,102,115<br \/>\nMontagnino,2005,43,65,48,68<br \/>\nVitko,2005,18,143,25,134<br \/>\nWoodle,2008,97,156,112,152<br \/>\nBurke,2001,6,20,13,20<br \/>\nPark,1994,8,22,35,46<br \/>\nCristinelli,1986,7,35,13,31<br \/>\nVanrenterghem,2005,39,235,62,237<br \/>\nSmak Gregoor,2002,14,76,11,73<br \/>\nSola,2002,5,46,6,46<br \/>\nHollander,1997,9,42,23,41<br \/>\n[\/table]<\/p>\n<p><strong>Loading the dataset<\/strong><\/p>\n<p>In R, a spreadsheet of data is termed a \u201cdataset\u201d. Datasets can either be entered manually, or imported from an excel spreadsheet. The latter can be performed from the command-line, or using the RStudio GUI.<\/p>\n<p><em>Loading data using the GUI<\/em><\/p>\n<p>This is the easiest method to load your dataset into R. From the \u201cEnvironment\u201d tab in the top right pane, click the \u201cImport Dataset\u201d button, and select \u201cFrom Text File&#8230;\u201d:<\/p>\n<p><a href=\"https:\/\/www.transplantevidence.com\/blog\/wp-content\/uploads\/2014\/08\/load_data.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-303\" src=\"https:\/\/www.transplantevidence.com\/blog\/wp-content\/uploads\/2014\/08\/load_data-300x118.jpg\" alt=\"Load data\" width=\"300\" height=\"118\" srcset=\"https:\/\/www.transplantevidence.com\/news\/wp-content\/uploads\/2014\/08\/load_data-300x118.jpg 300w, https:\/\/www.transplantevidence.com\/news\/wp-content\/uploads\/2014\/08\/load_data.jpg 314w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Select your .csv file that you created in excel, and click \u201cOpen\u201d.<\/p>\n<p>You will then be given the option to describe your data format. Use the settings shown below:<\/p>\n<p><a href=\"https:\/\/www.transplantevidence.com\/blog\/wp-content\/uploads\/2014\/08\/import_data.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-304\" src=\"https:\/\/www.transplantevidence.com\/blog\/wp-content\/uploads\/2014\/08\/import_data-300x225.jpg\" alt=\"Import data\" width=\"300\" height=\"225\" \/><\/a><\/p>\n<p>The data frame on the bottom left previews what you data will look like once imported. Click \u201cImport\u201d, and a new panel will open at the top left of the screen showing your data frame. The dataset will also appear in your environment in the top right pane:<\/p>\n<p><a href=\"https:\/\/www.transplantevidence.com\/blog\/wp-content\/uploads\/2014\/08\/data_imported.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-305\" src=\"https:\/\/www.transplantevidence.com\/blog\/wp-content\/uploads\/2014\/08\/data_imported-300x208.jpg\" alt=\"Data imported\" width=\"300\" height=\"208\" srcset=\"https:\/\/www.transplantevidence.com\/news\/wp-content\/uploads\/2014\/08\/data_imported-300x208.jpg 300w, https:\/\/www.transplantevidence.com\/news\/wp-content\/uploads\/2014\/08\/data_imported-768x533.jpg 768w, https:\/\/www.transplantevidence.com\/news\/wp-content\/uploads\/2014\/08\/data_imported-1024x711.jpg 1024w, https:\/\/www.transplantevidence.com\/news\/wp-content\/uploads\/2014\/08\/data_imported.jpg 1185w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><em>Loading data from the command-line<\/em><\/p>\n<p>If the above step does not work, or you are using a different GUI\/platform, you can load your file from the command-line. First of all, R needs to know where to find your files. From the \u201cSession\u201d menu, select \u201cSet Working Directory &gt; Choose Directory&#8230;\u201d. Navigate to the directory containing your data, and click \u201cSubmit\u201d. Alternatively, you can type in the console:<\/p>\n<pre>setwd(\"C:\/Documents and Settings\/User\/My Documents\")<\/pre>\n<p>Replace the directory in the quotes with your working directory.<\/p>\n<p>To see the files in the current directory, type:<\/p>\n<pre>dir()<\/pre>\n<p>To load a CSV file (as prepared above), type the following:<\/p>\n<pre>read.table(\"cholesterol.csv\", sep = \",\", header=TRUE)<\/pre>\n<p>This tells R the file name and extension, that the data is separated by commas, and that the first row of data is the column headings. It should output something like this:<\/p>\n<p><a href=\"https:\/\/www.transplantevidence.com\/blog\/wp-content\/uploads\/2014\/08\/data.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-306\" src=\"https:\/\/www.transplantevidence.com\/blog\/wp-content\/uploads\/2014\/08\/data-300x221.jpg\" alt=\"data\" width=\"300\" height=\"221\" srcset=\"https:\/\/www.transplantevidence.com\/news\/wp-content\/uploads\/2014\/08\/data-300x221.jpg 300w, https:\/\/www.transplantevidence.com\/news\/wp-content\/uploads\/2014\/08\/data.jpg 694w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>In order to be able to use this data, it must be stored as a variable. Run the following command:<\/p>\n<pre>cholesterol.data &lt;- read.table(\"cholesterol.csv\", sep = \",\", header=TRUE)<\/pre>\n<p>This stores the dataset above as a variable called \u201c<span style=\"font-family: 'Nimbus Mono L', monospace;\">cholesterol.data<\/span>\u201d. The dataset can be viewed by typing it&#8217;s name:<\/p>\n<pre>cholesterol.data<\/pre>\n<p>The output should be the same as the table above. To access an individual column from the data, use the $ operator. For example:<\/p>\n<pre>cholesterol.data$name<\/pre>\n<p>Should output:<\/p>\n<pre>[1] Vincenti      Laftavi       Ponticelli    Montagnino    Vitko        \n[6] Woodle        Burke         Park          Cristinelli   Vanrenterghem\n[11] Smak Gregoor  Sola          Hollander    <\/pre>\n<p><strong>Performing the meta-analysis<\/strong><\/p>\n<p>There are two steps to performing the meta-analysis. Firstly, an effect size must be calculated for each study. In the case of discrete data this can be a Relative Risk (RR), Odds Ratio (OR) or Risk Difference (RD). Then these effect sizes much be combined in a meta-analytical model to create a summary effect size, along with confidence intervals and measures of heterogeneity.<\/p>\n<p>Fortunately, the <span style=\"font-family: 'Nimbus Mono L', monospace;\">metafor <\/span> package contains functions that can perform these steps individually, or more conveniently combine these steps automatically giving all of the required data. The function for meta-analysis is the\u00a0<span style=\"font-family: 'Nimbus Mono L', monospace;\">rma.uni()<\/span> function. In the case of binary meta-analysis, it takes data in the form of a 2&#215;2 table:<\/p>\n<p>[table]<br \/>\nGroup, Outcome 1, Outcome 2, Total<br \/>\nStudy Group, ai, bi, n1i<br \/>\nControl Group, ci, di, n2i<br \/>\n[\/table]<\/p>\n<p>So looking at our cholesterol data from section 3.2, we have values for <span style=\"font-family: 'Nimbus Mono L', monospace;\">ai, ci, n1i<\/span> and <span style=\"font-family: 'Nimbus Mono L', monospace;\">n2i<\/span>. Try the following:<\/p>\n<pre>rma.uni(ai=event.s, n1i=n.s, ci=event.c, n2i= n.c, data=cholesterol.data, slab=paste(name, year), measure=\"RR\")<\/pre>\n<p>In brackets, we are telling the function the names of the columns containing the data (<span style=\"font-family: 'Nimbus Mono L', monospace;\">event.s, n.s, event.c, n.c<\/span>) and the name of the dataset (<span style=\"font-family: 'Nimbus Mono L', monospace;\">data=cholesterol.data<\/span>). The argument (<span style=\"font-family: 'Nimbus Mono L', monospace;\">slab=paste(name, year)<\/span>) provides a label for each study by combining the name and year columns, separated by a space. The final argument tells the function that we wish to use the relative risk. The command should produce the following output:<\/p>\n<pre>Random-Effects Model (k = 13; tau^2 estimator: REML)\n\ntau^2 (estimate of total amount of heterogeneity): 0.0225 (SE = 0.0225)\ntau (sqrt of the estimate of total heterogeneity): 0.1499\nI^2 (% of total variability due to heterogeneity): 47.93%\nH^2 (total variability \/ within-study variance):   1.92\n\nTest for Heterogeneity: \nQ(df = 12) = 20.6639, p-val = 0.0555\n\nModel Results:\n\nestimate       se     zval     pval    ci.lb    ci.ub          \n -0.2854   0.0712  -4.0083   <.0001  -0.4249  -0.1458      *** \n\n---\nSignif. codes:  0 \u2018***\u2019 0.001 \u2018**\u2019 0.01 \u2018*\u2019 0.05 \u2018.\u2019 0.1 \u2018 \u2019 1<\/pre>\n<p>The default here is a random-effects model.  Below this, there is an assessment of heterogeneity including the I^2 value and Chi-squared p-value.  Finally, the results of the model are given, with the log relative risk, SE, p-value and borders for the 95% confidence interval.  The log values can be converted to the true relative risk using the <span style=\"font-family: 'Nimbus Mono L', monospace;\">exp()<\/span> function.  For example:<\/p>\n<pre>exp(-0.2854)\n[1] 0.7517135<\/pre>\n<p>This tells us that the relative risk from the random-effects model is 0.75. The same can be done for the borders of the confidence interval (giving 0.65-0.86).<\/p>\n<p><strong>Other <span style=\"font-family: 'Nimbus Mono L', monospace;\">rma.uni<\/span> options<\/strong><\/p>\n<p>By default, the <span style=\"font-family: 'Nimbus Mono L', monospace;\">rma.uni<\/span> function uses the restricted maximum-likelihood estimator (REML) random-effects model.  By adding more options to our command, we can modify these defaults.  Some useful options are:<\/p>\n<p>[table th=0]<br \/>\n<span style=\"font-family: 'Nimbus Mono L', monospace;\">method<\/span>,\"The meta-analysis model used.  This can be 'REML', 'DL' (DeSimonian-Laird),  or \t\t\t'FE' (fixed effects).  Other models are available.\"<br \/>\n<span style=\"font-family: 'Nimbus Mono L', monospace;\">measure<\/span>, \"The summary method used.  This can be 'RR', 'OR' or 'RD' for binary data, 'MD' \t\t\tor 'SMD' for continuous data.\"<br \/>\n<span style=\"font-family: 'Nimbus Mono L', monospace;\">subset<\/span>,\t\"A subset of studies from the dataset to meta-analyse.  This will be described in a later post.\"<br \/>\n<span style=\"font-family: 'Nimbus Mono L', monospace;\">mods<\/span>, \"Moderator variables for a mixed-effects analysis.  This will be described in a later post.\"<br \/>\n[\/table]<\/p>\n<p>To give another example, try the following command:<\/p>\n<pre>rma.uni(ai=event.s, n1i=n.s, ci=event.c, n2i= n.c, data=cholesterol.data, slab=paste(name, year), measure=\"OR\", method=\"FE\")<\/pre>\n<p>This gives:<\/p>\n<pre>Fixed-Effects Model (k = 13)\n\nTest for Heterogeneity: \nQ(df = 12) = 19.6044, p-val = 0.0750\n\nModel Results:\n\nestimate       se     zval     pval    ci.lb    ci.ub          \n -0.5898   0.1005  -5.8685   <.0001  -0.7868  -0.3928      *** \n\n---\nSignif. codes:  0 \u2018***\u2019 0.001 \u2018**\u2019 0.01 \u2018*\u2019 0.05 \u2018.\u2019 0.1 \u2018 \u2019 1 <\/pre>\n<p>Now a fixed-effects model is used, with results reported as the log odds-ratio.  <span style=\"font-family: 'Nimbus Mono L', monospace;\">Exp(-0.5898)<\/span> tells us that the combined odds ratio from the fixed-effects model is 0.55.<\/p>\n<p>In the next post, I will deal with the meta-analysis of continuous data.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In part 1, I discussed how to get set up for meta-analysis in R, by installing the necessary software and libraries. In this post, I will take the reader through the steps for performing meta-analysis of binary data in R.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[169],"tags":[249,250,273,292],"class_list":["post-301","post","type-post","status-publish","format-standard","hentry","category-meta-analysis-in-r","tag-meta-analysis","tag-methodology","tag-r","tag-systematic-review"],"_links":{"self":[{"href":"https:\/\/www.transplantevidence.com\/news\/wp-json\/wp\/v2\/posts\/301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.transplantevidence.com\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.transplantevidence.com\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.transplantevidence.com\/news\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.transplantevidence.com\/news\/wp-json\/wp\/v2\/comments?post=301"}],"version-history":[{"count":0,"href":"https:\/\/www.transplantevidence.com\/news\/wp-json\/wp\/v2\/posts\/301\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.transplantevidence.com\/news\/wp-json\/wp\/v2\/media?parent=301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.transplantevidence.com\/news\/wp-json\/wp\/v2\/categories?post=301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.transplantevidence.com\/news\/wp-json\/wp\/v2\/tags?post=301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}