Articles by Numerilab

Functions and iteration

February 27, 2020 | Numerilab

Functions and iteration Introduction Functions in R allow us to automate things, instead of copy-pasting code. 3 major advantages : Functions can have names, so it makes code easier to read If your requirements change, you only have one place ...
[Read more...]

Meta-analysis

December 19, 2019 | Numerilab

Meta-analysis
<span class="n">library</span><span class="p">(</span><span class="n">dplyr</span><span class="p">)</span><span class="w"> </span><span class="c1"># data manipulation</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">ggplot2</span><span class="p">)</span><span class="w"> </span><span class="c1"># visualizations</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">metafor</span><span class="p">)</span><span class="w"> </span><span class="c1"># ready-made meta-analysis code</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">gt</span><span class="p">)</span><span class="w"> </span><span class="c1"># nice tables</span><span class="w">
</span>
Basic principle Scientific question Does playing Mozart to newborns improves their IQ? You look a bit around and find 3 studies :
<span class="n">etudes</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">data.frame</span><span class="p">(</span><span class="w">
  </span><span class="n">article</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="s2">"A"</span><span class="p">,</span><span class="s2">"B"</span><span class="p">,</span><span class="s2">"C"</span><span class="p">),</span><span class="w">
  </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="m">0.5</span><span class="p">,</span><span class="w"> </span><span class="m">0.01</span><span class="p">,</span><span class="w"> </span><span class="m">-0.1</span><span class="p">),</span><span class="w"> </span><span class="c1"># 0 no effect, <0 negative effect, >0 positive effect</span><span class="w">
  </span><span class="n">n</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="m">10</span><span class="p">,</span><span class="m">150</span><span class="p">,</span><span class="m">12</span><span class="p">),</span><span class="w">
  </span><span class="n">v</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="m">0.04</span><span class="p">,</span><span class="m">0.01</span><span class="p">,</span><span class="w"> </span><span class="m">0.03</span><span class="p">)</span><span class="w"> </span><span class="c1"># variance</span><span class="w">
</span><span class="p">)</span><span class="w">
</span><span class="n">etudes</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="n">gt</span><span class="w">
</span>
article y n v A 0.50 10 0.04 B 0.01 150 0.01 C -0.10 12 0.03 A simplistic way
<span class="n">etudes</span><span class="w"> </span><span class="o">%>%</span><span class="w">
  </span><span class="n">summarise</span><span class="p">(</span><span class="w">
    </span><span class="n">effet_resume</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mean</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="w">
  </span><span class="p">)</span><span class="w">
</span>
  effet_resume
1    0.1366667
Weighted mean When we talk about mean, we usually refer to the arithmetic mean : {{...
[Read more...]

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)