Copy/paste t-tests Directly to Manuscripts

[This article was first published on Dominique Makowski, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

One of the most time-consuming part of data analysis in psychology is the copy-pasting of specific values of some R output to a manuscript or a report. This task is frustrating, prone to errors, and increases the variability of statistical reporting. This is an important issue, as standardizing practices of what and how to report might be a key to overcome the reproducibility crisis of psychology. The psycho package was designed specifically to do this job. At first, for complex Bayesian mixed models, but the package is now compatible with basic methods, such as t-tests.

Do a t-test

<span class="c1"># Load packages</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">tidyverse</span><span class="p">)</span><span class="w">

</span><span class="c1"># devtools::install_github("neuropsychology/psycho.R")  # Install the latest psycho version</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">psycho</span><span class="p">)</span><span class="w">

</span><span class="n">df</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">psycho</span><span class="o">::</span><span class="n">affective</span><span class="w">  </span><span class="c1"># Load the data</span><span class="w">


</span><span class="n">results</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">t.test</span><span class="p">(</span><span class="n">df</span><span class="o">$</span><span class="n">Age</span><span class="w"> </span><span class="o">~</span><span class="w"> </span><span class="n">df</span><span class="o">$</span><span class="n">Sex</span><span class="p">)</span><span class="w">  </span><span class="c1"># Perform a simple t-test</span><span class="w">
</span>

APA formatted output

You simply run the analyze() function on the t-test object.

<span class="n">psycho</span><span class="o">::</span><span class="n">analyze</span><span class="p">(</span><span class="n">results</span><span class="p">)</span><span class="w">
</span>
The Welch Two Sample t-test suggests that the difference of df$Age by df$Sex (mean in group F = 26.78, mean in group M = 27.45, difference = -0.67) is not significant (t(360.68) = -0.86, 95% CI [-2.21, 0.87], p > .1).

Flexibility

It works for all kinds of different t-tests versions.

<span class="n">t.test</span><span class="p">(</span><span class="n">df</span><span class="o">$</span><span class="n">Adjusting</span><span class="w"> </span><span class="o">~</span><span class="w"> </span><span class="n">df</span><span class="o">$</span><span class="n">Sex</span><span class="p">,</span><span class="w">
       </span><span class="n">var.equal</span><span class="o">=</span><span class="kc">TRUE</span><span class="p">,</span><span class="w"> 
       </span><span class="n">conf.level</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">.90</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">psycho</span><span class="o">::</span><span class="n">analyze</span><span class="p">()</span><span class="w">
</span>
The  Two Sample t-test suggests that the difference of df$Adjusting by df$Sex (mean in group F = 3.72, mean in group M = 4.13, difference = -0.41) is significant (t(1249) = -4.13, 90% CI [-0.58, -0.25], p < .001).
<span class="n">t.test</span><span class="p">(</span><span class="n">df</span><span class="o">$</span><span class="n">Adjusting</span><span class="p">,</span><span class="w">
       </span><span class="n">mu</span><span class="o">=</span><span class="m">0</span><span class="p">,</span><span class="w">
       </span><span class="n">conf.level</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">.90</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">psycho</span><span class="o">::</span><span class="n">analyze</span><span class="p">()</span><span class="w">
</span>
The One Sample t-test suggests that the difference between df$Adjusting (mean = 3.80) and mu = 0 is significant (t(1250) = 93.93, 90% CI [3.74, 3.87], p < .001).

Dataframe of Values

It is also possible to have all the values stored in a dataframe by running a summary on the analyzed object.

<span class="n">library</span><span class="p">(</span><span class="n">tidyverse</span><span class="p">)</span><span class="w">

</span><span class="n">t.test</span><span class="p">(</span><span class="n">df</span><span class="o">$</span><span class="n">Adjusting</span><span class="w"> </span><span class="o">~</span><span class="w"> </span><span class="n">df</span><span class="o">$</span><span class="n">Sex</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">psycho</span><span class="o">::</span><span class="n">analyze</span><span class="p">()</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">summary</span><span class="p">()</span><span class="w">
</span>
effect statistic df p CI_lower CI_higher
-0.4149661 -4.067008 377.8364 5.8e-05 -0.6155884 -0.2143439

Contribute

Of course, these reporting standards should change, depending on new expert recommandations or official guidelines. The goal of this package is to flexibly adapt to new changes and accompany the evolution of best practices. Therefore, if you have any advices, opinions or ideas, we encourage you to let us know by opening an issue or, even better, to try to implement changes yourself by contributing to the code.

Credits

This package helped you? Don’t forget to cite the various packages you used 🙂

You can cite psycho as follows:

  • Makowski, (2018). The psycho Package: An Efficient and Publishing-Oriented Workflow for Psychological Science. Journal of Open Source Software, 3(22), 470. https://doi.org/10.21105/joss.00470

Previous blogposts

To leave a comment for the author, please follow the link and comment on their blog: Dominique Makowski.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)