forked from MathiasHarrer/Doing-Meta-Analysis-in-R
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Doing_Meta_Analysis_in_R.tex
6535 lines (5586 loc) · 273 KB
/
Doing_Meta_Analysis_in_R.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[]{book}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\else % if luatex or xelatex
\ifxetex
\usepackage{mathspec}
\else
\usepackage{fontspec}
\fi
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\fi
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage[margin=1in]{geometry}
\usepackage{hyperref}
\hypersetup{unicode=true,
pdftitle={Doing Meta Analysis in R},
pdfauthor={Mathias Harrer, B.Sc. \& Dr.~habil. David Ebert},
pdfborder={0 0 0},
breaklinks=true}
\urlstyle{same} % don't use monospace font for urls
\usepackage{natbib}
\bibliographystyle{apalike}
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\usepackage{longtable,booktabs}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}
% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
%%% Use protect on footnotes to avoid problems with footnotes in titles
\let\rmarkdownfootnote\footnote%
\def\footnote{\protect\rmarkdownfootnote}
%%% Change title format to be more compact
\usepackage{titling}
% Create subtitle command for use in maketitle
\newcommand{\subtitle}[1]{
\posttitle{
\begin{center}\large#1\end{center}
}
}
\setlength{\droptitle}{-2em}
\title{Doing Meta Analysis in R}
\pretitle{\vspace{\droptitle}\centering\huge}
\posttitle{\par}
\author{Mathias Harrer, B.Sc. \& Dr.~habil. David Ebert}
\preauthor{\centering\large\emph}
\postauthor{\par}
\predate{\centering\large\emph}
\postdate{\par}
\date{Friedrich-Alexander-University Erlangen-Nuremberg}
\usepackage{booktabs}
\usepackage{amsthm}
\makeatletter
\def\thm@space@setup{%
\thm@preskip=8pt plus 2pt minus 4pt
\thm@postskip=\thm@preskip
}
\makeatother
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage[table]{xcolor}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{colortbl}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage{makecell}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{lemma}{Lemma}[chapter]
\theoremstyle{definition}
\newtheorem{definition}{Definition}[chapter]
\newtheorem{corollary}{Corollary}[chapter]
\newtheorem{proposition}{Proposition}[chapter]
\theoremstyle{definition}
\newtheorem{example}{Example}[chapter]
\theoremstyle{definition}
\newtheorem{exercise}{Exercise}[chapter]
\theoremstyle{remark}
\newtheorem*{remark}{Remark}
\newtheorem*{solution}{Solution}
\begin{document}
\maketitle
{
\setcounter{tocdepth}{1}
\tableofcontents
}
\chapter{About this Guide}\label{about-this-guide}
\begin{figure}
\centering
\includegraphics{coverbild.jpg}
\caption{}
\end{figure}
\begin{rmdinfo}
This guide shows you how to conduct Meta-Analyses in R from scratch. The
focus of this guide is primarily on clinical outcome research in
psychology. It is designed for staff and collaborators of the
\href{https://www.protectlab.org}{\textbf{PROTECT Lab}}, which is headed
by \textbf{Dr.~David D. Ebert}.
\end{rmdinfo}
\includegraphics{Doing_Meta_Analysis_in_R_files/figure-latex/unnamed-chunk-2-1.pdf}
\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
\textbf{The guide will show you how to:}
\begin{itemize}
\tightlist
\item
Get \textbf{R} and \textbf{RStudio} set for your Meta-Analysis
\item
Get your data into R
\item
\textbf{Prepare your data} for the meta-analysis
\item
Perform \textbf{fixed-effect} and \textbf{random-effects}
meta-analysis using the \texttt{meta} and \texttt{metafor}packages
\item
Analyse the \textbf{heterogeneity} of your results
\item
Tackle heterogeneity using \textbf{subgroup analyses} and
\textbf{meta-regression}
\item
Check if \textbf{selective outcome reporting (publication bias)} is a
present in your data
\item
Control for selective outcome reporting and publication bias
\item
Analyse the \textbf{risk of bias} in your data
\item
Do advanced types of meta-analyses, such as
\begin{itemize}
\tightlist
\item
\textbf{network analyses} or
\item
meta-analyses with \textbf{more than one outcome}
\end{itemize}
\end{itemize}
\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
\textbf{What this guide will not cover}
Although this guide will provide some information on the statistics
behind meta-analysis, it will not give you an \textbf{in-depth
introduction} into how meta-analyses are calculated statistically.
It is also beyond the scope of this guide to advise in detail which
meta-analytical strategy is suited best in which contexts, and on how
the search, study inclusion and reporting of meta-analyses should be
conducted. The \href{http://handbook-5-1.cochrane.org/}{\emph{Cochrane
Handbook for Systematic Reviews of Interventions}}, however, should be a
great source to find more information on these topics.
\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
\textbf{Generally, there a two other sources to recommended when
conducting Meta-Analyses:}
\begin{itemize}
\tightlist
\item
If you're looking for a easily digestable, hands-on introduction on
how Meta-Analyses are conducted, we can recommend \textbf{Pim
Cuijpers' online courses on Meta-Analysis}. The courses are freely
available on YouTube. To have a look, click
\href{https://www.youtube.com/watch?v=pP7_VBrG_TY\&list=PL-h5cI5Bkvt0J-O0kq_9J9_aksWFPgR7s}{here}.
\item
If you're interested in more details on how to conduct Meta-Analyses
in R, you can either have a look at Wolfgang Viechtbauer's page for
the \texttt{metafor} package
(\href{http://metafor-project.org}{Link}). Or you can consult a book
on the \texttt{meta} package which was recently published
\citep{schwarzer2015meta}.
\end{itemize}
\begin{rmdinfo}
\textbf{How to get the R code for this guide}
\begin{figure}
\centering
\includegraphics{githublogo.png}
\caption{}
\end{figure}
All code behind this book is available online on \textbf{GitHub}. We
have created a website containing a \textbf{download link} for all
codes, and a \textbf{quick guide} on how to get the code running on your
computer. The site can be found
\href{https://mathiasharrer.github.io/Doing-Meta-Analysis-in-R/}{here}.
\end{rmdinfo}
\textbf{How to cite this guide}
Harrer, M. \& Ebert, D. D. (2018). Doing Meta-Analysis in R: A practical
Guide. \emph{PROTECT Lab Friedrich-Alexander University
Erlangen-Nuremberg}.
\url{https://bookdown.org/MathiasHarrer/Doing_Meta_Analysis_in_R/}
\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
\textbf{To get started, proceed to the next chapter!}
\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
\chapter{RStudio \& Basics}\label{rstudio-basics}
\begin{figure}
\centering
\includegraphics{chap2.jpg}
\caption{}
\end{figure}
\begin{rmdinfo}
Before we start with our meta-analysis, we have to download and prepare
a \textbf{computer program} which allows us to use \emph{R} for
programming.
Probably the best option for this at the moment is \textbf{RStudio}.
This program gives us a user interface which makes it easier to overlook
our data, packages and output. The best part is that RStudio is
\textbf{completely free} and can be downloaded anytime.
In this Chapter, we'll focus on how you can install RStudio on your
computer. We'll also provide some general information on R, and how you
can get help if you get error messages.
If you already have RStudio installed on your computer, and if you're an
experienced R user already, all of this might be nothing new for you.
You may \textbf{skip} this chapter then.
Especially if you have \textbf{never used R before, we would like to
consider this Chapter essential}, as it gives you some input on how R
works, and how we can use it for our data analyses.
\end{rmdinfo}
\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
\hypertarget{RStudio}{\section{Getting RStudio to run on your
computer}\label{RStudio}}
\includegraphics{Doing_Meta_Analysis_in_R_files/figure-latex/unnamed-chunk-7-1.pdf}
As a prerequisite for this guide, you need to have \textbf{RStudio} and
a few essential \textbf{R packages} installed.
\textbf{You have to follow these steps to get your RStudio set.}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
Download RStudio on the \textbf{RStudio} Website
(\href{https://www.rstudio.com/products/rstudio/download/}{Link}).
It's free!
\item
If you do not have \textbf{R} installed yet, you will have to install
the latest R Version before you can use RStudio. You can get the
latest R version
\href{https://cran.r-project.org/bin/windows/base/}{here}.
\item
Once RStudio is running, open the \textbf{Console} on the bottom left
corner of your screen.
\item
We will now install a few packages using R Code. Here's an overview of
the packages, and why we need them:
\end{enumerate}
\begin{verbatim}
## Warning: package 'kableExtra' was built under R version 3.4.4
\end{verbatim}
\begin{tabular}{l|l}
\hline
Package & Description\\
\hline
tidyverse & This is a large package containing various functions to tidy up your data\\
\hline
meta & This package is a so-called wrapper for many meta-analytic functions and makes it easy to code different meta-analyses\\
\hline
metafor & This package is used by the meta package for many applications, so we need to have it installed\\
\hline
\end{tabular}
5. To install these packages, we use the \texttt{install.packages()}
function in R. One package after another, our code should look like
this:
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{install.packages}\NormalTok{(}\StringTok{"tidyverse"}\NormalTok{)}
\KeywordTok{install.packages}\NormalTok{(}\StringTok{"meta"}\NormalTok{)}
\KeywordTok{install.packages}\NormalTok{(}\StringTok{"metafor"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{rmdachtung}
Don't forget to put the packages in \texttt{""}.
Otherwise, you will get an error message.
\end{rmdachtung}
\textbf{You are now set and ready to proceed. Below, you can find some
basic information on RStudio and troubleshooting}
\subsection{Running R Code}\label{running-r-code}
Order to get the most out of this guide, it's helpful (but not
essential) if you have some programming experience already. If you've
never programmed before, you might find \textbf{\emph{Hands-On
Programming with R}} \citep{grolemund2014hands} to be a useful primer.
There are three things you need to run the code: \textbf{R},
\textbf{RStudio}, and collection of \textbf{R packages}. Packages are
the fundamental units of reproducible R code. They include reusable
functions, the documentation that describes how to use them, and sample
data.
Gladly, once you've reached this point successfully, these three things
are set already. Nevertheless, we will have to install and load a few
new packages at some place in this guide, for which you can use the
\texttt{install.packages()} the same way as you did before.
Throughout the guide, a consistent set of conventions is used to refer
to code:
\begin{itemize}
\tightlist
\item
Functions are in a code font and followed by parentheses, like
\texttt{sum()} or \texttt{mean()}.
\item
Other R objects (like data or function arguments) are in a code font,
without parentheses, like \texttt{seTE} or \texttt{method.tau}.
\item
Sometimes, we'll use the package name followed by two colons, like
\texttt{meta::metagen()}. This is also valid R code. This is used so
as to not confuse the functions of different packages with the same
name.
\end{itemize}
\subsection{Getting Help}\label{getting-help}
As you start to apply the techniques described in this guide to your
data you will soon find questions that the guide does not answer. This
section describes a few tips on how to get help.
\begin{itemize}
\tightlist
\item
If you get stuck, start with \textbf{Google}. Typically, adding ``R''
to a search is enough to restrict it to relevant results: if the
search isn't useful, it often means that there aren't any R-specific
results available. Google is particularly useful for error messages.
If you get an error message and you have no idea what it means, try
googling it. Chances are that someone else has been confused by it in
the past, and there will be help somewhere on the web. (If the error
message isn't in English, run \texttt{Sys.setenv(LANGUAGE\ =\ "en")}
and re-run the code; you're more likely to find help for English error
messages.)
\item
If Google doesn't help, try
\href{https://stackoverflow.com}{stackoverflow}. Start by spending a
little time searching for an existing answer; including {[}R{]}
restricts your search to questions and answers that use R.
\item
Lastly, if you stumble upon an error (or typos!) in this guide's text
or R syntax, feel free to contact \textbf{Mathias Harrer} at
\textbf{\href{mailto:[email protected]}{\nolinkurl{[email protected]}}}.
\end{itemize}
\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
\chapter{Getting your data into R}\label{getting-your-data-into-r}
\begin{figure}
\centering
\includegraphics{chappool.jpg}
\caption{}
\end{figure}
\begin{rmdinfo}
This chapter will tell you about how you can \textbf{import} your effect
size data in RStudio. We will also show you a few commands which make it
easier to \textbf{manipulate data} directly in R.
Data preparation can be tedious and exhausting at times, but it is the
backbone of all later steps when doing meta-analyses in R. We therefore
have to pay \textbf{close attention} to preparing the data correctly
before we can proceed.
\end{rmdinfo}
\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
\section{Data preparation in Excel}\label{data-preparation-in-excel}
\hypertarget{excel_preparation}{\subsection{Setting the columns of the
excel spreadsheet}\label{excel_preparation}}
To conduct Meta-Analyses in R, you need to have your study data
prepared. For a standard meta-analysis, the following information is
needed for every study.
\begin{itemize}
\tightlist
\item
The \textbf{names} of the individual studies, so that they can be
easily identified later on. Usually, the first author and publication
year of a study is used for this (e.g. ``Ebert et al., 2018'')
\item
The \textbf{Mean} of both the Intervention and the Control group at
the same assessment point
\item
The \textbf{Standard Deviation} of both the Intervention and the
Control group at the same assessment point
\item
The \textbf{number of participants (N)} in each group of the trial
\item
If you want to have a look at differences between various study
subgroups later on, you also need a \textbf{subgroup code} for each
study which signifies to which subgroup it belongs. For example, if a
study was conducted in children, you might give it the subgroup code
``children''.
\end{itemize}
As per usual, such data is stored in \textbf{EXCEL spreadsheets}. We
recommend to store your data there, because this makes it very easy to
import data into RStudio.
However, it is very important how you \textbf{name the columns of your
spreadsheet}. If you name the columns of your sheet adequately in EXCEL
already, you can save a lot of time because your data doesn't have to be
transformed in RStudio later on.
\textbf{Here is how you should name the data columns in your EXCEL
spreadheet containing your Meta-Analysis data}
\begin{tabular}{l|l}
\hline
Column & Description\\
\hline
Author & This signifies the column for the study label (i.e., the first author)\\
\hline
Me & The Mean of the experimental/intervention group\\
\hline
Se & The Standard Deviation of the experimental/intervention group\\
\hline
Mc & The Mean of the control group\\
\hline
Sc & The Standard Deviation of the control group\\
\hline
Ne & The number of participants in the experimental/intervention group\\
\hline
Nc & The number of participats in the control group\\
\hline
Subgroup & This is the label for one of your Subgroup codes. It's not that important how you name it, so you can give it a more informative name (e.g. population). In this column, each study should then be given an subgroup code, which should be exactly the same for each subgroup, including upper/lowercase letters. Of course, you can also include more than one subgroup column with different subgroup codings, but the column name has to be unique\\
\hline
\end{tabular}
Note that it \textbf{doesn't matter how these columns are ordered in
your EXCEL spreadsheet}. They just have to be labeled correctly.
There's also no need to \textbf{format} the columns in any way. If you
type the column name in the first line of you spreadsheet, R will
automatically detect it as a column name.
\begin{rmdachtung}
It's also important to know that the import \textbf{will distort letters
like ä,ü,ö,á,é,ê, etc}. So be sure to transform them to ``normal''
letters before you proceed.
\end{rmdachtung}
\subsection{Setting the columns of your sheet if you have calculated the
effect sizes of each study
already}\label{setting-the-columns-of-your-sheet-if-you-have-calculated-the-effect-sizes-of-each-study-already}
If you have \textbf{already calculated the effect sizes for each study
on your own}, for example using \emph{Comprehensive Meta-Analysis} or
\emph{RevMan}, there's another way to prepare your data which makes
things a little easier. In this case, you only have to include the
following columns:
\begin{tabular}{l|l}
\hline
Column & Description\\
\hline
Author & This signifies the column for the study label (i.e., the first author)\\
\hline
TE & The calculated effect size of the study (either Cohen's d or Hedges' g, or some other form of effect size\\
\hline
seTE & The Standard Error (SE) of the calculated effect\\
\hline
Subgroup & This is the label for one of your Subgroup codes. It's not that important how you name it, so you can give it a more informative name (e.g. population). In this column, each study should then be given an subgroup code, which should be exactly the same for each subgroup, including upper/lowercase letters. Of course, you can also include more than one subgroup column with different subgroup codings, but the column name has to be unique\\
\hline
\end{tabular}
\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
\hypertarget{import_excel}{\section{Importing the Spreadsheet into
Rstudio}\label{import_excel}}
To get our data into R, we need to \textbf{save our data in a format and
at a place where RStudio can open it}.
\subsection{Saving the data in the right
format}\label{saving-the-data-in-the-right-format}
Generelly, finding the right format to import EXCEL can be tricky.
\begin{itemize}
\tightlist
\item
If you're using a PC or Mac, it is advised to save your EXCEL sheet as
a \textbf{comma-separated-values (.csv) file}. This can be done by
clicking on ``save as'' and then choosing (.csv) as the output format
in EXCEL.
\item
With some PCs, RStudios might not be able to open such files, or the
files might be distorted. In this case, you can also try to save the
sheet as a normal \textbf{.xslx} EXCEL-file and try if this works.
\end{itemize}
\subsection{Saving the data in your working
directory}\label{saving-the-data-in-your-working-directory}
To function properly, you have to set a working directory for RStudio
first. The working directory is a \textbf{folder on your computer from
which RStudio can use data, and in which output it saved}.
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
Therefore, create a folder on your computer and give it a meaningful
name (e.g. ``My Meta-Analysis'').
\item
Save your spreadsheet in the folder
\item
Set the folder as your working directory. This can be done in RStudio
on the \textbf{bottom-right corner of your screen}. Under the tile
\textbf{``Files''}, search for the folder on your computer, and open
it.
\item
Once you've opened your folder, the file you just saved there should
be in there.
\item
Now that you've opened the folder, click on the \textbf{little gear
wheel on top of the pane}
\end{enumerate}
\includegraphics{Doing_Meta_Analysis_in_R_files/figure-latex/unnamed-chunk-15-1.pdf}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{5}
\tightlist
\item
Then click on ``\textbf{Set as working directory}''
\end{enumerate}
\textbf{Your file, and the working directory, are now where they should
be!}
\subsection{Loading the data}\label{loading-the-data}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
To import the data, simply \textbf{click on the file} in the
bottom-right pane. Then click on \textbf{import dataset\ldots{}}
\item
An \textbf{import assistant} should now pop up, which is also loading
a preview of your data. This can be time-consuming sometimes, so you
can skip this step if you want to, and klick straight on
\textbf{``import''}
\end{enumerate}
\includegraphics{Doing_Meta_Analysis_in_R_files/figure-latex/unnamed-chunk-16-1.pdf}
As you can see, the on the top-right pane \textbf{Environment}, your
file is now listed as a data set in your RStudio environment.
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{2}
\tightlist
\item
I also want to give my data a shorter name (``madata''). To rename it,
i use the following code:
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{madata<-Meta_Analysis_Data}
\end{Highlighting}
\end{Shaded}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{3}
\tightlist
\item
Now, let's have a look at the \textbf{structure of my data} using the
\texttt{str()} function
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{str}\NormalTok{(madata)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Classes 'tbl_df', 'tbl' and 'data.frame': 18 obs. of 17 variables:
## $ Author : chr "Call et al." "Cavanagh et al." "DanitzOrsillo" "de Vibe et al." ...
## $ TE : num 0.709 0.355 1.791 0.182 0.422 ...
## $ seTE : num 0.261 0.196 0.346 0.118 0.145 ...
## $ RoB : chr "low" "low" "high" "low" ...
## $ Control : chr "WLC" "WLC" "WLC" "no intervention" ...
## $ intervention duration: chr "short" "short" "short" "short" ...
## $ intervention type : chr "mindfulness" "mindfulness" "ACT" "mindfulness" ...
## $ population : chr "undergraduate students" "students" "undergraduate students" "undergraduate students" ...
## $ type of students : chr "psychology" "general" "general" "general" ...
## $ prevention type : chr "selective" "universal" "universal" "universal" ...
## $ gender : chr "female" "mixed" "mixed" "mixed" ...
## $ mode of delivery : chr "group" "online" "group" "group" ...
## $ ROB streng : chr "high" "low" "high" "low" ...
## $ ROB superstreng : chr "high" "high" "high" "low" ...
## $ compensation : chr "none" "none" "voucher/money" "voucher/money" ...
## $ instruments : chr "DASS" "PSS" "DASS" "other" ...
## $ guidance : chr "f2f" "self-guided" "f2f" "f2f" ...
\end{verbatim}
Although this output looks kind of messy, it's already very informative.
It shows the structure of my data. In this case, i used data for which
the effect sizes were already calculated. This is why the variables
\textbf{TE} and \textbf{seTE} appear. I also see plenty of other
variables, which correspond to the subgroups which were coded for this
dataset.
\textbf{Here's a (shortened) table created for my data}
\begin{tabular}{l|r|r|l|l|l|l}
\hline
Author & TE & seTE & RoB & Control & intervention duration & intervention type\\
\hline
Call et al. & 0.7091362 & 0.2608202 & low & WLC & short & mindfulness\\
\hline
Cavanagh et al. & 0.3548641 & 0.1963624 & low & WLC & short & mindfulness\\
\hline
DanitzOrsillo & 1.7911700 & 0.3455692 & high & WLC & short & ACT\\
\hline
de Vibe et al. & 0.1824552 & 0.1177874 & low & no intervention & short & mindfulness\\
\hline
Frazier et al. & 0.4218509 & 0.1448128 & low & information only & short & PCI\\
\hline
Frogeli et al. & 0.6300000 & 0.1960000 & low & no intervention & short & ACT\\
\hline
Gallego et al. & 0.7248838 & 0.2246641 & high & no intervention & long & mindfulness\\
\hline
Hazlett-Stevens \& Oren & 0.5286638 & 0.2104609 & low & no intervention & long & mindfulness\\
\hline
Hintz et al. & 0.2840000 & 0.1680000 & low & information only & short & PCI\\
\hline
Kang et al. & 1.2750682 & 0.3371997 & low & no intervention & long & mindfulness\\
\hline
Kuhlmann et al. & 0.1036082 & 0.1947275 & low & no intervention & short & mindfulness\\
\hline
Lever Taylor et al. & 0.3883906 & 0.2307689 & low & WLC & long & mindfulness\\
\hline
Phang et al. & 0.5407398 & 0.2443133 & low & no intervention & short & mindfulness\\
\hline
Rasanen et al. & 0.4261593 & 0.2579379 & low & WLC & short & ACT\\
\hline
Ratanasiripong & 0.5153969 & 0.3512737 & high & no intervention & short & mindfulness\\
\hline
Shapiro et al. & 1.4797260 & 0.3152817 & low & WLC & long & mindfulness\\
\hline
SongLindquist & 0.6125782 & 0.2266834 & high & WLC & long & mindfulness\\
\hline
Warnecke et al. & 0.6000000 & 0.2490000 & low & information only & long & mindfulness\\
\hline
\end{tabular}
\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
\section{Data manipulation}\label{data-manipulation}
Now that we have the Meta-Analysis data in RStudio, let's do a
\textbf{few manipulations with the data}. These functions might come in
handy when were conducting analyses later on.
Going back to the output of the \texttt{str()} function, we see that
this also gives us details on the type of column data we have stored in
our data. There a different abbreviations signifying different types of
data.
\begin{tabular}{l|l|l}
\hline
Abbreviation & Type & Description\\
\hline
num & Numerical & This is all data stored as numbers (e.g. 1.02)\\
\hline
chr & Character & This is all data stored as words\\
\hline
log & Logical & These are variables which are binary, meaning that they signify that a condition is either TRUE or FALSE\\
\hline
factor & Factor & Factors are stored as numbers, with each number signifying a different level of a variable. A possible factor of a variable might be 1 = low, 2 = medium, 3 = high\\
\hline
\end{tabular}
\hypertarget{convertfactors}{\subsection{Converting to
factors}\label{convertfactors}}
Let's say we have the subgroup \textbf{Risk of Bias} (in which the Risk
of Bias rating is coded), and want it to be a factor with two different
levels: ``low'' and ``high''.
To do this, we need to the variable \texttt{ROB} to be a factor.
However, this variable is currently stored as a character
(\texttt{chr}). We can have a look at this variable by typing the name
of our dataset, then adding the selector \texttt{\$} and then adding the
variable we want to have a look at.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{madata}\OperatorTok{$}\NormalTok{ROB}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## [1] "high" "low" "high" "low" "low" "low" "high" "low" "low" "low"
## [11] "high" "low" "low" "low" "high" "high" "high" "low"
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{str}\NormalTok{(madata}\OperatorTok{$}\NormalTok{ROB)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## chr [1:18] "high" "low" "high" "low" "low" "low" "high" "low" "low" ...
\end{verbatim}
We can see now that \texttt{ROB}is indeed a \textbf{character} type
variable, which contains only two words: ``low'' and ``high''. We want
to convert this to a \textbf{factor} variable now, which has only two
levels, low and high. To do this, we use the \texttt{factor()} function.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{madata}\OperatorTok{$}\NormalTok{ROB<-}\KeywordTok{factor}\NormalTok{(madata}\OperatorTok{$}\NormalTok{ROB)}
\NormalTok{madata}\OperatorTok{$}\NormalTok{ROB}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## [1] high low high low low low high low low low high low low low
## [15] high high high low
## Levels: high low
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{str}\NormalTok{(madata}\OperatorTok{$}\NormalTok{ROB)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Factor w/ 2 levels "high","low": 1 2 1 2 2 2 1 2 2 2 ...
\end{verbatim}
We now see that the variable has been \textbf{converted to a factor with
the levels ``high'' and ``low''}.
\subsection{Converting to logicals}\label{converting-to-logicals}
Now lets have a look at the \textbf{intervention type} subgroup
variable. This variable is currently stores as a character \texttt{chr}
too.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{madata}\OperatorTok{$}\StringTok{`}\DataTypeTok{intervention type}\StringTok{`}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## [1] "mindfulness" "mindfulness" "ACT" "mindfulness" "PCI"
## [6] "ACT" "mindfulness" "mindfulness" "PCI" "mindfulness"
## [11] "mindfulness" "mindfulness" "mindfulness" "ACT" "mindfulness"
## [16] "mindfulness" "mindfulness" "mindfulness"
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{str}\NormalTok{(madata}\OperatorTok{$}\StringTok{`}\DataTypeTok{intervention type}\StringTok{`}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## chr [1:18] "mindfulness" "mindfulness" "ACT" "mindfulness" "PCI" ...
\end{verbatim}
Let's say we want a variable which only contains information if a study
way a mindfulness intervention or not. A logical is very well suited for
this. To convert the data to logical, we use the \texttt{as.logical}
function. We will create a new variable containing this information
called \texttt{intervention.type.logical}. To tell R what to count as
\texttt{TRUE} and what as \texttt{FALSE}, we have to define the specific
intervention type using the \texttt{==} command.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{intervention.type.logical<-}\KeywordTok{as.logical}\NormalTok{(madata}\OperatorTok{$}\StringTok{`}\DataTypeTok{intervention type}\StringTok{`}\OperatorTok{==}\StringTok{"mindfulness"}\NormalTok{)}
\NormalTok{intervention.type.logical}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## [1] TRUE TRUE FALSE TRUE FALSE FALSE TRUE TRUE FALSE TRUE TRUE
## [12] TRUE TRUE FALSE TRUE TRUE TRUE TRUE
\end{verbatim}
We see that R has converted the character information into trues and
falses for us. To check if this was done correctly, let's compare the
original and the new variable
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{n<-}\KeywordTok{data.frame}\NormalTok{(intervention.type.logical,madata}\OperatorTok{$}\StringTok{`}\DataTypeTok{intervention type}\StringTok{`}\NormalTok{)}
\NormalTok{names<-}\KeywordTok{c}\NormalTok{(}\StringTok{"New"}\NormalTok{, }\StringTok{"Original"}\NormalTok{)}
\KeywordTok{colnames}\NormalTok{(n)<-names}
\KeywordTok{kable}\NormalTok{(n)}
\end{Highlighting}
\end{Shaded}
\begin{tabular}{l|l}
\hline
New & Original\\
\hline
TRUE & mindfulness\\
\hline
TRUE & mindfulness\\
\hline
FALSE & ACT\\
\hline
TRUE & mindfulness\\
\hline
FALSE & PCI\\
\hline
FALSE & ACT\\
\hline
TRUE & mindfulness\\
\hline
TRUE & mindfulness\\
\hline
FALSE & PCI\\
\hline
TRUE & mindfulness\\
\hline
TRUE & mindfulness\\
\hline
TRUE & mindfulness\\
\hline
TRUE & mindfulness\\
\hline
FALSE & ACT\\
\hline
TRUE & mindfulness\\
\hline
TRUE & mindfulness\\
\hline
TRUE & mindfulness\\
\hline
TRUE & mindfulness\\
\hline
\end{tabular}
\hypertarget{select}{\subsection{Selecting specific
studies}\label{select}}
It may often come in handy to \textbf{select certain studies for further
analyses}, or to \textbf{exclude some studies in further analyses}
(e.g., if they are outliers).
To do this, we can use the \texttt{filter} function in the
\texttt{dplyr}package, which is part of the \texttt{tidyverse} package
we installed before.
So, let's load the package first.
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{library}\NormalTok{(dplyr)}
\end{Highlighting}
\end{Shaded}
Let's say we want to do a Meta-Analysis with three studies in our
dataset only. To do this, we need to create a new dataset containing
only these studies using the \texttt{dplyr::filter()} function. The
\texttt{dplyr::} part is necessary as there is more than one
`\texttt{filter} function in R, and we want to use to use the one of the
\texttt{dplyr}package.
Let's say we want to have the studies by \textbf{Cavanagh et al.},
\textbf{Frazier et al.} and \textbf{Phang et al.} stored in another