{"id":11693,"date":"2019-12-26T10:23:34","date_gmt":"2019-12-26T08:23:34","guid":{"rendered":"https:\/\/www.datanovia.com\/en\/?post_type=dt_lessons&#038;p=11693"},"modified":"2019-12-26T10:26:35","modified_gmt":"2019-12-26T08:26:35","slug":"how-to-do-a-t-test-in-r-calculation-and-reporting","status":"publish","type":"dt_lessons","link":"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/","title":{"rendered":"How to Do a T-test in R: Calculation and Reporting"},"content":{"rendered":"<div id=\"rdoc\">\n<p>This article describes <strong>how to do a t-test in R<\/strong> (or in <em>Rstudio<\/em>). You will learn how to:<\/p>\n<ul>\n<li><em>Perform a t-test in R<\/em> using the following functions :\n<ul>\n<li><code>t_test()<\/code> [rstatix package]: a wrapper around the R base function <code>t.test()<\/code>. The result is a data frame, which can be easily added to a plot using the <code>ggpubr<\/code> R package.<\/li>\n<li><code>t.test()<\/code> [stats package]: R base function to conduct a t-test.<\/li>\n<\/ul>\n<\/li>\n<li><em>Interpret and report the t-test<\/em><\/li>\n<li><em>Add p-values and significance levels to a plot<\/em><\/li>\n<li><em>Calculate and report the t-test effect size<\/em> using <em>Cohen\u2019s d<\/em>. The <code>d<\/code> statistic redefines the difference in means as the number of standard deviations that separates those means. T-test conventional effect sizes, proposed by Cohen, are: 0.2 (small effect), 0.5 (moderate effect) and 0.8 (large effect) <span class=\"citation\">(Cohen 1998)<\/span>.<\/li>\n<\/ul>\n<p>We will provide examples of R code to run the different types of t-test in R, including the:<\/p>\n<ul>\n<li>one-sample t-test<\/li>\n<li>two-sample t-test (also known as independent t-test or unpaired t-test)<\/li>\n<li>paired t-test (also known as dependent t-test or matched pairs t test)<\/li>\n<\/ul>\n<p>Contents:<\/p>\n<div id=\"TOC\">\n<ul>\n<li><a href=\"#prerequisites\">Prerequisites<\/a><\/li>\n<li><a href=\"#one-sample-t-test\">One-sample t-test<\/a>\n<ul>\n<li><a href=\"#demo-data\">Demo data<\/a><\/li>\n<li><a href=\"#summary-statistics\">Summary statistics<\/a><\/li>\n<li><a href=\"#calculation\">Calculation<\/a><\/li>\n<li><a href=\"#interpretation\">Interpretation<\/a><\/li>\n<li><a href=\"#effect-size\">Effect size<\/a><\/li>\n<li><a href=\"#reporting\">Reporting<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#two-sample-t-test\">Two-sample t-test<\/a>\n<ul>\n<li><a href=\"#demo-data-1\">Demo data<\/a><\/li>\n<li><a href=\"#summary-statistics-1\">Summary statistics<\/a><\/li>\n<li><a href=\"#calculation-1\">Calculation<\/a><\/li>\n<li><a href=\"#interpretation-1\">Interpretation<\/a><\/li>\n<li><a href=\"#effect-size-1\">Effect size<\/a><\/li>\n<li><a href=\"#cohens-d-for-student-t-test\">Cohen\u2019s d for Student t-test<\/a><\/li>\n<li><a href=\"#cohens-d-for-welch-t-test\">Cohen\u2019s d for Welch t-test<\/a><\/li>\n<li><a href=\"#report\">Report<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#paired-t-test\">Paired t-test<\/a>\n<ul>\n<li><a href=\"#demo-data-2\">Demo data<\/a><\/li>\n<li><a href=\"#summary-statistics-2\">Summary statistics<\/a><\/li>\n<li><a href=\"#calculation-2\">Calculation<\/a><\/li>\n<li><a href=\"#interpretation-2\">Interpretation<\/a><\/li>\n<li><a href=\"#effect-size-2\">Effect size<\/a><\/li>\n<li><a href=\"#report-1\">Report<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#summary\">Summary<\/a><\/li>\n<li><a href=\"#references\">References<\/a><\/li>\n<\/ul>\n<\/div>\n<div class='dt-sc-hr-invisible-medium  '><\/div>\n<div class='dt-sc-ico-content type1'><div class='custom-icon' ><a href='https:\/\/www.datanovia.com\/en\/product\/practical-statistics-in-r-for-comparing-groups-numerical-variables\/' target='_blank'><span class='fa fa-book'><\/span><\/a><\/div><h4><a href='https:\/\/www.datanovia.com\/en\/product\/practical-statistics-in-r-for-comparing-groups-numerical-variables\/' target='_blank'> Related Book <\/a><\/h4>Practical Statistics in R II - Comparing Groups: Numerical Variables<\/div>\n<div class='dt-sc-hr-invisible-medium  '><\/div>\n<div id=\"prerequisites\" class=\"section level2\">\n<h2>Prerequisites<\/h2>\n<p>Make sure you have installed the following R packages:<\/p>\n<ul>\n<li><code>tidyverse<\/code> for data manipulation and visualization<\/li>\n<li><code>ggpubr<\/code> for creating easily publication ready plots<\/li>\n<li><code>rstatix<\/code> provides pipe-friendly R functions for easy statistical analyses.<\/li>\n<li><code>datarium<\/code>: contains required data sets for this chapter.<\/li>\n<\/ul>\n<p>Start by loading the following required packages:<\/p>\n<pre class=\"r\"><code>library(tidyverse)\r\nlibrary(ggpubr)\r\nlibrary(rstatix)<\/code><\/pre>\n<\/div>\n<div id=\"one-sample-t-test\" class=\"section level2\">\n<h2>One-sample t-test<\/h2>\n<div id=\"demo-data\" class=\"section level3\">\n<h3>Demo data<\/h3>\n<p>Demo dataset: <code>mice<\/code> [in datarium package]. Contains the weight of 10 mice:<\/p>\n<pre class=\"r\"><code># Load and inspect the data\r\ndata(mice, package = \"datarium\")\r\nhead(mice, 3)<\/code><\/pre>\n<pre><code>## # A tibble: 3 x 2\r\n##   name  weight\r\n##   &lt;chr&gt;  &lt;dbl&gt;\r\n## 1 M_1     18.9\r\n## 2 M_2     19.5\r\n## 3 M_3     23.1<\/code><\/pre>\n<div class=\"block\">\n<p>We want to know, whether the average weight of the mice differs from 25g (two-tailed test)?<\/p>\n<\/div>\n<\/div>\n<div id=\"summary-statistics\" class=\"section level3\">\n<h3>Summary statistics<\/h3>\n<p>Compute some summary statistics: count (number of subjects), mean and sd (standard deviation)<\/p>\n<pre class=\"r\"><code>mice %&gt;% get_summary_stats(weight, type = \"mean_sd\")<\/code><\/pre>\n<pre><code>## # A tibble: 1 x 4\r\n##   variable     n  mean    sd\r\n##   &lt;chr&gt;    &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;\r\n## 1 weight      10  20.1  1.90<\/code><\/pre>\n<\/div>\n<div id=\"calculation\" class=\"section level3\">\n<h3>Calculation<\/h3>\n<div id=\"using-the-r-base-function\" class=\"section level4\">\n<h4>Using the R base function<\/h4>\n<pre class=\"r\"><code>res &lt;- t.test(mice$weight, mu = 25)\r\nres<\/code><\/pre>\n<pre><code>## \r\n##  One Sample t-test\r\n## \r\n## data:  mice$weight\r\n## t = -8, df = 9, p-value = 2e-05\r\n## alternative hypothesis: true mean is not equal to 25\r\n## 95 percent confidence interval:\r\n##  18.8 21.5\r\n## sample estimates:\r\n## mean of x \r\n##      20.1<\/code><\/pre>\n<p>In the result above :<\/p>\n<ul>\n<li><code>t<\/code> is the t-test statistic value (t = -8.105),<\/li>\n<li><code>df<\/code> is the degrees of freedom (df= 9),<\/li>\n<li><code>p-value<\/code> is the significance level of the t-test (p-value = 1.99510^{-5}).<\/li>\n<li><code>conf.int<\/code> is the confidence interval of the mean at 95% (conf.int = [18.7835, 21.4965]);<\/li>\n<li><code>sample estimates<\/code> is the mean value of the sample (mean = 20.14).<\/li>\n<\/ul>\n<\/div>\n<div id=\"using-the-rstatix-package\" class=\"section level4\">\n<h4>Using the rstatix package<\/h4>\n<p>We\u2019ll use the pipe-friendly <code>t_test()<\/code> function [rstatix package], a wrapper around the R base function <code>t.test()<\/code>. The results can be easily added to a plot using the <code>ggpubr<\/code> R package.<\/p>\n<pre class=\"r\"><code>stat.test &lt;- mice %&gt;% t_test(weight ~ 1, mu = 25)\r\nstat.test<\/code><\/pre>\n<pre><code>## # A tibble: 1 x 7\r\n##   .y.    group1 group2         n statistic    df       p\r\n## * &lt;chr&gt;  &lt;chr&gt;  &lt;chr&gt;      &lt;int&gt;     &lt;dbl&gt; &lt;dbl&gt;   &lt;dbl&gt;\r\n## 1 weight 1      null model    10     -8.10     9 0.00002<\/code><\/pre>\n<p>The results above show the following components:<\/p>\n<ul>\n<li><code>.y.<\/code>: the outcome variable used in the test.<\/li>\n<li><code>group1,group2<\/code>: generally, the compared groups in the pairwise tests. Here, we have null model (one-sample test).<\/li>\n<li><code>statistic<\/code>: test statistic (t-value) used to compute the p-value.<\/li>\n<li><code>df<\/code>: degrees of freedom.<\/li>\n<li><code>p<\/code>: p-value.<\/li>\n<\/ul>\n<div class=\"warning\">\n<p>You can obtain a detailed result by specifying the option <code>detailed = TRUE<\/code> in the function <code>t_test()<\/code>.<\/p>\n<\/div>\n<pre class=\"r\"><code>mice %&gt;% t_test(weight ~ 1, mu = 25, detailed = TRUE)<\/code><\/pre>\n<pre><code>## # A tibble: 1 x 12\r\n##   estimate .y.    group1 group2         n statistic       p    df conf.low conf.high method alternative\r\n## *    &lt;dbl&gt; &lt;chr&gt;  &lt;chr&gt;  &lt;chr&gt;      &lt;int&gt;     &lt;dbl&gt;   &lt;dbl&gt; &lt;dbl&gt;    &lt;dbl&gt;     &lt;dbl&gt; &lt;chr&gt;  &lt;chr&gt;      \r\n## 1     20.1 weight 1      null model    10     -8.10 0.00002     9     18.8      21.5 T-test two.sided<\/code><\/pre>\n<\/div>\n<\/div>\n<div id=\"interpretation\" class=\"section level3\">\n<h3>Interpretation<\/h3>\n<p>The p-value of the test is 210^{-5}, which is less than the significance level alpha = 0.05. We can conclude that the mean weight of the mice is significantly different from 25g with a <strong>p-value<\/strong> = 210^{-5}.<\/p>\n<\/div>\n<div id=\"effect-size\" class=\"section level3\">\n<h3>Effect size<\/h3>\n<p>To calculate an effect size, called <code>Cohen's d<\/code>, for the one-sample t-test you need to divide the mean difference by the standard deviation of the difference, as shown below. Note that, here: <code>sd(x-mu) = sd(x)<\/code>.<\/p>\n<p><strong>Cohen\u2019s d formula<\/strong>:<\/p>\n<p><span class=\"math display\">\\[<br \/>\nd = \\frac{m-\\mu}{s}<br \/>\n\\]<\/span><\/p>\n<ul>\n<li><span class=\"math inline\">\\(m\\)<\/span> is the sample mean<\/li>\n<li><span class=\"math inline\">\\(s\\)<\/span> is the sample standard deviation with <span class=\"math inline\">\\(n-1\\)<\/span> degrees of freedom<\/li>\n<li><span class=\"math inline\">\\(\\mu\\)<\/span> is the theoretical mean against which the mean of our sample is compared (default value is mu = 0).<\/li>\n<\/ul>\n<p><strong>Calculation<\/strong>:<\/p>\n<pre class=\"r\"><code>mice %&gt;% cohens_d(weight ~ 1, mu = 25)<\/code><\/pre>\n<pre><code>## # A tibble: 1 x 6\r\n##   .y.    group1 group2     effsize     n magnitude\r\n## * &lt;chr&gt;  &lt;chr&gt;  &lt;chr&gt;        &lt;dbl&gt; &lt;int&gt; &lt;ord&gt;    \r\n## 1 weight 1      null model    10.6    10 large<\/code><\/pre>\n<div class=\"success\">\n<p>Recall that, t-test conventional effect sizes, proposed by Cohen J. (1998), are: 0.2 (small effect), 0.5 (moderate effect) and 0.8 (large effect) (Cohen 1998). As the effect size, d, is 2.56 you can conclude that there is a large effect.<\/p>\n<\/div>\n<\/div>\n<div id=\"reporting\" class=\"section level3\">\n<h3>Reporting<\/h3>\n<p>We could report the result as follow:<\/p>\n<p>A one-sample t-test was computed to determine whether the recruited mice average weight was different to the population normal mean weight (25g).<\/p>\n<p>The measured mice mean weight (20.14 +\/- 1.94) was statistically significantly lower than the population normal mean weight 25 (<code>t(9) = -8.1, p &lt; 0.0001, d = 2.56<\/code>); where t(9) is shorthand notation for a t-statistic that has 9 degrees of freedom.<\/p>\n<p>The results can be visualized using either a box plot or a density plot.<\/p>\n<div id=\"box-plot\" class=\"section level4\">\n<h4>Box Plot<\/h4>\n<p>Create a boxplot to visualize the distribution of mice weights. Add also jittered points to show individual observations. The big dot represents the mean point.<\/p>\n<pre class=\"r\"><code># Create the box-plot\r\nbxp &lt;- ggboxplot(\r\n  mice$weight, width = 0.5, add = c(\"mean\", \"jitter\"), \r\n  ylab = \"Weight (g)\", xlab = FALSE\r\n  )\r\n# Add significance levels\r\nbxp + labs(subtitle = get_test_label(stat.test, detailed = TRUE))<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/r-statistics-2-comparing-groups-means\/figures\/084-how-to-do-a-t-test-in-r-one-sample-box-plot-with-p-value-1.png\" width=\"336\" \/><\/p>\n<\/div>\n<div id=\"density-plot\" class=\"section level4\">\n<h4>Density plot<\/h4>\n<p>Create a density plot with p-value:<\/p>\n<ul>\n<li>Red line corresponds to the observed mean<\/li>\n<li>Blue line corresponds to the theoretical mean<\/li>\n<\/ul>\n<pre class=\"r\"><code>ggdensity(mice, x = \"weight\", rug = TRUE, fill = \"lightgray\") +\r\n  scale_x_continuous(limits = c(15, 27)) +\r\n  stat_central_tendency(type = \"mean\", color = \"red\", linetype = \"dashed\") +\r\n  geom_vline(xintercept = 25, color = \"blue\", linetype = \"dashed\") + \r\n  labs(subtitle = get_test_label(stat.test,  detailed = TRUE))<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/r-statistics-2-comparing-groups-means\/figures\/084-how-to-do-a-t-test-in-r-one-sample-density-with-p-value-1.png\" width=\"384\" \/><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"two-sample-t-test\" class=\"section level2\">\n<h2>Two-sample t-test<\/h2>\n<p>The two-sample t-test is also known as the independent t-test. The independent samples t-test comes in two different forms:<\/p>\n<ul>\n<li>the standard <em>Student\u2019s t-test<\/em>, which assumes that the variance of the two groups are equal.<\/li>\n<li>the <em>Welch\u2019s t-test<\/em>, which is less restrictive compared to the original Student\u2019s test. This is the test where you do not assume that the variance is the same in the two groups, which results in the fractional degrees of freedom.<\/li>\n<\/ul>\n<div class=\"warning\">\n<p>The two methods give very similar results unless both the group sizes and the standard deviations are very different.<\/p>\n<\/div>\n<div id=\"demo-data-1\" class=\"section level3\">\n<h3>Demo data<\/h3>\n<p>Demo dataset: <code>genderweight<\/code> [in datarium package] containing the weight of 40 individuals (20 women and 20 men).<\/p>\n<p>Load the data and show some random rows by groups:<\/p>\n<pre class=\"r\"><code># Load the data\r\ndata(\"genderweight\", package = \"datarium\")\r\n# Show a sample of the data by group\r\nset.seed(123)\r\ngenderweight %&gt;% sample_n_by(group, size = 2)<\/code><\/pre>\n<pre><code>## # A tibble: 4 x 3\r\n##   id    group weight\r\n##   &lt;fct&gt; &lt;fct&gt;  &lt;dbl&gt;\r\n## 1 6     F       65.0\r\n## 2 15    F       65.9\r\n## 3 29    M       88.9\r\n## 4 37    M       77.0<\/code><\/pre>\n<div class=\"block\">\n<p>We want to know, whether the average weights are different between groups.<\/p>\n<\/div>\n<\/div>\n<div id=\"summary-statistics-1\" class=\"section level3\">\n<h3>Summary statistics<\/h3>\n<p>Compute some summary statistics by groups: mean and sd (standard deviation)<\/p>\n<pre class=\"r\"><code>genderweight %&gt;%\r\n  group_by(group) %&gt;%\r\n  get_summary_stats(weight, type = \"mean_sd\")<\/code><\/pre>\n<pre><code>## # A tibble: 2 x 5\r\n##   group variable     n  mean    sd\r\n##   &lt;fct&gt; &lt;chr&gt;    &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;\r\n## 1 F     weight      20  63.5  2.03\r\n## 2 M     weight      20  85.8  4.35<\/code><\/pre>\n<\/div>\n<div id=\"calculation-1\" class=\"section level3\">\n<h3>Calculation<\/h3>\n<p>Recall that, by default, R computes the Welch t-test, which is the safer one. This is the test where you do not assume that the variance is the same in the two groups, which results in the fractional degrees of freedom. If you want to assume the equality of variances (Student t-test), specify the option <code>var.equal = TRUE<\/code>.<\/p>\n<div id=\"using-the-r-base-function-1\" class=\"section level4\">\n<h4>Using the R base function<\/h4>\n<pre class=\"r\"><code>res &lt;- t.test(weight ~ group, data = genderweight)\r\nres<\/code><\/pre>\n<pre><code>## \r\n##  Welch Two Sample t-test\r\n## \r\n## data:  weight by group\r\n## t = -20, df = 30, p-value &lt;2e-16\r\n## alternative hypothesis: true difference in means is not equal to 0\r\n## 95 percent confidence interval:\r\n##  -24.5 -20.1\r\n## sample estimates:\r\n## mean in group F mean in group M \r\n##            63.5            85.8<\/code><\/pre>\n<p>In the result above :<\/p>\n<ul>\n<li><code>t<\/code> is the t-test statistic value (t = -20.79),<\/li>\n<li><code>df<\/code> is the degrees of freedom (df= 26.872),<\/li>\n<li><code>p-value<\/code> is the significance level of the t-test (p-value = 4.29810^{-18}).<\/li>\n<li><code>conf.int<\/code> is the confidence interval of the means difference at 95% (conf.int = [-24.5314, -20.1235]);<\/li>\n<li><code>sample estimates<\/code> is the mean value of the sample (mean = 63.499, 85.826).<\/li>\n<\/ul>\n<\/div>\n<div id=\"using-the-rstatix-package-1\" class=\"section level4\">\n<h4>Using the rstatix package<\/h4>\n<pre class=\"r\"><code>stat.test &lt;- genderweight %&gt;% \r\n  t_test(weight ~ group) %&gt;%\r\n  add_significance()\r\nstat.test<\/code><\/pre>\n<pre><code>## # A tibble: 1 x 9\r\n##   .y.    group1 group2    n1    n2 statistic    df        p p.signif\r\n##   &lt;chr&gt;  &lt;chr&gt;  &lt;chr&gt;  &lt;int&gt; &lt;int&gt;     &lt;dbl&gt; &lt;dbl&gt;    &lt;dbl&gt; &lt;chr&gt;   \r\n## 1 weight F      M         20    20     -20.8  26.9 4.30e-18 ****<\/code><\/pre>\n<p>The results above show the following components:<\/p>\n<ul>\n<li><code>.y.<\/code>: the y variable used in the test.<\/li>\n<li><code>group1,group2<\/code>: the compared groups in the pairwise tests.<\/li>\n<li><code>statistic<\/code>: Test statistic used to compute the p-value.<\/li>\n<li><code>df<\/code>: degrees of freedom.<\/li>\n<li><code>p<\/code>: p-value.<\/li>\n<\/ul>\n<div class=\"warning\">\n<p>Note that, you can obtain a detailed result by specifying the option <code>detailed = TRUE<\/code>.<\/p>\n<\/div>\n<pre class=\"r\"><code>genderweight %&gt;%\r\n  t_test(weight ~ group, detailed = TRUE) %&gt;%\r\n  add_significance()<\/code><\/pre>\n<pre><code>## # A tibble: 1 x 16\r\n##   estimate estimate1 estimate2 .y.    group1 group2    n1    n2 statistic        p    df conf.low conf.high method alternative p.signif\r\n##      &lt;dbl&gt;     &lt;dbl&gt;     &lt;dbl&gt; &lt;chr&gt;  &lt;chr&gt;  &lt;chr&gt;  &lt;int&gt; &lt;int&gt;     &lt;dbl&gt;    &lt;dbl&gt; &lt;dbl&gt;    &lt;dbl&gt;     &lt;dbl&gt; &lt;chr&gt;  &lt;chr&gt;       &lt;chr&gt;   \r\n## 1    -22.3      63.5      85.8 weight F      M         20    20     -20.8 4.30e-18  26.9    -24.5     -20.1 T-test two.sided   ****<\/code><\/pre>\n<\/div>\n<\/div>\n<div id=\"interpretation-1\" class=\"section level3\">\n<h3>Interpretation<\/h3>\n<p>The p-value of the test is 4.310^{-18}, which is less than the significance level alpha = 0.05. We can conclude that men\u2019s average weight is significantly different from women\u2019s average weight with a <strong>p-value<\/strong> = 4.310^{-18}.<\/p>\n<\/div>\n<div id=\"effect-size-1\" class=\"section level3\">\n<h3>Effect size<\/h3>\n<\/div>\n<div id=\"cohens-d-for-student-t-test\" class=\"section level3\">\n<h3>Cohen\u2019s d for Student t-test<\/h3>\n<p>There are multiple version of Cohen\u2019s d for Student t-test. The most commonly used version of the Student t-test effect size, comparing two groups (<span class=\"math inline\">\\(A\\)<\/span> and <span class=\"math inline\">\\(B\\)<\/span>), is calculated by dividing the mean difference between the groups by the pooled standard deviation.<\/p>\n<p><strong>Cohen\u2019s d formula<\/strong>:<\/p>\n<p><span class=\"math display\">\\[<br \/>\nd = \\frac{m_A - m_B}{SD_{pooled}}<br \/>\n\\]<\/span><\/p>\n<p>where,<\/p>\n<ul>\n<li><span class=\"math inline\">\\(m_A\\)<\/span> and <span class=\"math inline\">\\(m_B\\)<\/span> represent the mean value of the group A and B, respectively.<\/li>\n<li><span class=\"math inline\">\\(n_A\\)<\/span> and <span class=\"math inline\">\\(n_B\\)<\/span> represent the sizes of the group A and B, respectively.<\/li>\n<li><span class=\"math inline\">\\(SD_{pooled}\\)<\/span> is an estimator of the pooled standard deviation of the two groups. It can be calculated as follow :<br \/>\n<span class=\"math display\">\\[<br \/>\nSD_{pooled} = \\sqrt{\\frac{\\sum{(x-m_A)^2}+\\sum{(x-m_B)^2}}{n_A+n_B-2}}<br \/>\n\\]<\/span><\/li>\n<\/ul>\n<p><strong>Calculation<\/strong>. If the option <code>var.equal = TRUE<\/code>, then the pooled SD is used when computing the Cohen\u2019s d.<\/p>\n<pre class=\"r\"><code>genderweight %&gt;%  cohens_d(weight ~ group, var.equal = TRUE)<\/code><\/pre>\n<pre><code>## # A tibble: 1 x 7\r\n##   .y.    group1 group2 effsize    n1    n2 magnitude\r\n## * &lt;chr&gt;  &lt;chr&gt;  &lt;chr&gt;    &lt;dbl&gt; &lt;int&gt; &lt;int&gt; &lt;ord&gt;    \r\n## 1 weight F      M        -6.57    20    20 large<\/code><\/pre>\n<div class=\"success\">\n<p>There is a large effect size, d = 6.57.<\/p>\n<\/div>\n<p>Note that, for small sample size (&lt; 50), the Cohen\u2019s d tends to over-inflate results. There exists a <strong>Hedge\u2019s Corrected version of the Cohen\u2019s d<\/strong> <span class=\"citation\">(Hedges and Olkin 1985)<\/span>, which reduces effect sizes for small samples by a few percentage points. The correction is introduced by multiplying the usual value of d by <code>(N-3)\/(N-2.25)<\/code> (for unpaired t-test) and by <code>(n1-2)\/(n1-1.25)<\/code> for paired t-test; where N is the total size of the two groups being compared <code>(N = n1 + n2)<\/code>.<\/p>\n<\/div>\n<div id=\"cohens-d-for-welch-t-test\" class=\"section level3\">\n<h3>Cohen\u2019s d for Welch t-test<\/h3>\n<p>The Welch test is a variant of t-test used when the equality of variance can\u2019t be assumed. The effect size can be computed by dividing the mean difference between the groups by the \u201caveraged\u201d standard deviation.<\/p>\n<p><strong>Cohen\u2019s d formula<\/strong>:<\/p>\n<p><span class=\"math display\">\\[<br \/>\nd = \\frac{m_A - m_B}{\\sqrt{(Var_1 + Var_2)\/2}}<br \/>\n\\]<\/span><\/p>\n<p>where,<\/p>\n<ul>\n<li><span class=\"math inline\">\\(m_A\\)<\/span> and <span class=\"math inline\">\\(m_B\\)<\/span> represent the mean value of the group A and B, respectively.<\/li>\n<li><span class=\"math inline\">\\(Var_1\\)<\/span> and <span class=\"math inline\">\\(Var_2\\)<\/span> are the variance of the two groups.<\/li>\n<\/ul>\n<p><strong>Calculation<\/strong>:<\/p>\n<pre class=\"r\"><code>genderweight %&gt;% cohens_d(weight ~ group, var.equal = FALSE)<\/code><\/pre>\n<pre><code>## # A tibble: 1 x 7\r\n##   .y.    group1 group2 effsize    n1    n2 magnitude\r\n## * &lt;chr&gt;  &lt;chr&gt;  &lt;chr&gt;    &lt;dbl&gt; &lt;int&gt; &lt;int&gt; &lt;ord&gt;    \r\n## 1 weight F      M        -6.57    20    20 large<\/code><\/pre>\n<div class=\"warning\">\n<p>Note that, when group sizes are equal and group variances are homogeneous, Cohen\u2019s d for the standard Student and Welch t-tests are identical.<\/p>\n<\/div>\n<\/div>\n<div id=\"report\" class=\"section level3\">\n<h3>Report<\/h3>\n<p>We could report the result as follow:<\/p>\n<p>The mean weight in female group was 63.5 (SD = 2.03), whereas the mean in male group was 85.8 (SD = 4.3). A Welch two-samples t-test showed that the difference was statistically significant, t(26.9) = -20.8, p &lt; 0.0001, d = 6.57; where, t(26.9) is shorthand notation for a Welch t-statistic that has 26.9 degrees of freedom.<\/p>\n<p>Visualize the results:<\/p>\n<pre class=\"r\"><code># Create a box-plot\r\nbxp &lt;- ggboxplot(\r\n  genderweight, x = \"group\", y = \"weight\", \r\n  ylab = \"Weight\", xlab = \"Groups\", add = \"jitter\"\r\n  )\r\n\r\n# Add p-value and significance levels\r\nstat.test &lt;- stat.test %&gt;% add_xy_position(x = \"group\")\r\nbxp + \r\n  stat_pvalue_manual(stat.test, tip.length = 0) +\r\n  labs(subtitle = get_test_label(stat.test, detailed = TRUE))<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/r-statistics-2-comparing-groups-means\/figures\/084-how-to-do-a-t-test-in-r-two-sample-box-plot-with-p-values-1.png\" width=\"412.8\" \/><\/p>\n<\/div>\n<\/div>\n<div id=\"paired-t-test\" class=\"section level2\">\n<h2>Paired t-test<\/h2>\n<div id=\"demo-data-2\" class=\"section level3\">\n<h3>Demo data<\/h3>\n<p>Here, we\u2019ll use a demo dataset <code>mice2<\/code> [datarium package], which contains the weight of 10 mice before and after the treatment.<\/p>\n<pre class=\"r\"><code># Wide format\r\ndata(\"mice2\", package = \"datarium\")\r\nhead(mice2, 3)<\/code><\/pre>\n<pre><code>##   id before after\r\n## 1  1    187   430\r\n## 2  2    194   404\r\n## 3  3    232   406<\/code><\/pre>\n<pre class=\"r\"><code># Transform into long data: \r\n# gather the before and after values in the same column\r\nmice2.long &lt;- mice2 %&gt;%\r\n  gather(key = \"group\", value = \"weight\", before, after)\r\nhead(mice2.long, 3)<\/code><\/pre>\n<pre><code>##   id  group weight\r\n## 1  1 before    187\r\n## 2  2 before    194\r\n## 3  3 before    232<\/code><\/pre>\n<div class=\"block\">\n<p>We want to know, if there is any significant difference in the mean weights after treatment?<\/p>\n<\/div>\n<\/div>\n<div id=\"summary-statistics-2\" class=\"section level3\">\n<h3>Summary statistics<\/h3>\n<p>Compute some summary statistics (mean and sd) by groups:<\/p>\n<pre class=\"r\"><code>mice2.long %&gt;%\r\n  group_by(group) %&gt;%\r\n  get_summary_stats(weight, type = \"mean_sd\")<\/code><\/pre>\n<pre><code>## # A tibble: 2 x 5\r\n##   group  variable     n  mean    sd\r\n##   &lt;chr&gt;  &lt;chr&gt;    &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;\r\n## 1 after  weight      10  400.  30.1\r\n## 2 before weight      10  201.  20.0<\/code><\/pre>\n<\/div>\n<div id=\"calculation-2\" class=\"section level3\">\n<h3>Calculation<\/h3>\n<div id=\"using-the-r-base-function-2\" class=\"section level4\">\n<h4>Using the R base function<\/h4>\n<pre class=\"r\"><code>res &lt;- t.test(weight ~ group, data = mice2.long, paired = TRUE)\r\nres<\/code><\/pre>\n<p>In the result above :<\/p>\n<ul>\n<li><code>t<\/code> is the t-test statistic value (t = -20.79),<\/li>\n<li><code>df<\/code> is the degrees of freedom (df= 26.872),<\/li>\n<li><code>p-value<\/code> is the significance level of the t-test (p-value = 4.29810^{-18}).<\/li>\n<li><code>conf.int<\/code> is the confidence interval of the mean of the differences at 95% (conf.int = [-24.5314, -20.1235]);<\/li>\n<li><code>sample estimates<\/code> is the mean of the differences (mean = 63.499, 85.826).<\/li>\n<\/ul>\n<\/div>\n<div id=\"using-the-rstatix-package-2\" class=\"section level4\">\n<h4>Using the rstatix package<\/h4>\n<pre class=\"r\"><code>stat.test &lt;- mice2.long  %&gt;% \r\n  t_test(weight ~ group, paired = TRUE) %&gt;%\r\n  add_significance()\r\nstat.test<\/code><\/pre>\n<pre><code>## # A tibble: 1 x 9\r\n##   .y.    group1 group2    n1    n2 statistic    df             p p.signif\r\n##   &lt;chr&gt;  &lt;chr&gt;  &lt;chr&gt;  &lt;int&gt; &lt;int&gt;     &lt;dbl&gt; &lt;dbl&gt;         &lt;dbl&gt; &lt;chr&gt;   \r\n## 1 weight after  before    10    10      25.5     9 0.00000000104 ****<\/code><\/pre>\n<p>The results above show the following components:<\/p>\n<ul>\n<li><code>.y.<\/code>: the y variable used in the test.<\/li>\n<li><code>group1,group2<\/code>: the compared groups in the pairwise tests.<\/li>\n<li><code>statistic<\/code>: Test statistic used to compute the p-value.<\/li>\n<li><code>df<\/code>: degrees of freedom.<\/li>\n<li><code>p<\/code>: p-value.<\/li>\n<\/ul>\n<div class=\"warning\">\n<p>Note that, you can obtain a detailed result by specifying the option <code>detailed = TRUE<\/code>.<\/p>\n<\/div>\n<pre class=\"r\"><code>mice2.long %&gt;%\r\n  t_test(weight ~ group, paired = TRUE, detailed = TRUE) %&gt;%\r\n  add_significance()<\/code><\/pre>\n<pre><code>## # A tibble: 1 x 14\r\n##   estimate .y.    group1 group2    n1    n2 statistic             p    df conf.low conf.high method alternative p.signif\r\n##      &lt;dbl&gt; &lt;chr&gt;  &lt;chr&gt;  &lt;chr&gt;  &lt;int&gt; &lt;int&gt;     &lt;dbl&gt;         &lt;dbl&gt; &lt;dbl&gt;    &lt;dbl&gt;     &lt;dbl&gt; &lt;chr&gt;  &lt;chr&gt;       &lt;chr&gt;   \r\n## 1     199. weight after  before    10    10      25.5 0.00000000104     9     182.      217. T-test two.sided   ****<\/code><\/pre>\n<\/div>\n<\/div>\n<div id=\"interpretation-2\" class=\"section level3\">\n<h3>Interpretation<\/h3>\n<p>The p-value of the test is 1.0410^{-9}, which is less than the significance level alpha = 0.05. We can then reject null hypothesis and conclude that the average weight of the mice before treatment is significantly different from the average weight after treatment with a <strong>p-value<\/strong> = 1.0410^{-9}.<\/p>\n<\/div>\n<div id=\"effect-size-2\" class=\"section level3\">\n<h3>Effect size<\/h3>\n<p>The effect size for a paired-samples t-test can be calculated by dividing the mean difference by the standard deviation of the difference, as shown below.<\/p>\n<p><strong>Cohen\u2019s d formula<\/strong>:<\/p>\n<p><span class=\"math display\">\\[<br \/>\nd = \\frac{mean_D}{SD_D}<br \/>\n\\]<\/span><\/p>\n<p>Where <code>D<\/code> is the differences of the paired samples values.<\/p>\n<p><strong>Calculation<\/strong>:<\/p>\n<pre class=\"r\"><code>mice2.long  %&gt;% cohens_d(weight ~ group, paired = TRUE)<\/code><\/pre>\n<pre><code>## # A tibble: 1 x 7\r\n##   .y.    group1 group2 effsize    n1    n2 magnitude\r\n## * &lt;chr&gt;  &lt;chr&gt;  &lt;chr&gt;    &lt;dbl&gt; &lt;int&gt; &lt;int&gt; &lt;ord&gt;    \r\n## 1 weight after  before    8.08    10    10 large<\/code><\/pre>\n<div class=\"success\">\n<p>There is a large effect size, Cohen\u2019s d = 8.07.<\/p>\n<\/div>\n<\/div>\n<div id=\"report-1\" class=\"section level3\">\n<h3>Report<\/h3>\n<p>We could report the result as follow: The average weight of mice was significantly increased after treatment, t(9) = 25.5, p &lt; 0.0001, d = 8.07.<\/p>\n<p>Visualize the results:<\/p>\n<pre class=\"r\"><code># Create a box plot\r\nbxp &lt;- ggpaired(mice2.long, x = \"group\", y = \"weight\", \r\n         order = c(\"before\", \"after\"),\r\n         ylab = \"Weight\", xlab = \"Groups\")\r\n\r\n# Add p-value and significance levels\r\nstat.test &lt;- stat.test %&gt;% add_xy_position(x = \"group\")\r\nbxp + \r\n  stat_pvalue_manual(stat.test, tip.length = 0) +\r\n  labs(subtitle = get_test_label(stat.test, detailed= TRUE))<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/r-statistics-2-comparing-groups-means\/figures\/084-how-to-do-a-t-test-in-r-paired-t-test-box-plot-with-p-values-1.png\" width=\"364.8\" \/><\/p>\n<\/div>\n<\/div>\n<div id=\"summary\" class=\"section level2\">\n<h2>Summary<\/h2>\n<p>This article shows how to conduct a t-test in R\/Rstudio using two different ways: the R base function <code>t.test()<\/code> and the <code>t_test()<\/code> function in the rstatix package. We also describe how to interpret and report the t-test results.<\/p>\n<\/div>\n<div id=\"references\" class=\"section level2 unnumbered\">\n<h2>References<\/h2>\n<div id=\"refs\" class=\"references\">\n<div id=\"ref-cohen1998\">\n<p>Cohen, J. 1998. <em>Statistical Power Analysis for the Behavioral Sciences<\/em>. 2nd ed. Hillsdale, NJ: Lawrence Erlbaum Associates.<\/p>\n<\/div>\n<div id=\"ref-hedges1985\">\n<p>Hedges, Larry, and Ingram Olkin. 1985. \u201cStatistical Methods in Meta-Analysis.\u201d In <em>Stat Med<\/em>. Vol. 20. doi:<a href=\"https:\/\/doi.org\/10.2307\/1164953\">10.2307\/1164953<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><!--end rdoc--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Describes how to do a t-test in R\/Rstudio. You will learn how to 1) interpret and report the t-test; 2) add p-values and significance levels to a plot and 3) calculate and report the t-test effect size.<\/p>\n","protected":false},"author":1,"featured_media":8927,"parent":0,"menu_order":84,"comment_status":"open","ping_status":"closed","template":"","class_list":["post-11693","dt_lessons","type-dt_lessons","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Do a T-test in R: Calculation and Reporting - Best Ref - Datanovia<\/title>\n<meta name=\"description\" content=\"Describes how to do a t-test in R\/Rstudio. You will learn how to 1) interpret and report the t-test; 2) add p-values and significance levels to a plot and 3) calculate and report the t-test effect size.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Do a T-test in R: Calculation and Reporting - Best Ref - Datanovia\" \/>\n<meta property=\"og:description\" content=\"Describes how to do a t-test in R\/Rstudio. You will learn how to 1) interpret and report the t-test; 2) add p-values and significance levels to a plot and 3) calculate and report the t-test effect size.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/\" \/>\n<meta property=\"og:site_name\" content=\"Datanovia\" \/>\n<meta property=\"article:modified_time\" content=\"2019-12-26T08:26:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/X50589436_796126424060637_4634267315792248832_n.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/\",\"url\":\"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/\",\"name\":\"How to Do a T-test in R: Calculation and Reporting - Best Ref - Datanovia\",\"isPartOf\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/X50589436_796126424060637_4634267315792248832_n.jpg\",\"datePublished\":\"2019-12-26T08:23:34+00:00\",\"dateModified\":\"2019-12-26T08:26:35+00:00\",\"description\":\"Describes how to do a t-test in R\/Rstudio. You will learn how to 1) interpret and report the t-test; 2) add p-values and significance levels to a plot and 3) calculate and report the t-test effect size.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/#primaryimage\",\"url\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/X50589436_796126424060637_4634267315792248832_n.jpg\",\"contentUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/X50589436_796126424060637_4634267315792248832_n.jpg\",\"width\":1024,\"height\":512},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.datanovia.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Lessons\",\"item\":\"https:\/\/www.datanovia.com\/en\/lessons\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Do a T-test in R: Calculation and Reporting\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#website\",\"url\":\"https:\/\/www.datanovia.com\/en\/\",\"name\":\"Datanovia\",\"description\":\"Data Mining and Statistics for Decision Support\",\"publisher\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.datanovia.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#organization\",\"name\":\"Datanovia\",\"url\":\"https:\/\/www.datanovia.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png\",\"contentUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png\",\"width\":98,\"height\":99,\"caption\":\"Datanovia\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Do a T-test in R: Calculation and Reporting - Best Ref - Datanovia","description":"Describes how to do a t-test in R\/Rstudio. You will learn how to 1) interpret and report the t-test; 2) add p-values and significance levels to a plot and 3) calculate and report the t-test effect size.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/","og_locale":"en_US","og_type":"article","og_title":"How to Do a T-test in R: Calculation and Reporting - Best Ref - Datanovia","og_description":"Describes how to do a t-test in R\/Rstudio. You will learn how to 1) interpret and report the t-test; 2) add p-values and significance levels to a plot and 3) calculate and report the t-test effect size.","og_url":"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/","og_site_name":"Datanovia","article_modified_time":"2019-12-26T08:26:35+00:00","og_image":[{"width":1024,"height":512,"url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/X50589436_796126424060637_4634267315792248832_n.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/","url":"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/","name":"How to Do a T-test in R: Calculation and Reporting - Best Ref - Datanovia","isPartOf":{"@id":"https:\/\/www.datanovia.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/#primaryimage"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/#primaryimage"},"thumbnailUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/X50589436_796126424060637_4634267315792248832_n.jpg","datePublished":"2019-12-26T08:23:34+00:00","dateModified":"2019-12-26T08:26:35+00:00","description":"Describes how to do a t-test in R\/Rstudio. You will learn how to 1) interpret and report the t-test; 2) add p-values and significance levels to a plot and 3) calculate and report the t-test effect size.","breadcrumb":{"@id":"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/#primaryimage","url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/X50589436_796126424060637_4634267315792248832_n.jpg","contentUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/X50589436_796126424060637_4634267315792248832_n.jpg","width":1024,"height":512},{"@type":"BreadcrumbList","@id":"https:\/\/www.datanovia.com\/en\/lessons\/how-to-do-a-t-test-in-r-calculation-and-reporting\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.datanovia.com\/en\/"},{"@type":"ListItem","position":2,"name":"Lessons","item":"https:\/\/www.datanovia.com\/en\/lessons\/"},{"@type":"ListItem","position":3,"name":"How to Do a T-test in R: Calculation and Reporting"}]},{"@type":"WebSite","@id":"https:\/\/www.datanovia.com\/en\/#website","url":"https:\/\/www.datanovia.com\/en\/","name":"Datanovia","description":"Data Mining and Statistics for Decision Support","publisher":{"@id":"https:\/\/www.datanovia.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.datanovia.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.datanovia.com\/en\/#organization","name":"Datanovia","url":"https:\/\/www.datanovia.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png","contentUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png","width":98,"height":99,"caption":"Datanovia"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/"}}]}},"multi-rating":{"mr_rating_results":[]},"_links":{"self":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons\/11693","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons"}],"about":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/types\/dt_lessons"}],"author":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/comments?post=11693"}],"version-history":[{"count":0,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons\/11693\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media\/8927"}],"wp:attachment":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media?parent=11693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}