<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/copy-paste-t-tests-directly-to-manuscripts/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://neuropsychology.github.io/psycho.R//2018/06/19/analyze_ttest.html"> Dominique Makowski</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<ul>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/06/19/analyze_ttest.html#do-a-t-test" target="_blank">Do a t-test</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/06/19/analyze_ttest.html#apa-formatted-output" target="_blank">APA formatted output</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/06/19/analyze_ttest.html#flexibility" target="_blank">Flexibility</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/06/19/analyze_ttest.html#dataframe-of-values" target="_blank">Dataframe of Values</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/06/19/analyze_ttest.html#contribute" target="_blank">Contribute</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/06/19/analyze_ttest.html#credits" target="_blank">Credits</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/06/19/analyze_ttest.html#previous-blogposts" target="_blank">Previous blogposts</a></li>
</ul>
<p><img alt="" src="https://i1.wp.com/raw.githubusercontent.com/neuropsychology/psycho.R/master/vignettes/images/logo.PNG?w=456&ssl=1" data-recalc-dims="1"></p>
<p>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. <strong>The <a rel="nofollow" href="https://github.com/neuropsychology/psycho.R" target="_blank">psycho</a> package was designed specifically to do this job</strong>. At first, for complex <a rel="nofollow" href="https://cran.r-project.org/web/packages/psycho/vignettes/bayesian.html" target="_blank">Bayesian mixed models</a>, but the package is now compatible with basic methods, such as <strong>t-tests</strong>.</p>
<h1>Do a t-test</h1>
<div>
<div>
<pre><code><span># Load packages</span><span>
</span><span>library</span><span>(</span><span>tidyverse</span><span>)</span><span>
</span><span># devtools::install_github(&quot;neuropsychology/psycho.R&quot;) # Install the latest psycho version</span><span>
</span><span>library</span><span>(</span><span>psycho</span><span>)</span><span>
</span><span>df</span><span> </span><span>&lt;-</span><span> </span><span>psycho</span><span>::</span><span>affective</span><span> </span><span># Load the data</span><span>
</span><span>results</span><span> </span><span>&lt;-</span><span> </span><span>t.test</span><span>(</span><span>df</span><span>$</span><span>Age</span><span> </span><span>~</span><span> </span><span>df</span><span>$</span><span>Sex</span><span>)</span><span> </span><span># Perform a simple t-test</span><span>
</span></code></pre>
</div>
</div>
<h1>APA formatted output</h1>
<p>You simply run the <code>analyze()</code> function on the t-test object.</p>
<div>
<div>
<pre><code><span>psycho</span><span>::</span><span>analyze</span><span>(</span><span>results</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>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).
</code></pre>
</div>
</div>
<h1>Flexibility</h1>
<p>It works for all kinds of different t-tests versions.</p>
<div>
<div>
<pre><code><span>t.test</span><span>(</span><span>df</span><span>$</span><span>Adjusting</span><span> </span><span>~</span><span> </span><span>df</span><span>$</span><span>Sex</span><span>,</span><span>
</span><span>var.equal</span><span>=</span><span>TRUE</span><span>,</span><span> </span><span>conf.level</span><span> </span><span>=</span><span> </span><span>.90</span><span>)</span><span> </span><span>%>%</span><span> </span><span>psycho</span><span>::</span><span>analyze</span><span>()</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>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 &lt; .001).
</code></pre>
</div>
</div>
<div>
<div>
<pre><code><span>t.test</span><span>(</span><span>df</span><span>$</span><span>Adjusting</span><span>,</span><span>
</span><span>mu</span><span>=</span><span>0</span><span>,</span><span>
</span><span>conf.level</span><span> </span><span>=</span><span> </span><span>.90</span><span>)</span><span> </span><span>%>%</span><span> </span><span>psycho</span><span>::</span><span>analyze</span><span>()</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>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 &lt; .001).
</code></pre>
</div>
</div>
<h1>Dataframe of Values</h1>
<p>It is also possible to have all the values stored in a dataframe by running a <strong>summary</strong> on the analyzed object.</p>
<div>
<div>
<pre><code><span>library</span><span>(</span><span>tidyverse</span><span>)</span><span>
</span><span>t.test</span><span>(</span><span>df</span><span>$</span><span>Adjusting</span><span> </span><span>~</span><span> </span><span>df</span><span>$</span><span>Sex</span><span>)</span><span> </span><span>%>%</span><span> </span><span>psycho</span><span>::</span><span>analyze</span><span>()</span><span> </span><span>%>%</span><span> </span><span>summary</span><span>()</span><span>
</span></code></pre>
</div>
</div>
<table>
<thead>
<tr>
<th>effect</th>
<th>statistic</th>
<th>df</th>
<th>p</th>
<th>CI_lower</th>
<th>CI_higher</th>
</tr>
</thead>
<tbody>
<tr>
<td>-0.4149661</td>
<td>-4.067008</td>
<td>377.8364</td>
<td>5.8e-05</td>
<td>-0.6155884</td>
<td>-0.2143439</td>
</tr>
</tbody>
</table>
<h1>Contribute</h1>
<p>Of course, these reporting standards should change, depending on new expert recommandations or official guidelines. <strong>The goal of this package is to flexibly adapt to new changes and accompany the evolution of best practices</strong>. Therefore, if you have any advices, opinions or ideas, we encourage you to let us know by opening an <a rel="nofollow" href="https://github.com/neuropsychology/psycho.R/issues" target="_blank">issue</a> or, even better, to try to implement changes yourself by <a rel="nofollow" href="https://github.com/neuropsychology/psycho.R/blob/master/.github/CONTRIBUTING.md" target="_blank">contributing</a> to the code.</p>
<h1>Credits</h1>
<p>This package helped you? Don’t forget to cite the various packages you used <img alt="🙂" src="https://s.w.org/images/core/emoji/2.4/72x72/1f642.png" class="wp-smiley"></p>
<p>You can cite <code>psycho</code> as follows:</p>
<ul>
<li>Makowski, (2018). <em>The psycho Package: An Efficient and Publishing-Oriented Workflow for Psychological Science</em>. Journal of Open Source Software, 3(22), 470. <a rel="nofollow" href="https://doi.org/10.21105/joss.00470" target="_blank">https://doi.org/10.21105/joss.00470</a></li>
</ul>
<h1>Previous blogposts</h1>
<ul>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R/2018/06/11/bayesian_correlation.html" target="_blank">APA Formatted Bayesian Correlation</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R/2018/06/03/plot_bayesian_model.html" target="_blank">Fancy Plot (with Posterior Samples) for Bayesian Regressions</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R/2018/05/24/n_factors.html" target="_blank">How Many Factors to Retain in Factor Analysis</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R/2018/05/20/correlation.html" target="_blank">Beautiful and Powerful Correlation Tables</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R/2018/05/10/interpret_mixed_models.html" target="_blank">Format and Interpret Linear Mixed Models</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R/2018/05/01/repeated_measure_anovas.html" target="_blank">How to do Repeated Measures ANOVAs</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R/2018/03/29/standardize.html" target="_blank">Standardize (Z-score) a dataframe</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R/2018/03/29/SDT.html" target="_blank">Compute Signal Detection Theory Indices</a></li>
</ul>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://neuropsychology.github.io/psycho.R//2018/06/19/analyze_ttest.html"> Dominique Makowski</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/9qATRaiQVEE" height="1"></a></div>