{"id":3471,"date":"2026-03-01T20:31:39","date_gmt":"2026-03-01T19:31:39","guid":{"rendered":"https:\/\/www.gironi.it\/blog\/?p=3471"},"modified":"2026-07-17T08:47:25","modified_gmt":"2026-07-17T07:47:25","slug":"the-t-distribution-and-hypothesis-testing","status":"publish","type":"post","link":"https:\/\/www.gironi.it\/blog\/en\/the-t-distribution-and-hypothesis-testing\/","title":{"rendered":"T-Test with R examples for SEO: comparing CTR, conversions and metrics"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In the <a href=\"\/blog\/en\/hypothesis-testing\/\">article on hypothesis testing<\/a> we saw how to check whether a sample mean is compatible with a hypothesis about the population. In the examples we proposed, however, we knew the population standard deviation, <strong>sigma<\/strong> \u2014 which allowed us to use the <strong>normal distribution<\/strong> and the <strong>Z-score<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In practice this is a rather rare case. If we do not know the population sigma, or if <strong>we are working with small samples<\/strong>, we need a different distribution: the <strong>t distribution<\/strong>, or <strong>Student&#8217;s distribution<\/strong>.<\/p>\n\n\n\n<!--more-->\n\n\n\n<div class=\"wp-block-group has-background\" style=\"background-color:#f5f7f9;margin-top:2.5rem;margin-bottom:2.5rem;padding-top:1.5rem;padding-right:1.5rem;padding-bottom:1.5rem;padding-left:1.5rem\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p><strong>Student&#8217;s t distribution is a probability distribution used to assess the statistical significance of results when the sample is small and the population variance is unknown.<\/strong><\/p>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"history\">A Brief Historical Digression<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"360\" height=\"464\" class=\"wp-image-1369\" src=\"https:\/\/www.gironi.it\/blog\/wp-content\/uploads\/2019\/11\/William_Sealy_Gosset.jpg\" alt=\"William Sealy Gosset (Student)\" srcset=\"https:\/\/www.gironi.it\/blog\/wp-content\/uploads\/2019\/11\/William_Sealy_Gosset.jpg 360w, https:\/\/www.gironi.it\/blog\/wp-content\/uploads\/2019\/11\/William_Sealy_Gosset-233x300.jpg 233w\" sizes=\"auto, (max-width: 360px) 85vw, 360px\" \/><figcaption class=\"wp-element-caption\">William Sealy Gosset (Student)<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In the early 1900s, the chemist and statistician William Sealy Gosset, employed at the Guinness brewery (and a collaborator of Karl Pearson), discovered that when working with very small samples, the distributions of the mean differed significantly from the normal. As the sample size changed, the shape of the distribution changed too \u2014 and as the sample grew, it gradually approximated the normal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Unable to reveal his identity so as not to benefit competitors, he published under the pseudonym &#8220;Student&#8221;. This is why distributions for small samples are now known as <strong>Student&#8217;s t distributions<\/strong>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">The t distribution is symmetric about zero, but it is &#8220;flatter&#8221; than the standardised normal: a greater portion of its area lies in the tails.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>A larger sample causes the t distribution to approximate the normal ever more closely. The differences are greatest when we have few degrees of freedom.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"975\" height=\"600\" class=\"wp-image-4012\" src=\"https:\/\/www.gironi.it\/blog\/wp-content\/uploads\/2026\/07\/t-student-confronto-en.png\" alt=\"Student's t distributions for several degrees of freedom, compared with the normal (dashed). With few degrees of freedom the tails are heavier; by df = 30 the t is almost indistinguishable from the normal.\" srcset=\"https:\/\/www.gironi.it\/blog\/wp-content\/uploads\/2026\/07\/t-student-confronto-en.png 975w, https:\/\/www.gironi.it\/blog\/wp-content\/uploads\/2026\/07\/t-student-confronto-en-300x185.png 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption class=\"wp-element-caption\">Student&#8217;s t distributions for several degrees of freedom, compared with the normal (dashed). With few degrees of freedom the tails are heavier; by df = 30 the t is almost indistinguishable from the normal.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">What do we mean by <strong>degrees of freedom<\/strong>? The number of sample values that have the &#8220;freedom&#8221; to vary without changing the sample mean. In practice, for a one-sample test:<\/p>\n\n\n\n\\( df = n &#8211; 1 \\\\ \\)\n\n\n\n<p class=\"wp-block-paragraph\">where n is the sample size.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The procedure for hypothesis testing with the t distribution largely mirrors what we saw with the normal. <strong>We state the null hypothesis H\u2080 and the alternative hypothesis H\u2090<\/strong>, then compute the test statistic:<\/p>\n\n\n\n\\( t = \\frac{\\bar{x} &#8211; \\mu}{\\frac{s}{\\sqrt{n}}} \\\\ \\)\n\n\n\n<p class=\"wp-block-paragraph\">where \\( \\frac{s}{\\sqrt{n}} \\) is the <strong>estimated standard error<\/strong> (also denoted SE).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example\">An Example Is Worth a Thousand Explanations<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A light bulb manufacturer claims that its product has a mean lifespan of at least 4200 hours. We take a sample of n = 10 bulbs and find a sample mean of 4000 hours, with a sample standard deviation of 200 hours.<\/p>\n\n\n\n\\( n = 10 \\quad \\bar{x} = 4000 \\quad s = 200 \\\\ \\)\n\n\n\n<p class=\"wp-block-paragraph\">We set up the test:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\\( H_0 : \\mu \\ge 4200 \\qquad H_a : \\mu &lt; 4200 \\)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We choose a <strong>significance level \u03b1 = 0.05<\/strong> (corresponding to a 95% confidence level). In the t distribution critical value table, we look up the value for 9 degrees of freedom and \u03b1 = 0.05 (one-tailed). <strong>The critical value is 1.833.<\/strong> We will reject H\u2080 if the computed t is less than \u22121.833.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The standard error:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\\[ SE = \\frac{s}{\\sqrt{n}} = \\frac{200}{\\sqrt{10}} = 63.3 \\]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And the t value:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\\[ t = \\frac{\\bar{x} &#8211; \\mu}{SE} = \\frac{4000 &#8211; 4200}{63.3} = -3.16 \\]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>t value falls in the critical region<\/strong>: we reject H\u2080. There is sufficient statistical evidence to conclude that the mean lifespan is less than the claimed 4200 hours.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-4159\" src=\"https:\/\/www.gironi.it\/blog\/wp-content\/uploads\/2026\/07\/one-sample-t-test-critical-region.png\" alt=\"One-sample t-test: critical region and observed value\"\/><figcaption class=\"wp-element-caption\">One-sample t-test: critical region and observed value<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"p-value\">The p-Value<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We can also evaluate the hypothesis by asking: what is the probability of obtaining a test statistic value equal to or more extreme than the one observed, assuming H\u2080 is true? This probability is the <strong>p-value<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using R or a calculator we obtain t = \u22123.16 and p = 0.00578. The commands for the calculators:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>TI-83<\/strong>: <code>2nd \u2192 DISTR \u2192 tcdf(\u22121E99, \u22123.16, 9)<\/code><\/li><li><strong>Casio FX<\/strong> (STAT mode): <code>DIST \u2192 t \u2192 tcd<\/code> with Lower <code>\u22121E99<\/code>, Upper <code>\u22123.16<\/code>, df <code>9<\/code><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">There is just a 0.578% probability of observing a result like ours if H\u2080 were true. <strong>p &lt; 0.05<\/strong>: we reject H\u2080 in favour of the alternative hypothesis.<\/p>\n\n\n\n<div class=\"wp-block-group has-background\" style=\"background-color:#f5f7f9;margin-top:2.5rem;margin-bottom:2.5rem;padding-top:1.5rem;padding-right:1.5rem;padding-bottom:1.5rem;padding-left:1.5rem\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p>A word of caution: the p-value is not the probability that H\u2080 is true. It is the probability of the data <em>given<\/em> H\u2080, not the probability of H\u2080 <em>given<\/em> the data.<\/p>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"confidence-interval\">Confidence Interval<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When we reject a hypothesis, it is useful to estimate the true mean. In our example, we rejected the manufacturer&#8217;s claim. But how long do the bulbs actually last?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The confidence interval needs three things: the sample mean, the standard error, and the critical value.<\/p>\n\n\n\n\\( \\text{Margin of Error} = t_{\\text{critical}} \\times SE \\\\ \\)\n\n\n\n<p class=\"wp-block-paragraph\">In our case: ME = 1.833 \u00d7 63.3 \u2248 116. The 95% confidence interval is:<\/p>\n\n\n\n\\( 4000 \\pm 116 = [3884,\\ 4116] \\\\ \\)\n\n\n\n<p class=\"wp-block-paragraph\">The value of 4200 hours falls outside the interval, confirming the test result.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"r\">The t-Test in R<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">R lets us perform the test simply and completely. We prepare a vector of 10 measurements with a mean of 4000 and use <code>t.test()<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bulb_life &lt;- c(4100, 3900, 3800, 4200, 4000,\n               4100, 3900, 3800, 4200, 4000)\nt.test(bulb_life, mu = 4200, alternative = \"less\")<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\tOne Sample t-test\n\ndata:  bulb_life\nt = -3.1623, df = 9, p-value = 0.005788\nalternative hypothesis: true mean is less than 4200\n95 percent confidence interval:\n     -Inf 4115.791\nsample estimates:\nmean of x\n     4000<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"practical-case\">A Practical Case: Do Rewritten Title Tags Perform Better?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let us bring the tool onto the ground we actually care about. Suppose we have rewritten the title tags of ten pages and we want to know whether their CTR has shifted from the <strong>3.0%<\/strong> that was the group&#8217;s historical average. Ten pages are few, and we do not know the population variance: this is exactly where the t distribution is at its best.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are the measured CTRs, as percentages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ctr &lt;- c(3.8, 4.2, 3.1, 4.9, 3.5, 4.1, 2.9, 4.6, 3.7, 4.4)\nt.test(ctr, mu = 3.0)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\tOne Sample t-test\n\ndata:  ctr\nt = 4.5276, df = 9, p-value = 0.001431\n95 percent confidence interval:\n 3.460337 4.379663\nsample estimates:\nmean of x\n     3.92<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let us read the output. The sample mean is <strong>3.92%<\/strong>, almost a full point above the reference. The <strong>t value is 4.53<\/strong> with <strong>9 degrees of freedom<\/strong>: a measure of how many estimated standard deviations the observed mean lies from the hypothesised 3.0%. The <strong>p-value is 0.0014<\/strong>, well below the 0.05 threshold: a gap like this, if the true mean were really 3.0%, we would see by pure chance a little more than once in a thousand times. The rewrite produced an effect that is hard to dismiss as noise.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>95% confidence interval<\/strong> runs from <strong>3.46% to 4.38%<\/strong> and does not contain 3.0%. It is the same conclusion as the test, seen from another angle \u2014 not just &#8220;the effect exists&#8221; but &#8220;here is the plausible range.&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>A word of caution<\/strong>: with just ten pages that range is still almost a full percentage point wide; more data would narrow it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Effect Size: Cohen&#8217;s d<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The p-value tells us <em>whether<\/em> the difference is statistically significant. To understand <em>how large<\/em> it is, we compute <strong>Cohen&#8217;s d<\/strong> for a one-sample test:<\/p>\n\n\n\n\\( d = \\frac{\\bar{x} &#8211; \\mu}{s} \\\\ \\)\n\n\n\n<pre class=\"wp-block-code\"><code>d &lt;- (3.92 - 3.0) \/ sd(ctr)\nd<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>[1] 1.432<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Rule of thumb: d \u2248 0.2 is small, 0.5 medium, 0.8 large. Our d = 1.43 is a large effect \u2014 the difference is not only statistically significant but also substantial.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"try-it-yourself\">Try It Yourself<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We have seven landing pages and want to know whether their conversion rate departs from the <strong>2.5%<\/strong> target. Here are the values, as percentages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cr &lt;- c(2.8, 3.1, 2.4, 3.5, 2.9, 3.3, 2.7)\nt.test(cr, mu = 2.5)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Run the test, read t, df, p-value and confidence interval. The mean is <strong>2.96%<\/strong>, <strong>t is 3.24<\/strong> on <strong>6 df<\/strong>, the <strong>p-value is 0.018<\/strong>, and the 95% CI runs from <strong>2.61% to 3.30%<\/strong>. Since it does not include 2.5%, the seven pages beat the target in a way that is hard to attribute to chance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"faq\">FAQ<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>When should I use the t distribution instead of the normal?<\/strong><br> Whenever the population standard deviation is unknown and we estimate it from the sample. In practice: almost always. The normal with known sigma is more of a textbook case than a real situation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Does the t distribution work with very small samples?<\/strong><br> Yes, provided the data are not strongly skewed. For n \u2265 30, the t and the normal are practically indistinguishable. For n &lt; 15, check normality with <code>shapiro.test()<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>What are degrees of freedom?<\/strong><br> In a one-sample test, df = n \u2212 1. It is the number of values that can vary freely given a fixed mean. The more df we have, the closer the t approximates the normal.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">Student&#8217;s t distribution gave us a way to reason when the data are few and the population variance is unknown \u2014 the situation, as we have seen, we almost always find ourselves in. So far we have compared a single group against a reference value. The question that arises naturally is: what if there were <strong>two<\/strong> groups to compare \u2014 version A and version B of a page, the before and after of an intervention? That is the next step: <a href=\"\/blog\/en\/the-two-sample-t-test-how-to-test-a-hypothesis-for-dependent-or-independent-samples\/\">the two-sample t-test<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Further Reading<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For a comprehensive treatment of the t distribution, hypothesis testing, and the full machinery of statistical inference, <em>Statistica<\/em> by Newbold, Carlson and Thorne provides a rigorous yet accessible walkthrough of the theory and practice, from small-sample tests to confidence interval construction. <a href=\"https:\/\/www.amazon.it\/dp\/8891910651?tag=consulenzeinf-21&amp;ascsubtag=the-t-distribution-and-hypothesis-testing\" rel=\"nofollow sponsored noopener\" target=\"_blank\">Amazon<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the article on hypothesis testing we saw how to check whether a sample mean is compatible with a hypothesis about the population. In the examples we proposed, however, we knew the population standard deviation, sigma \u2014 which allowed us to use the normal distribution and the Z-score. In practice this is a rather rare &hellip; <a href=\"https:\/\/www.gironi.it\/blog\/en\/the-t-distribution-and-hypothesis-testing\/\" class=\"more-link\">Leggi tutto<span class=\"screen-reader-text\"> &#8220;T-Test with R examples for SEO: comparing CTR, conversions and metrics&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[161],"tags":[],"class_list":["post-3471","post","type-post","status-publish","format-standard","hentry","category-statistics"],"lang":"en","translations":{"en":3471,"it":1131},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"Paolo Gironi","author_link":"https:\/\/www.gironi.it\/blog\/author\/autore-articoli\/"},"uagb_comment_info":1,"uagb_excerpt":"In the article on hypothesis testing we saw how to check whether a sample mean is compatible with a hypothesis about the population. In the examples we proposed, however, we knew the population standard deviation, sigma \u2014 which allowed us to use the normal distribution and the Z-score. In practice this is a rather rare&hellip;","_links":{"self":[{"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/posts\/3471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/comments?post=3471"}],"version-history":[{"count":5,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/posts\/3471\/revisions"}],"predecessor-version":[{"id":4381,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/posts\/3471\/revisions\/4381"}],"wp:attachment":[{"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/media?parent=3471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/categories?post=3471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/tags?post=3471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}