<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>anova &#8211; paologironi blog</title>
	<atom:link href="https://www.gironi.it/blog/en/tag/anova/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.gironi.it/blog</link>
	<description>Scattered notes on (retro) computing, data analysis, statistics, SEO, and things that change</description>
	<lastBuildDate>Sun, 12 Jul 2026 19:16:20 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Analysis of Variance: ANOVA Explained Simply</title>
		<link>https://www.gironi.it/blog/en/analysis-of-variance-anova-explained-simply/</link>
					<comments>https://www.gironi.it/blog/en/analysis-of-variance-anova-explained-simply/#respond</comments>
		
		<dc:creator><![CDATA[paolo]]></dc:creator>
		<pubDate>Sun, 03 Oct 2021 13:53:00 +0000</pubDate>
				<category><![CDATA[statistics]]></category>
		<category><![CDATA[Analysis of Variance]]></category>
		<category><![CDATA[anova]]></category>
		<category><![CDATA[parametric test]]></category>
		<guid isPermaLink="false">https://www.gironi.it/blog/?p=3303</guid>

					<description><![CDATA[You have three Google Ads campaigns. Or four landing pages. Or five versions of a newsletter. The averages seem different, but are these real differences or just statistical noise? This is exactly the problem that Analysis of Variance (ANOVA) solves: determining whether at least one group differs genuinely from the others, without falling into the &#8230; <a href="https://www.gironi.it/blog/en/analysis-of-variance-anova-explained-simply/" class="more-link">Continue reading<span class="screen-reader-text"> "Analysis of Variance: ANOVA Explained Simply"</span></a>]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">You have three Google Ads campaigns. Or four landing pages. Or five versions of a newsletter. The averages seem different, but are these real differences or just statistical noise?</p>



<p class="wp-block-paragraph">This is exactly the problem that <strong>Analysis of Variance (ANOVA)</strong> solves: determining whether at least one group differs genuinely from the others, without falling into the trap of running dozens of separate comparisons.</p>



<span id="more-3303"></span>



<p class="wp-block-paragraph">The term &#8220;analysis of variance&#8221; sounds counterintuitive: we are comparing means, not variances. The name comes from the way the test uses variances to determine whether the means differ. ANOVA compares the variance of the means <em>between</em> groups with the variance <em>within</em> each group. If the former is sufficiently larger than the latter, we have evidence that the groups are not equivalent.</p>



<h2 class="wp-block-heading" id="intuition">The Intuition in a Metaphor</h2>



<p class="wp-block-paragraph">Imagine three school classes. In each class the students have fairly similar grades (low within-group variance), but the class averages are very different (high between-group variance). In this case it is easy to conclude that the classes are genuinely different.</p>



<p class="wp-block-paragraph">If instead the grades within each class vary wildly — brilliant students next to struggling ones — distinguishing one class from another becomes much harder, even if the averages look different. The within-group variability &#8220;drowns out&#8221; the differences between groups.</p>



<p class="wp-block-paragraph">This is what ANOVA is all about: a ratio between the variability <em>between</em> groups and the variability <em>within</em> groups. When the former clearly dominates the latter, the F value grows and we have evidence against the null hypothesis.</p>



<h2 class="wp-block-heading" id="when">When to Use ANOVA</h2>



<p class="wp-block-paragraph">ANOVA is a parametric test. It requires a few conditions:</p>



<ul class="wp-block-list"><li><strong>Normality</strong>: data in each group should approximate a normal distribution — the F statistic assumes that residuals follow a normal distribution</li><li><strong>Homogeneity of variances</strong>: groups should have approximately equal variances (homoscedasticity), otherwise the pooled variance estimate becomes biased</li><li><strong>Independence</strong>: observations are independent of each other — no observation should influence another</li><li><strong>Continuous dependent variable</strong> and <strong>categorical independent variable</strong> (the factor, with two or more levels)</li></ul>



<h2 class="wp-block-heading" id="why-not-ttests">Why ANOVA Instead of Multiple t-Tests?</h2>



<p class="wp-block-paragraph">A natural question arises: why use ANOVA when we could simply compare every pair of groups with a t-test?</p>



<p class="wp-block-paragraph">The problem is not the inconvenience of running many tests. The problem is that <strong>each test has a probability α of producing a false positive</strong> (Type I error). When we run many independent tests, these probabilities accumulate.</p>



<p class="wp-block-paragraph">For k groups, the number of pairwise comparisons is:</p>



\( n = \frac{k(k-1)}{2} \\ \)



<p class="wp-block-paragraph">With 4 groups that would be 6 t-tests. The probability of committing <em>at least one</em> Type I error becomes:</p>



\( 1 &#8211; (1 &#8211; \alpha)^n \\ \)



<p class="wp-block-paragraph">With α = 0.05 and n = 6:</p>



\( 1 &#8211; (1 &#8211; 0.05)^6 = 1 &#8211; 0.735 = 0.265 \\ \)



<p class="wp-block-paragraph">That is 26.5%: more than one in four. Unacceptable.</p>



<p class="wp-block-paragraph"><strong>When comparing three or more groups, ANOVA is preferable</strong> because it runs a single test with a single α, controlling the overall error rate.</p>



<h2 class="wp-block-heading" id="one-way">The Simplest Case: One-Way ANOVA</h2>



<p class="wp-block-paragraph">One-way ANOVA is the simplest form. The data are organised into groups based on a single categorical variable (the factor). The question is:</p>



<p class="wp-block-paragraph">&gt; Are the observed differences between the means too large to be attributed to chance?</p>



<p class="wp-block-paragraph">Let us formalise the hypotheses:</p>



\( H_0: \mu_1 = \mu_2 = \dots = \mu_k \\ \)



\( H_a: \text{at least one mean differs from the others} \\ \)



<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">
<p><strong>Important</strong>: ANOVA tells us THAT a difference exists, not WHERE it is. To identify which groups differ, we need a <em>post-hoc</em> test, which we will see shortly.</p>
</div></div>



<h2 class="wp-block-heading" id="interpret-f">How to Interpret the F Value</h2>



<p class="wp-block-paragraph">The core of ANOVA is the F ratio:</p>



\( F = \frac{\text{variance between groups}}{\text{variance within groups}} = \frac{MS_b}{MS_e} \\ \)



<p class="wp-block-paragraph">If the null hypothesis is true, both \( MS_b \) and \( MS_e \) estimate the same variance, and F is close to 1. If F is significantly greater than 1, we have evidence that the means are not all equal.</p>



<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">
<p>ANOVA was developed by <strong>Ronald Fisher</strong> in the 1920s. The F statistic it relies on is named in his honour as the <strong>Fisher-Snedecor F distribution</strong>.</p>
</div></div>



<figure class="wp-block-image size-large"><img decoding="async" class="wp-image-4167" src="https://www.gironi.it/blog/wp-content/uploads/2026/07/f-distribution.png" alt="F distribution and critical region"/><figcaption class="wp-element-caption">F distribution and critical region</figcaption></figure>



<h2 class="wp-block-heading" id="example">A Step-by-Step Example</h2>



<p class="wp-block-paragraph">Let us take a concrete case. We want to know whether the type of device (desktop, mobile, tablet) affects goal completions on the site. We track monthly data for 6 months:</p>



<figure class="wp-block-table"><table><thead><tr><th>Desktop</th><th>Mobile</th><th>Tablet</th></tr></thead><tbody><tr><td>39</td><td>45</td><td>30</td></tr><tr><td>67</td><td>54</td><td>45</td></tr><tr><td>78</td><td>64</td><td>22</td></tr><tr><td>59</td><td>52</td><td>39</td></tr><tr><td>42</td><td>46</td><td>38</td></tr><tr><td>51</td><td>35</td><td>41</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">Group means:</p>



\( \bar{x}_{\text{desktop}} = 56 \quad \bar{x}_{\text{mobile}} = 49.3 \quad \bar{x}_{\text{tablet}} = 35.8 \\ \)



<p class="wp-block-paragraph">And the <strong>grand mean</strong> (mean of all observations): \( \bar{x} = 47 \).</p>



<p class="wp-block-paragraph">To understand where the F statistic comes from, we need to decompose the total variability into two parts: the variability <em>between</em> groups and the variability <em>within</em> groups. Without going through every manual calculation — nobody does them by hand anymore, as we will see shortly — from these we derive the respective variances (Mean Squares) and finally the F ratio.</p>



<figure class="wp-block-table"><table><thead><tr><th>Source</th><th>SS</th><th>df</th><th>MS</th><th>F</th><th>p</th></tr></thead><tbody><tr><td>Device (between)</td><td>1266.4</td><td>2</td><td>633.2</td><td><strong>4.86</strong></td><td><strong>0.0236</strong></td></tr><tr><td>Residual (within)</td><td>1954.2</td><td>15</td><td>130.3</td><td></td><td></td></tr><tr><td>Total</td><td>3220.6</td><td>17</td><td></td><td></td><td></td></tr></tbody></table></figure>



<p class="wp-block-paragraph">F = 4.86 exceeds the critical value (3.68 for df = 2,15 and α = 0.05). With a p-value of <strong>0.0236</strong>, we reject the null hypothesis: at least one device has a different mean.</p>



<h2 class="wp-block-heading" id="interpret-p">How to Interpret the p-Value</h2>



<p class="wp-block-paragraph">The p-value in ANOVA is read like any hypothesis test: it is the probability of observing an F value equal to or more extreme than the one obtained, assuming H₀ is true. A small p-value (typically &lt; 0.05) tells us that the observed differences are unlikely to be due to chance.</p>



<p class="wp-block-paragraph">But note: <strong>statistical significance does not mean practical importance</strong>. A very small p-value can hide a negligible effect if the sample is large. That is why we need effect size.</p>



<h2 class="wp-block-heading" id="effect-size">Effect Size: η² (Eta-Squared)</h2>



<p class="wp-block-paragraph">The p-value tells us <em>whether</em> a difference exists. Eta-squared tells us <em>how large</em> it is.</p>



\( \eta^2 = \frac{SS_b}{SS_{\text{total}}} = \frac{1266.4}{3220.6} \approx 0.39 \\ \)



<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">
<p>A very small p-value tells us that a difference probably exists. But it does not tell us whether that difference is large or negligible. That is why it is good practice to always accompany ANOVA with a measure of effect size.</p>
</div></div>



<p class="wp-block-paragraph">Rules of thumb for η²:</p>



<ul class="wp-block-list"><li><strong>0.01</strong>: small effect</li><li><strong>0.06</strong>: medium effect</li><li><strong>0.14</strong>: large effect</li></ul>



<p class="wp-block-paragraph">Our η² = 0.39 is a very large effect: the type of device explains 39% of the variability in goal completions.</p>



<h2 class="wp-block-heading" id="post-hoc">What to Do After ANOVA: Post-Hoc Tests</h2>



<p class="wp-block-paragraph">ANOVA tells us that a difference exists, but not which groups differ. For that we need <strong>post-hoc</strong> tests.</p>



<p class="wp-block-paragraph">The most common is <strong>Tukey&#8217;s HSD</strong> (Honestly Significant Difference), which compares all pairs of means while correcting for multiple comparisons.</p>



<p class="wp-block-paragraph">In our example, Tukey HSD would tell us that the significant difference is between tablet and desktop, while the other pairs do not reach significance.</p>



<h2 class="wp-block-heading" id="seo">A Practical SEO Case: Does Time on Page Depend on Channel?</h2>



<p class="wp-block-paragraph">Let us put ANOVA to work on a question anyone looking at site data eventually asks: do users coming from different channels behave differently?</p>



<p class="wp-block-paragraph">We have time on page (in seconds) for 8 sessions from each of four channels:</p>



<pre class="wp-block-code"><code>organic &lt;- c(98, 112, 85, 105, 92, 120, 88, 101)
direct  &lt;- c(90, 102, 78, 95, 110, 84, 99, 88)
paid    &lt;- c(72, 65, 80, 58, 70, 75, 62, 68)
social  &lt;- c(55, 48, 62, 50, 44, 58, 52, 46)

time   &lt;- c(organic, direct, paid, social)
channel &lt;- factor(rep(c("organic","direct","paid","social"), each = 8))</code></pre>



<p class="wp-block-paragraph">Compute in R:</p>



<pre class="wp-block-code"><code>summary(aov(time ~ channel))</code></pre>



<pre class="wp-block-code"><code>             Df Sum Sq Mean Sq F value   Pr(&gt;F)
channel       3  11913    3971   46.82 4.89e-11 ***
Residuals    28   2375      85</code></pre>



<p class="wp-block-paragraph">F = 46.82 and the p-value is on the order of 10⁻¹¹: well below any reasonable threshold. We reject the null hypothesis: <strong>at least one channel</strong> behaves differently.</p>



<p class="wp-block-paragraph">Let us look at the means:</p>



<pre class="wp-block-code"><code>tapply(time, channel, mean)</code></pre>



<pre class="wp-block-code"><code>  direct  organic     paid   social
    93.2    100.1     68.8     51.9</code></pre>



<p class="wp-block-paragraph">Organic is the most engaged channel (100 seconds), followed by direct (93). Social stops at 52 seconds — traffic from feeds tends to bounce quickly.</p>



<p class="wp-block-paragraph">Let us calculate η² to understand the effect size:</p>



<pre class="wp-block-code"><code>11913 / (11913 + 2375)  # ≈ 0.83</code></pre>



<p class="wp-block-paragraph"><strong>0.83</strong>: the channel explains 83% of the variability in time on page. A huge effect. In real-world settings such high values are quite rare: this example is deliberately constructed to make the method&#8217;s workings evident.</p>



<pre class="wp-block-code"><code>TukeyHSD(aov(time ~ channel))</code></pre>



<pre class="wp-block-code"><code>                      diff       lwr        upr     p adj
direct-organic      -6.875  -24.423    10.6730 0.7165876
paid-organic       -31.250  -48.798   -13.7020 0.0003217
social-organic     -48.250  -65.798   -30.7020 0.0000001
paid-direct        -24.375  -41.923    -6.8270 0.0041674
social-direct      -41.375  -58.923   -23.8270 0.0000073
social-paid        -17.000  -34.548     0.5480 0.0598936</code></pre>



<p class="wp-block-paragraph">The post-hoc test confirms that all differences involving paid and social versus organic and direct are significant. The difference between organic and direct, however, is not statistically significant.</p>



<h2 class="wp-block-heading" id="assumptions">Checking ANOVA Assumptions</h2>



<p class="wp-block-paragraph">Before trusting the results, it is wise to verify the assumptions:</p>



<p class="wp-block-paragraph"><strong>Normality of residuals:</strong></p>



<pre class="wp-block-code"><code>model &lt;- aov(time ~ channel)
shapiro.test(residuals(model))</code></pre>



<p class="wp-block-paragraph"><strong>Homogeneity of variances (homoscedasticity):</strong></p>



<pre class="wp-block-code"><code>bartlett.test(time ~ channel)</code></pre>



<p class="wp-block-paragraph">If these assumptions are violated, non-parametric alternatives such as the <strong>Kruskal-Wallis test</strong> can be used.</p>



<h2 class="wp-block-heading" id="practice">In Everyday Practice</h2>



<p class="wp-block-paragraph">Nobody computes an ANOVA table by hand anymore. Programs like R, Python (scipy.stats), SPSS, or Jamovi perform the calculation in seconds. Understanding what the different components represent — the decomposition of variance, the F ratio, the degrees of freedom — remains essential for correctly interpreting the result.</p>



<h2 class="wp-block-heading" id="try">Try It Yourself</h2>



<p class="wp-block-paragraph">An e-commerce store ran three campaigns (A, B, C) and wants to know whether the average order value differs significantly.</p>



<pre class="wp-block-code"><code>camp_A &lt;- c(42, 38, 45, 50, 41, 47, 39, 44)
camp_B &lt;- c(48, 52, 46, 55, 50, 53, 49, 51)
camp_C &lt;- c(44, 40, 49, 43, 46, 41, 45, 47)

value    &lt;- c(camp_A, camp_B, camp_C)
campaign &lt;- factor(rep(c("A","B","C"), each = 8))
summary(aov(value ~ campaign))</code></pre>



<p class="wp-block-paragraph">Run the test, read F and p-value, calculate η².</p>



<p class="wp-block-paragraph">F = <strong>10.77</strong>, p = <strong>0.0006</strong>, η² = <strong>0.44</strong>. Campaign B (mean €50.5) performs better than A (€43.2) and C (€44.4), and the difference is statistically significant. Tukey HSD would confirm this by pointing at B.</p>



<h2 class="wp-block-heading" id="faq">FAQ</h2>



<p class="wp-block-paragraph"><strong>Does ANOVA work with only two groups?</strong><br> Yes, but in that case it is equivalent to a two-tailed t-test (and F = t²).</p>



<p class="wp-block-paragraph"><strong>What does &#8220;one-way&#8221; and &#8220;two-way&#8221; mean?</strong><br> One-way: a single factor (e.g., channel). Two-way: two factors simultaneously (e.g., channel × device), which also allows studying their interaction.</p>



<p class="wp-block-paragraph"><strong>Can I use ANOVA with small samples?</strong><br> Yes, but check normality and homoscedasticity. With unequal group sizes, ANOVA is still robust if the deviations are not extreme.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="wp-block-paragraph">ANOVA is one of those ideas that, once understood, you see everywhere: whenever we compare a continuous metric across multiple groups — channels, devices, variants, time periods — it is the right tool for not confusing noise with signal. And it is not an island: under the hood, analysis of variance and linear regression are the same model, seen from two different angles. It is from that model — the linear model — that the most powerful part of applied statistics flows, and that is where our journey continues.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h3 class="wp-block-heading">Further Reading</h3>



<p class="wp-block-paragraph">Analysis of variance in all its forms — one-way, two-way, repeated measures — is covered in <em>Statistics</em> by Newbold, Carlson and Thorne, for those who want to go beyond the introduction in this article. <a href="https://www.amazon.it/dp/8891910651?tag=consulenzeinf-21&amp;ascsubtag=analysis-of-variance-anova-explained-simply" rel="nofollow sponsored noopener" target="_blank">Amazon</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gironi.it/blog/en/analysis-of-variance-anova-explained-simply/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
