

{"id":4913,"date":"2017-12-02T12:35:57","date_gmt":"2017-12-02T07:05:57","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=4913"},"modified":"2021-08-25T17:26:23","modified_gmt":"2021-08-25T11:56:23","slug":"t-tests-in-r","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/t-tests-in-r\/","title":{"rendered":"T-tests in R &#8211; Learn to perform &amp; use it today itself!"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:1463,&quot;href&quot;:&quot;https:\\\/\\\/www.r-project.org\\\/about.html&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251001184431\\\/https:\\\/\\\/www.r-project.org\\\/about.html&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-09 07:45:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-13 16:47:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-17 00:44:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-20 07:22:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-24 11:16:29&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2025-12-27 15:20:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-03 17:17:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-07 10:13:13&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-10 21:41:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-15 04:43:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-19 10:33:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-23 04:45:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-26 07:29:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-29 17:22:16&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-02 13:19:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-06 04:11:53&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-10 17:03:32&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-02-14 06:52:53&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-17 15:21:44&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-02-21 02:00:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-24 08:01:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-27 12:29:53&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 14:58:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-05 20:44:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-10 04:28:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-13 05:33:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-16 05:53:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-21 02:54:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-24 07:39:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 15:59:49&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-01 09:45:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-05 15:11:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-09 04:11:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-12 14:44:40&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-16 05:31:41&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-19 11:55:27&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-23 03:08:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-26 07:10:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-29 16:46:00&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-02 19:54:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-06 20:30:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-10 10:01:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-14 12:31:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-17 21:24:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-21 13:32:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-24 18:37:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-28 04:36:06&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-06-01 14:14:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-04 20:45:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-08 04:11:15&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-08 04:11:15&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>In this tutorial, we are going to learn what is T-tests in R. Along with this, we will learn how to perform T-tests in R and its various uses. Also, we will look at various types of T-test in R like one sample and Welch T-test etc.<\/p>\n<p>So, let&#8217;s start the tutorial.<\/p>\n<h2>What is T-tests in R Programming?<\/h2>\n<p>T-tests in R is one of the most common tests in statistics. So, we use it to determine whether the means of two groups are equal to each other. The assumption for the test is that both groups are sampled from normal distributions with equal variances. The null hypothesis is that the two means are equal, and the alternative is that they are not equal. It is known that under the null hypothesis, we can calculate a t-statistic that will follow a t-distribution with <strong>n1 + n2 &#8211; 2 degrees of freedom<\/strong>.<\/p>\n<p>Welch\u2019s T-test is a user modification of the T-test that adjusts the number of degrees of freedom when the variances are thought not to be equal to each other.<\/p>\n<p>We use t.test() which provides a variety of T-tests:<br \/>\n<b><\/b><\/p>\n<p><b># independent 2-group T-test<\/b><br \/>\n<span style=\"font-weight: 400\">t.test(y~x) # where y is numeric and x is a binary factor<\/span><br \/>\n<b><\/b><\/p>\n<p><b># independent 2-group T-test<\/b><br \/>\n<span style=\"font-weight: 400\">t.test(y1,y2) # where y1 and y2 are numeric<\/span><br \/>\n<b><\/b><\/p>\n<p><b># paired T-test<\/b><br \/>\n<span style=\"font-weight: 400\">t.test(y1,y2,paired=TRUE) # where y1 &amp; y2 are numeric<\/span><br \/>\n<b><\/b><\/p>\n<p><b># one sample T-test<\/b><br \/>\n<span style=\"font-weight: 400\">t.test(y,mu=3) # Ho: mu=3<\/span><\/p>\n<p><strong>Understand everything about the <a href=\"https:\/\/data-flair.training\/blogs\/r-factor-functions\/\">R Factor Functions<\/a><\/strong><\/p>\n<h3>How to Perform T-tests in R?<\/h3>\n<p>We can use the var.equal = TRUE option to specify equal variances and a pooled variance estimate.<\/p>\n<p><span style=\"font-weight: 400\">You can use them:<\/span><\/p>\n<p><span style=\"font-weight: 400\">alternative=&#8221;less&#8221; or<\/span><br \/>\n<span style=\"font-weight: 400\">alternative=&#8221;greater&#8221;, option to specify one-tailed test.<\/span><\/p>\n<h4>1. One-Sample<\/h4>\n<p><span style=\"font-weight: 400\">In R, we use the syntax <\/span><b>t.test(y, mu = 0) <\/b><span style=\"font-weight: 400\">to conduct one-sample tests in R, where<\/span><\/p>\n<ul>\n<li><strong>x:<\/strong> \u00a0is the name of our variable of interest and<\/li>\n<li><span style=\"font-weight: 400\"><strong>mu:<\/strong>\u00a0mu, which is described by the null hypothesis is set equal to the mean. <\/span><br \/>\n<b><\/b><\/li>\n<\/ul>\n<p><b>For example<\/b><span style=\"font-weight: 400\">:<\/span><\/p>\n<p><span style=\"font-weight: 400\">If we wanted to test whether the volume of a shipment of lumber was less than usual (<\/span><i><span style=\"font-weight: 400\">\u03bc<\/span><\/i><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">=37000 cubic<\/span><span style=\"font-weight: 400\"> feet), we would run:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">set.seed(0)\r\nship_vol\u00a0&lt;-\u00a0c(rnorm(75,\u00a0mean\u00a0=\u00a037000,\u00a0sd\u00a0=\u00a02500))\r\nt.test(ship_vol,\u00a0mu\u00a0=\u00a039000)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-Sample-T-Tests-in-R.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-60264\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-Sample-T-Tests-in-R.jpg\" alt=\"One-Sample T-Tests in R\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-Sample-T-Tests-in-R.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-Sample-T-Tests-in-R-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-Sample-T-Tests-in-R-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-Sample-T-Tests-in-R-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-Sample-T-Tests-in-R-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/One-Sample-T-Tests-in-R-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><em><strong>Wait! Have you checked &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/survival-analysis-in-r\/\">Survival Analysis in R Programming<\/a><\/strong><\/em><\/p>\n<h4>2. Paired Sample<\/h4>\n<p><span style=\"font-weight: 400\">We need either of the two vectors of data, y1 and y2, to conduct a paired-samples test. Then, we will run this code using this using <\/span>syntax<b> t.test(y1, y2, paired=TRUE).<\/b><\/p>\n<p>For instance, let\u2019s say that we work at a large health clinic and we are testing a new drug, Procardia, whose work is to reduce hypertension. We find 13000 individuals with high systolic blood pressure (x\u00af=150 mmHg, SD=10 mmHg) and we provide them Procardia for a month, and then measure their blood pressure again. We find that the mean systolic blood pressure has decreased to 144 mmHg with a standard deviation of 9 mmHg.<br \/>\n<b><\/b><\/p>\n<p><b>Here, we would conduct a T-test using<\/b><span style=\"font-weight: 400\">:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#Author\u00a0DataFlair\r\nset.seed(2820)\r\npre_Treatment\u00a0&lt;-\u00a0c(rnorm(2000,\u00a0mean\u00a0=\u00a0150,\u00a0sd\u00a0=\u00a010))\r\npost_Treatment\u00a0&lt;-\u00a0c(rnorm(2000,\u00a0mean\u00a0=\u00a0144,\u00a0sd\u00a0=\u00a09))\r\nt.test(pre_Treatment,\u00a0post_Treatment,\u00a0paired\u00a0=\u00a0TRUE)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Paired-sample-T-Tests-in-R.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-60265\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Paired-sample-T-Tests-in-R.jpg\" alt=\"Paired sample T-Tests in R\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Paired-sample-T-Tests-in-R.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Paired-sample-T-Tests-in-R-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Paired-sample-T-Tests-in-R-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Paired-sample-T-Tests-in-R-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Paired-sample-T-Tests-in-R-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Paired-sample-T-Tests-in-R-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400\">Again, we see that there is a statistically significant difference in means of:<\/span><\/p>\n<p>t = 20.789, p-value &lt; 2.2e-16<\/p>\n<p><em><strong>Don&#8217;t forget to check the <a href=\"https:\/\/data-flair.training\/blogs\/r-predictive-and-descriptive-analytics\/\">Predictive and Descriptive Analysis in R<\/a><\/strong><\/em><\/p>\n<h4>3. Independent Samples<\/h4>\n<p>The independent-samples test can take one of three forms, depending on the structure of your data and the equality of their variances. The general form of the test is <strong>t.test(y1, y2, paired=FALSE)<\/strong>. By default, R assumes that the variances of y1 and y2 are unequal, thus defaulting to Welch&#8217;s test. To toggle this, we use the flag, <strong>var.equal=TRUE<\/strong>.<\/p>\n<p>In the three examples shown here, we\u2019ll test the hypothesis in which Clevelanders and New Yorkers spend different amounts for eating outside on a monthly basis.<br \/>\n<b><\/b><\/p>\n<p><b>Independent-samples T-test where y1 and y2 are numeric<\/b><span style=\"font-weight: 400\">:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#Author\u00a0DataFlair\r\nset.seed(0)\r\nSpenders_Cleve\u00a0&lt;-\u00a0rnorm(60,\u00a0mean\u00a0=\u00a0350,\u00a0sd\u00a0=\u00a077)\r\nSpenders_NY\u00a0&lt;-\u00a0rnorm(60,\u00a0mean\u00a0=\u00a0400,\u00a0sd\u00a0=\u00a080)\r\nt.test(Spenders_Cleve,\u00a0Spenders_NY,\u00a0var.equal\u00a0=\u00a0TRUE)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Independent-Samples.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-60278 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Independent-Samples.jpg\" alt=\"Independent Samples - y1 and y2 are numeric\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Independent-Samples.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Independent-Samples-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Independent-Samples-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Independent-Samples-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Independent-Samples-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Independent-Samples-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><b>Where y1 is numeric and y2 is binary<\/b><span style=\"font-weight: 400\">:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#Author\u00a0DataFlair\r\nAmount_Spent\u00a0&lt;-\u00a0c(Spenders_Cleve,\u00a0Spenders_NY)\r\ncity_name\u00a0&lt;-\u00a0c(rep(\"Cleveland\",\u00a060),\u00a0rep(\"New\u00a0York\",\u00a060))\r\nt.test(Amount_Spent\u00a0~\u00a0city_name,\u00a0var.equal\u00a0=\u00a0TRUE)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Where-y1-is-numeric-and-y2-is-binary.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-60279\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Where-y1-is-numeric-and-y2-is-binary.jpg\" alt=\"Where y1 is numeric and y2 is binary\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Where-y1-is-numeric-and-y2-is-binary.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Where-y1-is-numeric-and-y2-is-binary-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Where-y1-is-numeric-and-y2-is-binary-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Where-y1-is-numeric-and-y2-is-binary-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Where-y1-is-numeric-and-y2-is-binary-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Where-y1-is-numeric-and-y2-is-binary-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><b>With equal variances not assumed<\/b><span style=\"font-weight: 400\">:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#Author DataFlair\r\nt.test(Spenders_Cleve,\u00a0Spenders_NY,\u00a0var.equal\u00a0=\u00a0FALSE)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/With-equal-variances-not-assumed.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-60280\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/With-equal-variances-not-assumed.jpg\" alt=\"With equal variances not assumed\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/With-equal-variances-not-assumed.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/With-equal-variances-not-assumed-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/With-equal-variances-not-assumed-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/With-equal-variances-not-assumed-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/With-equal-variances-not-assumed-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/With-equal-variances-not-assumed-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400\">In each case, we see that the results really don\u2019t differ substantially: our simulated data show that in any case, New Yorkers spend more amount each month at restaurants than Clevelanders do. However, if you want to test for equality of variances in your data prior to running an independent-samples T-test, <a href=\"https:\/\/www.r-project.org\/about.html\">R<\/a> offers an easy way to do so with the var.test() function:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">var.test(Spenders_Cleve,\u00a0Spenders_NY)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/var-test.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-60281\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/var-test.jpg\" alt=\"var.test\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/var-test.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/var-test-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/var-test-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/var-test-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/var-test-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/var-test-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><em><strong>Do you know &#8211; How to <a href=\"https:\/\/data-flair.training\/blogs\/importing-data-in-r\/\">Import Data in R<\/a><\/strong><\/em><\/p>\n<h3>Reasons behind Using T-tests in R<\/h3>\n<h4>1. Why we use a T-test in R?<\/h4>\n<p><span style=\"font-weight: 400\">It is an analysis of two populations which means a use of statistical examination. It is a type of T-test with two samples being used with small sample sizes. And, testing the difference between the samples when the variances of two normal distributions are not known.<\/span><\/p>\n<h4>2. What is Welch&#8217;s T-test used for?<\/h4>\n<p><span style=\"font-weight: 400\">In statistics, we use Welch&#8217;s T-test, which is a two-sample location test. We use it to test the hypothesis such that the two populations have equal means. Welch&#8217;s test, which is an adaptation of Student&#8217;s T-test is much more robust than the latter. It is more reliable when the two samples have unequal variances and unequal sample sizes.<\/span><\/p>\n<h4>3. Why we use One-Sample T-test?<\/h4>\n<p><span style=\"font-weight: 400\">We use it only for tests of the sample mean.<\/span><\/p>\n<h4>4. Why do we use the T-test for research?<\/h4>\n<p><span style=\"font-weight: 400\">We use PowerPoint on T-tests which is made for our use. The T-test is one type of inferential statistics. We use it to determine whether there is a \u00a0difference between the means of two groups. With the implementation of inferential statistics, we assume the dependent variable fits the normal distribution.<\/span><\/p>\n<h2>Summary<\/h2>\n<p>We have learned about the concept of T-tests in R. We have discussed how to perform different T-tests in R along with its different uses in R. Hope you understood the independent T-test, paired sample T-test, and one sample T-tests in R.<\/p>\n<p><em><strong>Now, the next tutorial for you &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/anova-in-r\/\">ANOVA in R &#8211; Common Statistical ANOVA Models<\/a><\/strong><\/em><\/p>\n<p>Still, if you have any queries regarding the tutorial, ask in the comment section.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we are going to learn what is T-tests in R. Along with this, we will learn how to perform T-tests in R and its various uses. Also, we will look at&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":60282,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[20271,14131,20270],"class_list":["post-4913","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-perform-t-tests-in-r","tag-t-tests-in-r","tag-t-tests-in-r-uses"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>T-tests in R - Learn to perform &amp; use it today itself! - DataFlair<\/title>\n<meta name=\"description\" content=\"Explore the T-tests in R concept &amp; learn to perform it with various methods; one sample, paired sample and independent samples T-test along with its uses.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/t-tests-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"T-tests in R - Learn to perform &amp; use it today itself! - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Explore the T-tests in R concept &amp; learn to perform it with various methods; one sample, paired sample and independent samples T-test along with its uses.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/t-tests-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-02T07:05:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-25T11:56:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/T-tests-in-R.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"T-tests in R - Learn to perform &amp; use it today itself! - DataFlair","description":"Explore the T-tests in R concept & learn to perform it with various methods; one sample, paired sample and independent samples T-test along with its uses.","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:\/\/data-flair.training\/blogs\/t-tests-in-r\/","og_locale":"en_US","og_type":"article","og_title":"T-tests in R - Learn to perform &amp; use it today itself! - DataFlair","og_description":"Explore the T-tests in R concept & learn to perform it with various methods; one sample, paired sample and independent samples T-test along with its uses.","og_url":"https:\/\/data-flair.training\/blogs\/t-tests-in-r\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2017-12-02T07:05:57+00:00","article_modified_time":"2021-08-25T11:56:23+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/T-tests-in-R.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/t-tests-in-r\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/t-tests-in-r\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"T-tests in R &#8211; Learn to perform &amp; use it today itself!","datePublished":"2017-12-02T07:05:57+00:00","dateModified":"2021-08-25T11:56:23+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/t-tests-in-r\/"},"wordCount":985,"commentCount":3,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/t-tests-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/T-tests-in-R.jpg","keywords":["Perform T-tests in R","t-tests in R","T-tests in R Uses"],"articleSection":["R Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/t-tests-in-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/t-tests-in-r\/","url":"https:\/\/data-flair.training\/blogs\/t-tests-in-r\/","name":"T-tests in R - Learn to perform &amp; use it today itself! - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/t-tests-in-r\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/t-tests-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/T-tests-in-R.jpg","datePublished":"2017-12-02T07:05:57+00:00","dateModified":"2021-08-25T11:56:23+00:00","description":"Explore the T-tests in R concept & learn to perform it with various methods; one sample, paired sample and independent samples T-test along with its uses.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/t-tests-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/t-tests-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/t-tests-in-r\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/T-tests-in-R.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/T-tests-in-R.jpg","width":802,"height":420,"caption":"T tests in R"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/t-tests-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"R Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/r\/"},{"@type":"ListItem","position":3,"name":"T-tests in R &#8211; Learn to perform &amp; use it today itself!"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4913","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=4913"}],"version-history":[{"count":10,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4913\/revisions"}],"predecessor-version":[{"id":60286,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4913\/revisions\/60286"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/60282"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=4913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=4913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=4913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}