<?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>regressione &#8211; paologironi blog</title>
	<atom:link href="https://www.gironi.it/blog/en/tag/regressione/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>Mon, 12 Oct 2026 09:01:21 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Multicollinearity, Heteroscedasticity, Autocorrelation: Three Difficult-Sounding Concepts Explained Simply (with an Example in R)</title>
		<link>https://www.gironi.it/blog/en/multicollinearity-heteroscedasticity-autocorrelation-three-difficult-sounding-concepts-explained-simply/</link>
					<comments>https://www.gironi.it/blog/en/multicollinearity-heteroscedasticity-autocorrelation-three-difficult-sounding-concepts-explained-simply/#respond</comments>
		
		<dc:creator><![CDATA[paolo]]></dc:creator>
		<pubDate>Sun, 17 Oct 2021 13:41:00 +0000</pubDate>
				<category><![CDATA[statistics]]></category>
		<category><![CDATA[autocorrelation]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[eteroschedasticità]]></category>
		<category><![CDATA[Heteroscedasticity]]></category>
		<category><![CDATA[omoschedasticità]]></category>
		<category><![CDATA[regressione]]></category>
		<category><![CDATA[time series]]></category>
		<guid isPermaLink="false">https://www.gironi.it/blog/?p=3299</guid>

					<description><![CDATA[In the posts on multiple regression, analysis of variance and time series we came across three terms that seem made on purpose to scare the reader. Multicollinearity, heteroscedasticity, autocorrelation: if we want to convince someone that statistics is a dark and inaccessible subject, these are the magic words to say. 🙂 Surprise: behind the names &#8230; <a href="https://www.gironi.it/blog/en/multicollinearity-heteroscedasticity-autocorrelation-three-difficult-sounding-concepts-explained-simply/" class="more-link">Continue reading<span class="screen-reader-text"> "Multicollinearity, Heteroscedasticity, Autocorrelation: Three Difficult-Sounding Concepts Explained Simply (with an Example in R)"</span></a>]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">In the posts on <a href="https://www.gironi.it/blog/en/multiple-regression-analysis-explained-simply/">multiple regression</a>, <a href="https://www.gironi.it/blog/en/analysis-of-variance-anova-explained-simply/">analysis of variance</a> and <a href="https://www.gironi.it/blog/en/time-series-analysis-and-forecasting-in-r/">time series</a> we came across three terms that seem made on purpose to scare the reader. Multicollinearity, heteroscedasticity, autocorrelation: if we want to convince someone that statistics is a dark and inaccessible subject, these are the magic words to say. 🙂</p>



<p class="wp-block-paragraph">Surprise: behind the names there are three simple ideas, and above all three very concrete problems. To see them at work, let&#8217;s take the model that sooner or later anyone working in digital marketing builds: how many conversions does each euro spent on Google Ads and on Meta bring us? We&#8217;ll watch it fall into all three traps, one after the other, and learn how to recognise them and get out.</p>



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



<p class="wp-block-paragraph"><strong>In short:</strong> these are three different problems of regression. <strong>Multicollinearity</strong> concerns the <em>predictors</em>: two or more explanatory variables are strongly correlated with each other, and the model can&#8217;t separate their effects (unstable coefficients, sometimes with the wrong sign). <strong>Heteroscedasticity</strong> concerns the <em>errors</em>: their spread is not constant, but grows or shrinks with the predicted values. <strong>Autocorrelation</strong> also concerns the <em>errors</em>, ordered in time: today&#8217;s error is linked to yesterday&#8217;s. In the last two cases the coefficients remain correct on average, but <strong>standard errors, p-values and confidence intervals become unreliable</strong>. In R they are diagnosed with the VIF, the Breusch-Pagan test and the Durbin-Watson test.</p>



<p class="wp-block-paragraph"><strong>What we&#8217;ll cover</strong>:</p>



<ul class="wp-block-list"><li><a href="#the-model">The model: how much is each advertising euro worth?</a></li><li><a href="#multicollinearity">What is multicollinearity?</a></li><li><a href="#heteroscedasticity">What is heteroscedasticity?</a></li><li><a href="#autocorrelation">What is autocorrelation?</a></li><li><a href="#differences">Multicollinearity vs heteroscedasticity vs autocorrelation: what&#8217;s the difference?</a></li><li><a href="#faq">Frequently asked questions</a></li><li><a href="#try-it-yourself">Try it yourself</a></li><li><a href="#further-reading">Further reading</a></li></ul>



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



<h2 class="wp-block-heading" id="the-model">The model: how much is each advertising euro worth?</h2>



<p class="wp-block-paragraph">Let&#8217;s imagine an e-commerce site that for two years has been investing every week in Google Ads and Meta. The business is growing, spend follows the seasons, and in the spreadsheet we have 104 rows: for each week the two budgets and the conversions obtained. The data are simulated, so we know the truth: both channels work, Google a little more than Meta.</p>



<p class="wp-block-paragraph">Let&#8217;s generate the data in R:</p>



<pre class="wp-block-code"><code>library(lmtest)     # Breusch-Pagan and Durbin-Watson tests
library(sandwich)   # robust standard errors

simulate &lt;- function() {
  week &lt;- 1:104
  growth &lt;- seq(5000, 15000, length.out = 104)            # the business grows
  season &lt;- 1 + 0.35 * sin(2 * pi * week / 52)            # high and low season
  google &lt;- round(growth * season * exp(rnorm(104, 0, 0.10)))
  meta &lt;- round(0.45 * google * exp(rnorm(104, 0, 0.08)))  # follows Google
  error &lt;- as.numeric(arima.sim(list(ar = 0.6), 104, sd = 0.12))
  conversions &lt;- round(exp(0.6 + 0.40 * log(google) + 0.20 * log(meta) + error))
  data.frame(week, google, meta, conversions)
}

set.seed(114)
data &lt;- simulate()</code></pre>



<p class="wp-block-paragraph">The three traps are already written into these lines, even if we can&#8217;t see them yet: Meta&#8217;s budget is set as a share of Google&#8217;s, the error is multiplicative (it grows with the size of the week) and it follows a pattern that drags on from one week to the next. Now let&#8217;s do what anyone would do, a regression of conversions on the two kinds of spend:</p>



<pre class="wp-block-code"><code>model &lt;- lm(conversions ~ google + meta, data = data)
summary(model)
# Coefficients:
#               Estimate Std. Error t value Pr(&gt;|t|)
# (Intercept) 179.480922  19.529960   9.190 5.45e-15 ***
# google        0.030642   0.008473   3.616 0.000468 ***
# meta         -0.024130   0.018618  -1.296 0.197920
#
# Multiple R-squared:  0.5323,	Adjusted R-squared:  0.5231
# F-statistic: 57.48 on 2 and 101 DF,  p-value: &lt; 2.2e-16</code></pre>



<p class="wp-block-paragraph">Let&#8217;s read it the way a marketing manager would: every €1,000 on Google brings about 31 conversions. And every €1,000 on Meta <em>takes away</em> 24. Obvious conclusion: switch Meta off.</p>



<p class="wp-block-paragraph">It would be a costly mistake, because in the data Meta works. The model as a whole explains half of the variability in conversions (R² 0.53, F test with a tiny p-value), but the split between the two channels is an illusion. Welcome to multicollinearity.</p>



<h2 class="wp-block-heading" id="multicollinearity">What is multicollinearity?</h2>



<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>We speak of <strong>multicollinearity</strong> when <strong>two or more explanatory variables in a regression model are strongly correlated with each other</strong>. The model knows that <em>together</em> they matter, but it can&#8217;t establish <em>how much</em> each one does.</p>
</div></div>



<p class="wp-block-paragraph">The reason is intuitive. To estimate the effect of Meta &#8220;holding Google fixed&#8221;, the regression needs weeks in which Meta varies and Google doesn&#8217;t. But in our data, when Google goes up Meta goes up too: the correlation between the two kinds of spend is 0.975. The weeks that help tell the two effects apart are very few, and the estimate rests on those few random wobbles.</p>



<p class="wp-block-paragraph">The standard tool to measure the problem is the <strong>VIF</strong>, the <em>variance inflation factor</em>. It&#8217;s computed with an auxiliary regression: we explain one predictor with all the others and see how well we manage. If the R² of this regression is high, the predictor is almost a copy of the others:</p>



<p class="wp-block-paragraph">\(VIF = \frac{1}{1 &#8211; R^2_{\text{auxiliary}}}\)</p>



<p class="wp-block-paragraph">The name says exactly what it measures: how many times the variance of the coefficient is inflated compared with the case of independent predictors. Let&#8217;s compute it:</p>



<pre class="wp-block-code"><code>r2_aux &lt;- summary(lm(google ~ meta, data = data))$r.squared
r2_aux
# [1] 0.9511464
1 / (1 - r2_aux)
# [1] 20.46933</code></pre>



<p class="wp-block-paragraph">The car package computes it directly with <code>vif(model)</code>. The most widespread rule of thumb considers a VIF above 5 worrying and above 10 serious. Ours is <strong>20.5</strong>: the variance of the estimates is twenty times what we&#8217;d have with two independent channels, and the standard error (its square root) more than four times.</p>



<p class="wp-block-paragraph">What does that mean in practice? We see it by repeating the same experiment 500 times: same rules, same true effects, just a different random draw.</p>



<pre class="wp-block-code"><code>set.seed(2026)
estimates &lt;- t(replicate(500, {
  d &lt;- simulate()
  1000 * c(coef(lm(conversions ~ google + meta, data = d))[2:3],
           total = coef(lm(conversions ~ I(google + meta), data = d))[[2]])
}))
mean(estimates[, "meta"] &lt; 0)
# [1] 0.146
cor(estimates[, "google"], estimates[, "meta"])
# [1] -0.9068232</code></pre>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.gironi.it/blog/wp-content/uploads/2026/10/diagnostica-multicollinearita-en.png" alt="On the left, weekly spend on Google Ads and Meta: the points lie almost on a line, correlation 0.98. On the right, the estimates of the two effects in 500 repetitions of the same experiment: they line up along a descending diagonal, because when one estimate goes up the other goes down. In about one case in seven Meta's effect comes out negative; the red dot is our data."/><figcaption class="wp-element-caption">On the left, weekly spend on Google Ads and Meta: the points lie almost on a line, correlation 0.98. On the right, the estimates of the two effects in 500 repetitions of the same experiment: they line up along a descending diagonal, because when one estimate goes up the other goes down. In about one case in seven Meta&#8217;s effect comes out negative; the red dot is our data.</figcaption></figure>



<p class="wp-block-paragraph"><strong>The two estimates compete for the same effect</strong>: when one goes up, the other goes down (correlation −0.91 between the estimates). In one case in seven Meta even comes out negative, and our dataset is one of those. And yet the sum of the two effects is stable: total spend has a standard deviation of 2.5 conversions per €1,000, against 8.7 for Google and 17.7 for Meta.</p>



<p class="wp-block-paragraph">Here is the hallmark of multicollinearity: <strong>the model as a whole works, the predictions are good, but the individual coefficients are not credible</strong>. It often shows up exactly like this: a fair or high R², a significant F test, and coefficients with huge standard errors or signs that defy common sense.</p>



<h3 class="wp-block-heading">How do we avoid it in a marketing regression model?</h3>



<p class="wp-block-paragraph">There&#8217;s no test that &#8220;cures&#8221; multicollinearity, because it isn&#8217;t a flaw in the calculation: it&#8217;s a lack of information in the data. There are four routes.</p>



<ul class="wp-block-list"><li><strong>Ask a less ambitious question.</strong> If the two budgets move together, let&#8217;s ask how much total spend is worth. With <code>lm(conversions ~ I(google + meta))</code> we get 13.6 conversions per €1,000, with a standard error of 1.3: a solid estimate.</li><li><strong>Get the missing information.</strong> To separate the channels we need weeks in which they move independently: an experiment where Meta is switched off in some areas or some weeks, the same principle as the control group we use in <a href="https://www.gironi.it/blog/en/seo-split-testing/">SEO split tests</a>. More data of the same kind, on the other hand, helps little: if the budgets keep moving together, the problem stays.</li><li><strong>Drop one of the two variables</strong>, but carefully: Google would also take credit for Meta, and the estimate would become biased. It&#8217;s the same confounding mechanism we saw in multiple regression.</li><li><strong>Use methods that accept some bias in exchange for stability</strong>, such as <em>ridge</em> regression, which shrinks the coefficients towards zero. They are the bread and butter of machine learning, but they make interpretation less immediate.</li></ul>



<p class="wp-block-paragraph">From here on we follow the first route and work with total spend:</p>



<pre class="wp-block-code"><code>data$spend &lt;- data$google + data$meta
model_tot &lt;- lm(conversions ~ spend, data = data)</code></pre>



<h2 class="wp-block-heading" id="heteroscedasticity">What is heteroscedasticity?</h2>



<p class="wp-block-paragraph">Well, this term seems made on purpose to scare. But the concept, it turns out, isn&#8217;t that complicated.</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><strong>Heteroscedasticity</strong> basically means <strong>unequal spread</strong>: it happens when <strong>the variance of the errors of a regression model is not constant, but changes with the predicted values or with an explanatory variable</strong>. The opposite case, the one ordinary least squares assumes, is called <strong>homoscedasticity</strong>: errors with the same spread at every level.</p>
</div></div>



<p class="wp-block-paragraph">In marketing, heteroscedasticity is almost the rule. A 300-conversion week can be off by 30 either way; a 600-conversion week, other things equal, is off by 60. Errors grow with size, because effects are proportional rather than additive. The simplest way to notice it is to look at the residuals against the predicted values: if they fan out, the variance isn&#8217;t constant.</p>



<p class="wp-block-paragraph">For a formal check we use the <strong>Breusch-Pagan test</strong>, which checks whether the squared residuals can be explained by the predictors. The null hypothesis is homoscedasticity:</p>



<pre class="wp-block-code"><code>bptest(model_tot)
# BP = 9.3544, df = 1, p-value = 0.002224</code></pre>



<p class="wp-block-paragraph">With a p-value of 0.002, the constant-variance hypothesis doesn&#8217;t hold.</p>



<p class="wp-block-paragraph"><strong>What happens if we ignore it?</strong> Here there&#8217;s good news that textbooks often leave in the shade: <strong>the coefficients remain correct on average</strong>. What breaks is the estimate of their precision: standard errors computed with the classical formula are wrong, and so are p-values and confidence intervals. In our case the <em>robust</em> standard errors, which don&#8217;t assume constant variance, are 20% larger (from 0.00131 to 0.00157):</p>



<pre class="wp-block-code"><code>coeftest(model_tot, vcov = vcovHC(model_tot, type = "HC3"))
#               Estimate Std. Error t value  Pr(&gt;|t|)
# (Intercept) 1.7769e+02 2.0789e+01  8.5472 1.310e-13 ***
# spend       1.3622e-02 1.5723e-03  8.6638 7.273e-14 ***</code></pre>



<p class="wp-block-paragraph"><strong>How do we fix it?</strong> There are three routes, often combined:</p>



<ul class="wp-block-list"><li>use <strong>robust standard errors</strong>, as we just did: the simplest solution, which doesn&#8217;t change the estimates but only their uncertainty;</li><li><strong>transform the variables</strong>, typically with logarithms, when effects are proportional;</li><li>use <strong>weighted least squares</strong>, which give less weight to the noisier observations.</li></ul>



<p class="wp-block-paragraph">In our case the second route is also the most natural, because the error is multiplicative by construction. Let&#8217;s move to logarithms:</p>



<pre class="wp-block-code"><code>model_log &lt;- lm(log(conversions) ~ log(spend), data = data)
coef(summary(model_log))
#              Estimate Std. Error    t value     Pr(&gt;|t|)
# (Intercept) 0.2257489 0.45602741  0.4950336 6.216411e-01
# log(spend)  0.5953304 0.04792515 12.4220879 3.942384e-22
bptest(model_log)
# BP = 1.1777, df = 1, p-value = 0.2778</code></pre>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.gironi.it/blog/wp-content/uploads/2026/10/diagnostica-eteroschedasticita-en.png" alt="Residuals against predicted values, for the linear model (left) and the model on logarithms (right). In the first the cloud widens towards the bigger weeks; in the second the spread is uniform. The Breusch-Pagan test goes from p = 0.002 to p = 0.28."/><figcaption class="wp-element-caption">Residuals against predicted values, for the linear model (left) and the model on logarithms (right). In the first the cloud widens towards the bigger weeks; in the second the spread is uniform. The Breusch-Pagan test goes from p = 0.002 to p = 0.28.</figcaption></figure>



<p class="wp-block-paragraph">The fan closes, and the test finds nothing anymore. On top of that, the coefficient has gained a very handy interpretation: in a model with logarithms on both sides it&#8217;s an <strong>elasticity</strong>. The value of 0.595 says that <strong>10% more spend brings about 5.8% more conversions</strong> (1.1 raised to 0.595 is 1.058). In the simulation the true value is 0.6: the model got very close.</p>



<h2 class="wp-block-heading" id="autocorrelation">What is autocorrelation?</h2>



<p class="wp-block-paragraph">The last trap remains, the sneakiest one when data are ordered in time.</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>We have <strong>autocorrelation</strong> (or <em>serial correlation</em>) when <strong>the errors of a regression model are correlated with each other over time</strong>: the error of one period says something about the error of the next one. In the most common case, first-order positive autocorrelation, a week that went better than expected tends to be followed by another week that went better than expected.</p>
</div></div>



<p class="wp-block-paragraph">In marketing it happens all the time: a competitor&#8217;s campaign, a period of favourable prices, a Google algorithm update, a good review going round. They&#8217;re all things the model doesn&#8217;t see and that last more than a week. The errors, then, don&#8217;t jump randomly above and below zero: they stay on the same side for weeks on end. The plot of residuals in time order shows it at a glance:</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.gironi.it/blog/wp-content/uploads/2026/10/diagnostica-autocorrelazione-en.png" alt="The residuals of the model on logarithms, week by week. Instead of alternating randomly above and below zero, they form long runs of the same sign: the lag-1 autocorrelation is 0.59 and the Durbin-Watson statistic 0.81."/><figcaption class="wp-element-caption">The residuals of the model on logarithms, week by week. Instead of alternating randomly above and below zero, they form long runs of the same sign: the lag-1 autocorrelation is 0.59 and the Durbin-Watson statistic 0.81.</figcaption></figure>



<p class="wp-block-paragraph">The classical test is <strong>Durbin-Watson</strong>. Its statistic d is about 2 with no autocorrelation, drops towards 0 with positive autocorrelation and rises towards 4 with negative autocorrelation. In R we no longer need the tables: the test returns the p-value directly.</p>



<pre class="wp-block-code"><code>dwtest(model_log)
# DW = 0.81187, p-value = 2.573e-10
acf(resid(model_log), plot = FALSE)$acf[2]
# [1] 0.5881333</code></pre>



<p class="wp-block-paragraph">A statistic of 0.81 and a residual autocorrelation of 0.59 between one week and the next: the problem is there, and it&#8217;s strong. For longer series or higher-order autocorrelation (between an error and the one two or more periods earlier) we also use the <code>acf()</code> function and the Ljung-Box test, which we met when talking about time series.</p>



<p class="wp-block-paragraph"><strong>What happens if we ignore it?</strong> As with heteroscedasticity, the estimates remain correct on average, but the classical standard-error formula assumes that each week brings independent information. With positive autocorrelation that isn&#8217;t so: 104 weeks that resemble each other in groups are worth less than 104 independent observations. <strong>The model believes it&#8217;s more precise than it is.</strong> Newey-West standard errors, which account for both autocorrelation and heteroscedasticity, show it right away:</p>



<pre class="wp-block-code"><code>coeftest(model_log, vcov = NeweyWest(model_log))
#             Estimate Std. Error t value  Pr(&gt;|t|)
# (Intercept)  0.22575    1.00072  0.2256     0.822
# log(spend)   0.59533    0.10624  5.6039 1.791e-07 ***</code></pre>



<p class="wp-block-paragraph">The standard error of the elasticity goes from 0.048 to 0.106, more than double. The 95% confidence interval, which with the classical formula ran from 0.50 to 0.69, widens to 0.38 to 0.81. The effect of advertising remains clearly positive, but our uncertainty about <em>how much</em> it&#8217;s worth is more than double what we thought. With a smaller effect, the difference between the two formulas would be the one between a &#8220;significant&#8221; result and one that isn&#8217;t.</p>



<p class="wp-block-paragraph"><strong>How do we fix it?</strong></p>



<ul class="wp-block-list"><li>use <strong>Newey-West standard errors</strong>, as above, if what matters is mainly the estimates and their uncertainty;</li><li><strong>model what&#8217;s missing</strong>: autocorrelation often comes from an omitted variable that moves slowly (seasonality, trend, promotions), and adding it to the model reduces it;</li><li>use models that explicitly estimate the correlation between errors, such as generalised least squares (in R <code>gls()</code> from the nlme package, with <code>correlation = corAR1()</code>). They are the modern descendants of Durbin&#8217;s two-step method and of the Cochrane-Orcutt procedure.</li></ul>



<h2 class="wp-block-heading" id="differences">Multicollinearity vs heteroscedasticity vs autocorrelation: what&#8217;s the difference?</h2>



<p class="wp-block-paragraph">At this point we can put the three concepts side by side. The most important distinction is where the problem lies: multicollinearity concerns the explanatory variables, the other two concern the errors.</p>



<figure class="wp-block-table"><table><thead><tr><th></th><th>Multicollinearity</th><th>Heteroscedasticity</th><th>Autocorrelation</th></tr></thead><tbody><tr><td>Where the problem lies</td><td>in the predictors, correlated with each other</td><td>in the errors, with non-constant variance</td><td>in the errors, correlated over time</td></tr><tr><td>Coefficients</td><td>correct on average, but very unstable</td><td>correct on average</td><td>correct on average</td></tr><tr><td>Standard errors</td><td>large (inflated)</td><td>wrong</td><td>usually too small</td></tr><tr><td>How to spot it</td><td>VIF above 5-10</td><td>fan-shaped residuals, Breusch-Pagan test</td><td>residuals in runs, Durbin-Watson test</td></tr><tr><td>Typical remedies</td><td>aggregate spend, experiments, ridge</td><td>logarithms, robust standard errors</td><td>Newey-West, omitted variables, <code>gls()</code></td></tr></tbody></table></figure>



<p class="wp-block-paragraph">There&#8217;s a subtle but important difference between the first and the other two. With multicollinearity the standard errors are large <em>and they know it</em>: the model warns us, in its own way, that it can&#8217;t separate the effects. With heteroscedasticity and autocorrelation, instead, classical standard errors are wrong <em>silently</em>, and often in the worst direction: they make us look more confident than we are. That&#8217;s why diagnostic tests aren&#8217;t an appendix for nitpickers, but a check to run every time a regression has to guide a decision, from an advertising ROI model to a forecast of organic traffic.</p>



<h2 class="wp-block-heading" id="faq">Frequently asked questions</h2>



<h3 class="wp-block-heading">What is the difference between multicollinearity and autocorrelation?</h3>



<p class="wp-block-paragraph">Multicollinearity concerns the explanatory variables, correlated with each other; autocorrelation concerns the model&#8217;s errors, correlated over time. The first makes the coefficients unstable and is measured with the VIF; the second makes the standard errors too optimistic and is checked with the Durbin-Watson test.</p>



<h3 class="wp-block-heading">What is the difference between heteroscedasticity and multicollinearity?</h3>



<p class="wp-block-paragraph">Heteroscedasticity concerns the errors, whose variance is not constant; multicollinearity concerns the predictors, which are strongly correlated. With heteroscedasticity the coefficients are fine but the classical standard errors are wrong; with multicollinearity the standard errors are honestly large because the data can&#8217;t separate the effects.</p>



<h3 class="wp-block-heading">What is the difference between heteroscedasticity and autocorrelation?</h3>



<p class="wp-block-paragraph">Both concern the model&#8217;s errors and leave the coefficients correct on average. Heteroscedasticity is about their spread, which changes from one observation to another; autocorrelation is about their link over time. They can occur together, and Newey-West standard errors account for both.</p>



<h3 class="wp-block-heading">How do we avoid these problems in a marketing or advertising ROI regression model?</h3>



<p class="wp-block-paragraph">For multicollinearity, avoid moving all channels together, or use experiments that vary one channel at a time; otherwise model total spend. For heteroscedasticity, use logarithms when effects are proportional, or robust standard errors. For autocorrelation in weekly data, add seasonality and trend to the model and use Newey-West standard errors.</p>



<h3 class="wp-block-heading">What VIF value indicates multicollinearity?</h3>



<p class="wp-block-paragraph">There is no universal threshold. The most widespread rule of thumb considers a VIF above 5 worth watching and above 10 serious. A VIF of 10 means the variance of the coefficient is ten times what it would be with independent predictors.</p>



<h3 class="wp-block-heading">What should the Durbin-Watson statistic be?</h3>



<p class="wp-block-paragraph">About 2 with no autocorrelation. Values close to 0 indicate positive autocorrelation, values close to 4 negative autocorrelation. In R, <code>dwtest()</code> from the lmtest package also returns the p-value, with no need for tables.</p>



<script type="application/ld+json">{"@context": "https://schema.org", "@type": "FAQPage", "mainEntity": [{"@type": "Question", "name": "What is the difference between multicollinearity and autocorrelation?", "acceptedAnswer": {"@type": "Answer", "text": "Multicollinearity concerns the explanatory variables, correlated with each other; autocorrelation concerns the model's errors, correlated over time. The first makes the coefficients unstable and is measured with the VIF; the second makes the standard errors too optimistic and is checked with the Durbin-Watson test."}}, {"@type": "Question", "name": "What is the difference between heteroscedasticity and multicollinearity?", "acceptedAnswer": {"@type": "Answer", "text": "Heteroscedasticity concerns the errors, whose variance is not constant; multicollinearity concerns the predictors, which are strongly correlated. With heteroscedasticity the coefficients are fine but the classical standard errors are wrong; with multicollinearity the standard errors are honestly large because the data can't separate the effects."}}, {"@type": "Question", "name": "What is the difference between heteroscedasticity and autocorrelation?", "acceptedAnswer": {"@type": "Answer", "text": "Both concern the model's errors and leave the coefficients correct on average. Heteroscedasticity is about their spread, which changes from one observation to another; autocorrelation is about their link over time. They can occur together, and Newey-West standard errors account for both."}}, {"@type": "Question", "name": "How do we avoid these problems in a marketing or advertising ROI regression model?", "acceptedAnswer": {"@type": "Answer", "text": "For multicollinearity, avoid moving all channels together, or use experiments that vary one channel at a time; otherwise model total spend. For heteroscedasticity, use logarithms when effects are proportional, or robust standard errors. For autocorrelation in weekly data, add seasonality and trend to the model and use Newey-West standard errors."}}, {"@type": "Question", "name": "What VIF value indicates multicollinearity?", "acceptedAnswer": {"@type": "Answer", "text": "There is no universal threshold. The most widespread rule of thumb considers a VIF above 5 worth watching and above 10 serious. A VIF of 10 means the variance of the coefficient is ten times what it would be with independent predictors."}}, {"@type": "Question", "name": "What should the Durbin-Watson statistic be?", "acceptedAnswer": {"@type": "Answer", "text": "About 2 with no autocorrelation. Values close to 0 indicate positive autocorrelation, values close to 4 negative autocorrelation. In R, dwtest() from the lmtest package also returns the p-value, with no need for tables."}}]}</script>



<h2 class="wp-block-heading" id="try-it-yourself">Try it yourself</h2>



<p class="wp-block-paragraph">The article&#8217;s code lends itself to a few experiments.</p>



<ul class="wp-block-list"><li>In the <code>simulate()</code> function, raise the standard deviation of Meta&#8217;s noise from 0.08 to 0.40, so the two budgets move more independently. What happens to the VIF? And to the share of negative Meta estimates in the 500 repetitions?</li><li>Set <code>ar = 0</code> in <code>arima.sim()</code>: does the Durbin-Watson statistic go back close to 2? And do the Newey-West standard errors get close to the classical ones?</li><li>Fit the log model with both channels, <code>lm(log(conversions) ~ log(google) + log(meta))</code>: does multicollinearity disappear with logarithms?</li></ul>



<p class="wp-block-paragraph">The last exercise has an instructive answer: transformations cure heteroscedasticity, but not multicollinearity. If the two budgets move together, so do their logarithms.</p>



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



<p class="wp-block-paragraph">With this we have the tools to trust (or not trust) a regression. It&#8217;s time to put them to work on a very concrete SEO problem: building a model of the CTR we expect at each position, and using it to find the pages that perform worse than they should. That&#8217;s the topic of <a href="https://www.gironi.it/blog/en/expected-vs-actual-ctr/">expected vs actual CTR</a>, the next stop on our journey.</p>



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



<h3 class="wp-block-heading" id="further-reading">Further reading</h3>



<p class="wp-block-paragraph">The three problems we discussed are covered in depth in <a href="https://www.amazon.it/dp/8891906190?tag=consulenzeinf-21&amp;ascsubtag=multicollinearity-heteroscedasticity-autocorrelation" rel="nofollow sponsored noopener" target="_blank"><em>Introduzione all&#8217;econometria</em></a> by Stock and Watson (Italian edition), the book I recommend: it devotes very clear pages to heteroscedasticity-robust standard errors and to Newey-West errors for time series, always starting from concrete economic examples.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gironi.it/blog/en/multicollinearity-heteroscedasticity-autocorrelation-three-difficult-sounding-concepts-explained-simply/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Correlation and Simple Linear Regression: the Line, Pearson&#8217;s r and R²</title>
		<link>https://www.gironi.it/blog/en/correlation-and-regression-analysis-linear-regression/</link>
					<comments>https://www.gironi.it/blog/en/correlation-and-regression-analysis-linear-regression/#respond</comments>
		
		<dc:creator><![CDATA[paolo]]></dc:creator>
		<pubDate>Tue, 25 Aug 2020 10:10:00 +0000</pubDate>
				<category><![CDATA[statistics]]></category>
		<category><![CDATA[coefficiente di determinazione]]></category>
		<category><![CDATA[correlazione]]></category>
		<category><![CDATA[grafico dispersione]]></category>
		<category><![CDATA[r di pearson]]></category>
		<category><![CDATA[regressione]]></category>
		<category><![CDATA[residui]]></category>
		<category><![CDATA[scatterplot]]></category>
		<guid isPermaLink="false">https://www.gironi.it/blog/?p=3340</guid>

					<description><![CDATA[The hotter it gets, the more ice cream sells: we all suspect as much. But by how much? If tomorrow the thermometer reads 27 degrees, how many ice creams should we get ready? And, moving onto our own ground: if we raise the campaign budget, how many extra conversions can we expect? Concepts such as &#8230; <a href="https://www.gironi.it/blog/en/correlation-and-regression-analysis-linear-regression/" class="more-link">Continue reading<span class="screen-reader-text"> "Correlation and Simple Linear Regression: the Line, Pearson&#8217;s r and R²"</span></a>]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">The hotter it gets, the more ice cream sells: we all suspect as much. But <em>by how much</em>? If tomorrow the thermometer reads 27 degrees, how many ice creams should we get ready? And, moving onto our own ground: if we raise the campaign budget, how many extra conversions can we expect?</p>



<p class="wp-block-paragraph">Concepts such as the <a href="https://www.gironi.it/blog/en/descriptive-statistics-measures-of-position-and-central-tendency/">mean</a> or the <a href="https://www.gironi.it/blog/en/descriptive-statistics-measures-of-variability-or-dispersion/#standard-deviation">standard deviation</a> describe one variable at a time. Questions like these, instead, require us to <strong>look at two variables together</strong>: that is the job of <strong>correlation</strong> and <strong>simple linear regression</strong>, two of the most widely used (and most misunderstood) tools in data analysis.</p>



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



<p class="wp-block-paragraph"><strong>In short:</strong> <strong>simple linear regression</strong> describes the relationship between a dependent variable y and a single independent variable x with a straight line, y = b + m·x, chosen by the <strong>least squares method</strong> (the line that minimises the sum of squared residuals). The slope m tells us how much y changes on average when x increases by one unit. <strong>Pearson&#8217;s correlation coefficient r</strong>, between −1 and +1, measures the strength and direction of the linear relationship; the <strong>coefficient of determination R²</strong> is the share of the variability of y explained by the model (with a single predictor, R² = r²). A strong correlation does not prove cause and effect. In R we use <code>cor()</code> and <code>lm()</code>.</p>



<div style="border: 1px solid #ccc;padding: 1.2em 1.5em;margin: 1.5em 0;border-radius: 6px">
<h3 style="margin-top: 0">Contents</h3>
<ul>
<li><a href="#simple-linear-regression">What is simple linear regression?</a></li>
<li><a href="#pearson-correlation-coefficient">How do we calculate Pearson&#8217;s correlation coefficient?</a></li>
<li><a href="#coefficient-of-determination-r2">What does the coefficient of determination R&sup2; measure?</a></li>
<li><a href="#finding-the-regression-equation">How do we find the regression line?</a></li>
<li><a href="#case-study-ad-spend-conversions">A case study: ad spend and conversions</a></li>
<li><a href="#outliers-influential-points">Outliers and influential points</a></li>
<li><a href="#model-assumptions">Model assumptions</a></li>
<li><a href="#residual-analysis">Residual analysis</a></li>
<li><a href="#practical-difficulties">Practical difficulties</a></li>
<li><a href="#other-correlation-coefficients">Other correlation coefficients</a></li>
<li><a href="#try-it-yourself">Try it yourself</a></li>
<li><a href="#faq">Frequently asked questions</a></li>
</ul>
</div>



<h2 class="wp-block-heading" id="simple-linear-regression">What Is Simple Linear Regression?</h2>



<p class="wp-block-paragraph">We can consider <strong>regression</strong> as a method suitable for finding a mathematical relationship that expresses a link between a variable y (the <em><strong>dependent variable</strong></em> or <em><strong>response variable</strong></em>) and a variable x (the <em><strong>independent variable</strong></em> or <em><strong>predictor variable</strong></em>).</p>



<p class="wp-block-paragraph"><strong>The first useful step to qualitatively investigate the possible dependence between two variables x and y is always to draw a graph, called a scatter diagram (<em>scatterplot</em>).</strong></p>



<p class="wp-block-paragraph">We place the data relating to one of the two variables on the abscissa, the data relating to the other variable on the ordinate, and we represent the individual observations with points. Remember that scatter plots compare two variables.</p>



<p class="wp-block-paragraph">If there is a simple relationship between the two variables, the diagram should show it!</p>



<p class="wp-block-paragraph">Let&#8217;s use some example values and let R draw our scatter diagram.</p>



<p class="wp-block-paragraph">I put some imaginary data in a CSV file relating to a hypothetical correlation between the ambient temperature recorded in my city and the sales of ice cream. I name the file <em>gelati.csv</em> and save it as plain text in any folder on my filesystem (in my example in <em>tmp/gelati.csv</em>). The file will have this content:</p>



<pre class="wp-block-code"><code>temperatura,gelati
25,58
30,70
29,61
26,53
25,48
28,66
24,47
22,47
20,40
18,29
22,33</code></pre>



<p class="wp-block-paragraph">Now I open R Studio and load my dataset:</p>



<pre class="wp-block-code"><code>gelati &lt;- read.csv("/tmp/gelati.csv")</code></pre>



<p class="wp-block-paragraph">Then I plot the scatterplot to see if the figure is compatible with a linear regression hypothesis:</p>



<pre class="wp-block-code"><code>plot(gelati)</code></pre>



<figure class="wp-block-image size-large is-resized"><img fetchpriority="high" decoding="async" width="855" height="540" src="https://www.gironi.it/blog/wp-content/uploads/2020/08/diagramma-a-dispersione.png" alt="Scatterplot" class="wp-image-1810" srcset="https://www.gironi.it/blog/wp-content/uploads/2020/08/diagramma-a-dispersione.png 855w, https://www.gironi.it/blog/wp-content/uploads/2020/08/diagramma-a-dispersione-300x189.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /><figcaption class="wp-element-caption">The scatter diagram representing the variables temperature and number of ice creams sold.</figcaption></figure>



<p class="wp-block-paragraph">The diagram shows an evident linear correlation, with an upward trend.</p>



<h2 class="wp-block-heading" id="pearson-correlation-coefficient">How Do We Calculate Pearson&#8217;s Correlation Coefficient?</h2>



<p class="wp-block-paragraph">There are various types of correlation coefficients in statistics. <strong>If the relationship to be investigated is between two <a href="https://www.gironi.it/blog/en/the-data-the-4-scales-of-measurement/" class="rank-math-link">variables of interval or ratio type</a> (i.e., quantitative, numerical variables), the best known and most used is certainly Pearson&#8217;s correlation coefficient</strong>, generally indicated with the letter <em>r</em>.</p>



<p class="wp-block-paragraph">I use the R language (not to be confused with the coefficient <em>r</em>) for a practical example with Pearson&#8217;s correlation coefficient.<br>The function to use is cor():</p>



<pre class="wp-block-code"><code>cor(gelati$temperatura,gelati$gelati)

[1] 0.9320279</code></pre>



<p class="wp-block-paragraph">As you can see, the correlation in this example is very strong.</p>



<p class="wp-block-paragraph"><em><strong>r</strong></em> is a <strong>standardized value ranging from +1 to -1</strong>. The further it is from zero and closer to 1 (or -1 in the case of negative correlation), the stronger the correlation.</p>



<p class="has-light-gray-background-color has-background wp-block-paragraph">If r is positive, the correlation is positive, meaning y increases as x increases.<br>If r is negative, y decreases as x increases.</p>



<p class="wp-block-paragraph">But when can I say that a correlation is strong or very strong, and when is it moderate or even null? The answer is&#8230; it depends 🙂<br>There is no standard answer. Very arbitrarily, we can say that generally a correlation below 0.20 (or better, between -0.2 and +0.2) is considered very weak, between 0.2 and 0.5 (or between -0.2 and -0.5) moderate, between 0.5 and 0.8 (or between -0.5 and -0.8) quite strong. Correlations higher than 0.8 or lower than -0.8, very strong, are actually quite rare.</p>



<p class="wp-block-paragraph"><strong><em>CAUTION 1</em></strong>: <strong>The most important thing is that the evidence of a relationship between two variables does not necessarily imply the presence of a cause-effect relationship between the two variables. This is a point of utmost importance, which must always be kept in mind. </strong>Both variables that in my study show a very strong correlation may actually depend on a third variable, or many other variables, which constitute the real cause. Finding and calculating the correlation between two variables is relatively simple; finding and especially proving a cause-and-effect relationship is extremely complex!</p>



<p class="wp-block-paragraph"><strong><em>CAUTION 2:</em></strong> Another point I would like to emphasize is that <strong>Pearson&#8217;s correlation coefficient r measures the linear correlation</strong> between two variables. This means that two variables can show an apparent null correlation (<em>r</em> around 0) and yet be correlated, for example showing a <strong>curvilinear correlation</strong>. A classic textbook example concerns the correlation between stress level and performance in an exam. In fact, a slight stress contributes to improving performance, but beyond a certain threshold it is completely harmful, leading to a decline in the result. In this case, the analysis in terms of r and linear correlation would lead to discarding an existing correlation.</p>



<div class="wp-block-group bordo has-light-gray-background-color has-background"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<p><b>And now some math (but just a little)</b></p>



<p class="wp-block-paragraph">Pearson&#8217;s correlation coefficient for a population, given two variables X and Y, is indicated by the Greek letter rho and is given by:</p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
\(
\\
\rho_{X,Y}=\frac{COV(X,Y)}{\sigma_X \sigma_Y}
\\
\)



<p>where:</p>
<ul>
<li>COV indicates the covariance</li>
<li>&sigma;<sub>X</sub> is the <a href="https://www.gironi.it/blog/en/descriptive-statistics-measures-of-variability-or-dispersion/#standard-deviation">standard deviation</a> of X</li>
<li>&sigma;<sub>Y</sub> is the <a href="https://www.gironi.it/blog/en/descriptive-statistics-measures-of-variability-or-dispersion/#standard-deviation">standard deviation</a> of Y</li>
</ul>



<p class="wp-block-paragraph">To calculate the population covariance (which, we recall, is a <em>non-standardized</em> measure of the direction and strength of the relationship between the elements of two populations):</p>



\(
\sigma_{XY}=\frac{\sum\limits_{i=1}^n (X_i-\mu_x)(Y_i-\mu_y)}{n}
\
\)



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



<ul>
<li>μ<sub>x</sub> is the population mean for x</li>
<li>μ<sub>y</sub> is the population mean for y</li>
<li>n is the number of elements in both variables</li>
<li>i is the index ranging from 1 to n</li>
<li>X<sub>i</sub> is a single element of population x</li><li>Y<sub>i</sub> is a single element of population y</li></ul>



<p class="wp-block-paragraph"><strong>Note</strong>: when we work on a sample and want to estimate the population covariance, the denominator is <em>n-1</em>.<br>R always uses the sample versions of covariance and standard deviation; for Pearson&#8217;s r, however, the choice changes nothing, because n-1 appears both above and below the fraction and cancels out.</p>



<p class="wp-block-paragraph"><strong>I take out the calculator &#8211; or paper and pen &#8211; and do some calculations&#8230;</strong></p>



<p class="wp-block-paragraph">This is my table, which I completed by computing the various values:</p>



<table border=1 style="font-size:11px!important">
<tr> <th> </th> <th> temperatura </th> <th> gelati </th> <th> x<sub>i</sub> − x̄ </th> <th> y<sub>i</sub> − ȳ </th> <th> (x<sub>i</sub> − x̄)·(y<sub>i</sub> − ȳ)</th> </tr>
<tr> <td align="right"> 1 </td> <td align="right"> 25 </td> <td align="right"> 58 </td> <td align="right"> 0.55 </td> <td align="right"> 7.82 </td> <td align="right"> 4.26 </td> </tr>
<tr> <td align="right"> 2 </td> <td align="right"> 30 </td> <td align="right"> 70 </td> <td align="right"> 5.55 </td> <td align="right"> 19.82 </td> <td align="right"> 109.90 </td> </tr>
<tr> <td align="right"> 3 </td> <td align="right"> 29 </td> <td align="right"> 61 </td> <td align="right"> 4.55 </td> <td align="right"> 10.82 </td> <td align="right"> 49.17 </td> </tr>
<tr> <td align="right"> 4 </td> <td align="right"> 26 </td> <td align="right"> 53 </td> <td align="right"> 1.55 </td> <td align="right"> 2.82 </td> <td align="right"> 4.36 </td> </tr>
<tr> <td align="right"> 5 </td> <td align="right"> 25 </td> <td align="right"> 48 </td> <td align="right"> 0.55 </td> <td align="right"> -2.18 </td> <td align="right"> -1.19 </td> </tr>
<tr> <td align="right"> 6 </td> <td align="right"> 28 </td> <td align="right"> 66 </td> <td align="right"> 3.55 </td> <td align="right"> 15.82 </td> <td align="right"> 56.08 </td> </tr>
<tr> <td align="right"> 7 </td> <td align="right"> 24 </td> <td align="right"> 47 </td> <td align="right"> -0.45 </td> <td align="right"> -3.18 </td> <td align="right"> 1.45 </td> </tr>
<tr> <td align="right"> 8 </td> <td align="right"> 22 </td> <td align="right"> 47 </td> <td align="right"> -2.45 </td> <td align="right"> -3.18 </td> <td align="right"> 7.81 </td> </tr>
<tr> <td align="right"> 9 </td> <td align="right"> 20 </td> <td align="right"> 40 </td> <td align="right"> -4.45 </td> <td align="right"> -10.18 </td> <td align="right"> 45.36 </td> </tr>
<tr> <td align="right"> 10 </td> <td align="right"> 18 </td> <td align="right"> 29 </td> <td align="right"> -6.45 </td> <td align="right"> -21.18 </td> <td align="right"> 136.72 </td> </tr>
<tr> <td align="right"> 11 </td> <td align="right"> 22 </td> <td align="right"> 33 </td> <td align="right"> -2.45 </td> <td align="right"> -17.18 </td> <td align="right"> 42.17 </td> </tr>
</table>



<p class="wp-block-paragraph">The sum of the values in the last column is 456.0909.</p>



<p class="wp-block-paragraph">So I can calculate the covariance by dividing by n-1 = 10, therefore:<br>456.0909/10 = 45.60909</p>



<p class="wp-block-paragraph">Calculating the sample standard deviations for X and Y, I find the values:</p>



<p class="wp-block-paragraph">S<sub>x</sub> = 3.751363<br>S<sub>y</sub> = 13.04468</p>



<p class="wp-block-paragraph">So S<sub>x</sub> * S<sub>y</sub> = 48.9353299</p>



<p class="wp-block-paragraph">Last step. <strong>I can calculate r</strong>:</p>



<p class="wp-block-paragraph">45.60909 / 48.9353299 = 0.9320278435</p>



<p class="wp-block-paragraph">which, as you can see, perfectly coincides with the value provided by R&#8217;s cor() function.</p>
</div></div>
</div></div>



<h2 class="wp-block-heading" id="coefficient-of-determination-r2">What Does the Coefficient of Determination R<sup>2</sup> Measure?</h2>



<p class="wp-block-paragraph">By squaring <em><strong>r</strong></em>, we obtain the <strong>coefficient of determination</strong>.</p>



<p class="wp-block-paragraph">In our case, the coefficient of determination r<sup>2</sup> will be:</p>



<pre class="wp-block-code"><code>R-squared = 0.86868</code></pre>



<p class="wp-block-paragraph">But what does this number mean?</p>



<p class="wp-block-paragraph">r<sup>2</sup> tells us to what extent our regression equation reproduces the variance of the data.<br>In other words, how much of the variation in the response variable is explained by the predictor variable. The more accurate the regression equation, the more the value of r<sup>2</sup> tends to 1.</p>



<p class="has-light-gray-background-color has-background wp-block-paragraph">With a single predictor, the coefficient of determination is literally the square of r: 0.932² = 0.869. Temperature therefore explains about <strong>87% of the variability</strong> in sales, and the remaining 13% comes from everything the model cannot see.<br>With more predictors the equality no longer holds, and R² grows every time a variable is added, even a useless one: that is why <a href="https://www.gironi.it/blog/en/multiple-regression-analysis-explained-simply/">multiple regression</a> looks at the adjusted R².</p>



<h2 class="wp-block-heading" id="finding-the-regression-equation">How Do We Find the Regression Line?</h2>



<p class="wp-block-paragraph">Our goal is to obtain the regression equation, and since it is a linear regression, the typical form will be:</p>



<pre class="wp-block-code"><code>y = mx + b</code></pre>



<p class="wp-block-paragraph">m indicates the slope of the line in the graph, and is called the <strong>regression coefficient</strong>.</p>



<p class="wp-block-paragraph">b is the point where the line intersects the y-axis, and is called the <strong>intercept</strong>.</p>



<p class="wp-block-paragraph">Always remember that the linear regression line is the line that best fits the data provided. Ideally, we would like to minimize the distances of all data points from the regression line. These distances are called <strong>errors</strong> and are also known as <strong>residuals</strong>. A good line will have small residuals.</p>



<p class="wp-block-paragraph">We fit the regression line to the data points in a scatter plot using the <strong>least squares method</strong>.</p>



<p class="wp-block-paragraph">The calculations are not difficult, and they are worth seeing once. The slope is the ratio between the covariance of x and y and the variance of x; equivalently, it is the correlation r «translated back» into the units of the two variables:</p>



\( m = \frac{COV(X,Y)}{s_X^2} = r \cdot \frac{s_Y}{s_X} \)



<p class="wp-block-paragraph">The intercept then follows from requiring the line to pass through the centre of the cloud, that is through the pair of means:</p>



\( b = \bar{y} &#8211; m \cdot \bar{x} \)



<p class="wp-block-paragraph">With the numbers already computed in the box on Pearson&#8217;s coefficient: m = 0.932 × 13.045 / 3.751 = <strong>3.241</strong> and b = 50.18 − 3.241 × 24.45 = <strong>−29.07</strong>. In practice, though, nobody does these sums by hand: every advanced scientific calculator and spreadsheet has a dedicated function, and in R the process is even easier.</p>



<p class="wp-block-paragraph">I proceed by calculating the parameters of the regression line:</p>



<pre class="wp-block-code"><code># calculate the parameters of the regression line
lm(gelati$gelati ~ gelati$temperatura)

Call: lm(formula = gelati$gelati ~ gelati$temperatura)
Coefficients:
(Intercept) gelati$temperatura
-29.074 3.241</code></pre>



<p class="wp-block-paragraph">So my line will have the equation:</p>



<pre class="wp-block-code"><code><strong>y = 3.241x - 29.074</strong></code></pre>



<p class="wp-block-paragraph">Let&#8217;s read it: <strong>each extra degree is worth, on average, about 3.2 more ice creams sold</strong>. And the question we started with gets its answer: at 27 degrees the model predicts 3.241 × 27 − 29.07 ≈ <strong>58 ice creams</strong>.<br>The intercept, on the other hand, should not be taken literally: at zero degrees the line predicts −29 ice creams, which makes no sense. The reason is simple: the data contain no day below 18 degrees, and outside the observed range the line knows nothing. We will come back to this when we talk about <em>extrapolation</em>.</p>



<p class="wp-block-paragraph">It&#8217;s time to plot the scatter diagram again, overlapping the regression line I just found:</p>



<pre class="wp-block-code"><code># draw the scatterplot
plot(gelati$temperatura,gelati$gelati, main="Scatterplot and Regression Line",xlab="temperature", ylab="gelati")

# and draw the regression line in red
abline(lm(gelati$gelati ~ gelati$temperatura),col="red",lwd=2)</code></pre>



<figure class="wp-block-image size-large is-resized"><img decoding="async" width="855" height="540" src="https://www.gironi.it/blog/wp-content/uploads/2020/08/regressione-lineare.png" alt="Linear Regression: simple regression line" class="wp-image-1816" srcset="https://www.gironi.it/blog/wp-content/uploads/2020/08/regressione-lineare.png 855w, https://www.gironi.it/blog/wp-content/uploads/2020/08/regressione-lineare-300x189.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /><figcaption class="wp-element-caption">The regression line superimposed on the scatter diagram.</figcaption></figure>



<h2 class="wp-block-heading" id="case-study-ad-spend-conversions">A Case Study: Ad Spend and Conversions</h2>



<p class="wp-block-paragraph">The ice-cream dataset has carried us this far, but let&#8217;s now take regression into the territory we actually care about: marketing. We have twelve weeks of Google Ads campaigns, and for each week we know the spend (in euros) and the conversions recorded. The question is the one every client asks us sooner or later: <strong>if I increase the budget, how many extra conversions can I expect?</strong></p>



<pre class="wp-block-code"><code>spend,conversions
120,15
150,14
95,11
180,22
210,20
160,18
140,13
250,26
190,17
230,25
110,13
175,16</code></pre>



<p class="wp-block-paragraph">I fit the model in R:</p>



<pre class="wp-block-code"><code>data &lt;- read.csv("/tmp/ads.csv")
model &lt;- lm(conversions ~ spend, data = data)
summary(model)

Coefficients:
            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)  1.93098    2.22949   0.866    0.407
spend        0.09295    0.01284   7.240 2.79e-05 ***

Multiple R-squared:  0.8398,    Adjusted R-squared:  0.8238</code></pre>



<p class="wp-block-paragraph">Let&#8217;s read the results carefully, because every number has something to tell us.</p>



<p class="wp-block-paragraph">The <strong>slope</strong> is 0.093: for every extra euro of spend, the model estimates 0.093 additional conversions. In plainer terms: <strong>one conversion roughly every 11 euros</strong>. Its p-value (2.79e-05) tells us the relationship is anything but random.</p>



<p class="wp-block-paragraph">The <strong>intercept</strong> is 1.93: that would be the expected conversions at zero spend. But mind its p-value (0.407): it is not statistically different from zero. The model, in other words, does not have enough data to tell us how much we would convert without campaigns &mdash; hardly surprising, since there is not a single zero-spend week in the dataset. Predictions outside the observed range (95&ndash;250 euros) remain slippery ground.</p>



<p class="wp-block-paragraph">The <strong>R<sup>2</sup> is 0.84</strong>: spend explains 84% of the variability in weekly conversions. The remaining 16% is everything the model cannot see: seasonality, ad quality, competition, rainy days.</p>



<p class="wp-block-paragraph">At this point, prediction is child&#8217;s play. How many conversions at 200 euros of spend? I compute it in R:</p>



<pre class="wp-block-code"><code>predict(model, data.frame(spend = 200))
# 20.52</code></pre>



<p class="wp-block-paragraph"><strong>One warning before taking this number into a meeting.</strong> Regression describes an <em>association</em>; it does not prove a cause. If the budget was raised precisely in the high-demand weeks (sales, seasonality), part of that slope belongs to demand, not to the campaigns. Establishing a causal link requires a controlled experiment &mdash; which is exactly what <a href="https://www.gironi.it/blog/en/guide-to-statistical-tests-for-a-b-analysis/">A/B testing</a> is for.</p>



<h2 class="wp-block-heading" id="outliers-influential-points">Outliers and Influential Points</h2>



<p class="wp-block-paragraph">An outlier is an extreme observation that does not fit the general correlation or regression pattern. In practice, in our graph we will see that such outliers, if any, will be very far from the regression line in the y direction.<br>The inclusion of an outlier can affect the slope and y-intercept of the regression line.</p>



<p class="wp-block-paragraph">When examining a scatter plot and calculating the regression equation, it is worth considering whether or not anomalous observations should be included. They could in fact be errors in the data – and then they should be excluded – but also “real” values, and in this case they are information of the utmost importance for the analyst.</p>



<p class="wp-block-paragraph"><strong>But when can we speak of outliers?</strong> There is no fixed rule when trying to decide whether or not to include an outlier in the regression analysis. This decision depends on the sample size, how extreme the outlier is, and the normality of the distribution.<br><br>For univariate data, an <strong>empirical rule based on the <a href="https://www.gironi.it/blog/en/descriptive-statistics-measures-of-position-and-central-tendency/" class="rank-math-link">interquartile range IQR</a></strong> can be used to determine whether or not a point is an outlier.<br><br>We proceed in this way:</p>



<ul class="wp-block-list">
<li>Calculate the interquartile range for our data.</li>



<li>Multiply the interquartile range (IQR) by 1.5.</li>



<li>Add 1.5 x (IQR) to the third quartile.<br>Any number greater than the value found is a suspected extreme datum.</li>



<li>Subtract 1.5 x (IQR) from the first quartile. Any number lower is a suspected extreme datum.</li>
</ul>



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



<p class="wp-block-paragraph">An <strong>influential point</strong> is a point that, if removed, produces a significant change in the model estimate. <strong>An influential point may or may not be an outlier</strong>.</p>



<p class="wp-block-paragraph">The influence.measures() command provides a whole series of useful influence measures: dfbeta, dffit, covratio, Cook&#8217;s distance and leverage points of all observations:</p>



<pre class="wp-block-code"><code># measure influential points
influence.measures(lm(gelati$gelati ~ gelati$temperatura))</code></pre>



<h2 class="wp-block-heading" id="model-assumptions">Model Assumptions</h2>



<p class="wp-block-paragraph">For the linear regression model to be effectively usable, some assumptions must be met:</p>



<ul class="wp-block-list">
<li><strong>Linearity</strong>: the relationship between X and Y really is a straight line, not a curve.</li>



<li><strong>Normal distribution of errors</strong>: the errors must have, for each value of X, a normal distribution.</li>



<li><strong>Homoscedasticity</strong>: the variability of the errors is constant for each value of X.</li>



<li><strong>Independence of errors</strong>: the errors must be independent for each value of X (it is especially important for observations over time, in which it must be verified that there is no autocorrelation).</li>
</ul>



<p class="has-dark-gray-color has-light-gray-background-color has-text-color has-background wp-block-paragraph">The assumptions must <strong>always be checked</strong>, but they do not all carry the same weight. Without linearity, the line itself is wrong. With <em>heteroscedasticity</em> or <em>serial correlation</em> the coefficient estimates are still right on average, but standard errors, p-values and confidence intervals become unreliable. <em>Non-normal residuals</em>, finally, matter mostly in small samples.<br>We look at the remedies in the article on <a href="https://www.gironi.it/blog/en/multicollinearity-heteroscedasticity-autocorrelation-three-difficult-sounding-concepts-explained-simply/">regression diagnostics</a>.</p>



<h2 class="wp-block-heading" id="residual-analysis">Residual Analysis</h2>



<p class="wp-block-paragraph">The <strong>residual</strong> is equal to the difference between the observed value and the predicted value of Y.</p>



<ul class="wp-block-list">
<li>To estimate the goodness of fit of the regression line to the data, a graphical analysis is appropriate using a scatter plot of the residuals (on the ordinate) and the values of X (on the abscissa).<br> </li>



<li>To verify the assumptions, I can evaluate the <strong>graph of the residuals with respect to X</strong>: this allows us to establish whether the variability of the errors varies according to the values of X, confirming or not the <strong>assumption of homoscedasticity</strong>.<br> </li>



<li>To verify linearity, plot the residuals, on the ordinate, with respect to the predicted values, on the abscissa. The points should be distributed symmetrically around a horizontal line with an intercept equal to zero. Different trends indicate the presence of non-linearity.</li>
</ul>



<pre class="wp-block-code"><code># look at the distribution of residuals.
# must be balanced above and below the zero line.
lmgelati &lt;- lm(gelati$gelati ~ gelati$temperatura)
plot (lmgelati$residual ~ lmgelati$fitted, ylab="Residuals",
xlab="Fitted")
abline(h=0)</code></pre>



<figure class="wp-block-image size-large is-resized"><img decoding="async" width="855" height="540" src="https://www.gironi.it/blog/wp-content/uploads/2020/08/linearita-residui.png" alt="graph of residuals linearity" class="wp-image-1830" srcset="https://www.gironi.it/blog/wp-content/uploads/2020/08/linearita-residui.png 855w, https://www.gironi.it/blog/wp-content/uploads/2020/08/linearita-residui-300x189.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /><figcaption class="wp-element-caption">The graph of residuals with respect to predicted values.</figcaption></figure>



<p class="wp-block-paragraph">R&#8217;s <em>lmtest</em> package provides us with the Breusch-Pagan test to verify the homoscedasticity of the residuals:</p>



<pre class="wp-block-code"><code># check homoscedasticity of residuals
# using the Breusch-Pagan test
library(lmtest)
testbp &lt;- bptest(gelati ~ temperatura, data=gelati)
testbp

# BP = 0.33208, df = 1, p-value = 0.5644</code></pre>



<p class="wp-block-paragraph">The p-value of 0.56 gives us no reason to reject the null hypothesis of homoscedasticity: the variability of the residuals looks constant.</p>



<p class="wp-block-paragraph">As for the <strong>normality of the residuals</strong>, the <strong>frequency histogram</strong> allows us to verify or not the condition.</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" width="855" height="540" src="https://www.gironi.it/blog/wp-content/uploads/2020/08/residui-normalita.png" alt="Histogram of residuals" class="wp-image-1820" srcset="https://www.gironi.it/blog/wp-content/uploads/2020/08/residui-normalita.png 855w, https://www.gironi.it/blog/wp-content/uploads/2020/08/residui-normalita-300x189.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /><figcaption class="wp-element-caption">The verification of normality of residuals in our example, using a histogram.</figcaption></figure>



<p class="wp-block-paragraph">We can also verify the normality of the residuals numerically, using a Shapiro-Wilk test:</p>



<pre class="wp-block-code"><code># check the normality of the distribution of errors
# with the Shapiro-Wilk test
residui &lt;- residuals(lm(gelati$gelati ~ gelati$temperatura))
shapiro &lt;- shapiro.test(residui)
shapiro

# W = 0.93844, p-value = 0.5023</code></pre>



<p class="wp-block-paragraph">A check that is often suggested, the t-test on the mean of the residuals, is actually pointless: when the model has an intercept, least squares produces residuals whose mean is <em>exactly</em> zero by construction, whatever the data.</p>



<p class="wp-block-paragraph">The <strong>graph of the residuals with respect to time</strong> (and the use of the <em>Durbin-Watson</em> statistic) allows us to highlight the existence or not of <strong>autocorrelation</strong>.</p>



<pre class="wp-block-code"><code># Durbin-Watson test for autocorrelation
dwtest(gelati ~ temperatura, data=gelati)

# DW = 1.3644, p-value = 0.07275</code></pre>



<p class="wp-block-paragraph">The test only makes sense when the observations are in time order (days, weeks): with data that have no natural order, autocorrelation has no meaning. Here the p-value of 0.07 stays above the 5% threshold.</p>



<h2 class="wp-block-heading" id="practical-difficulties">Regression Analysis: Practical Difficulties</h2>



<p class="wp-block-paragraph">Simple regression analysis is a widely used model, but very, very insidious. The generalized tendency, in fact, is to use this type of analysis in a not very conscious and rigorous way – as for example in the simplified example I proposed 🙂<br>The assumptions underlying the model are rather stringent, and very often ignored&#8230;</p>



<p class="wp-block-paragraph">Frequently, the analysis is carried out without taking into account the way in which these assumptions must be evaluated or the simple linear regression model is chosen instead of more appropriate alternative models.</p>



<p class="wp-block-paragraph">Another very common error is given by <strong>extrapolation</strong>: that is, <strong>an estimation of values external to the range of observed values is made</strong>. This is a big no-no.</p>



<p class="wp-block-paragraph">The advice is always to start the analysis by looking very carefully at the scatter diagram and to carefully verify the hypotheses underlying the regression model before using the results.</p>



<h2 class="wp-block-heading" id="other-correlation-coefficients">Other Types of Correlation Coefficients</h2>



<p class="wp-block-paragraph">Pearson&#8217;s correlation coefficient is certainly the best known, studied and used, but as we have seen it applies in cases where both variables are of quantitative type, measured through an interval or ratio scale. There are other methods that allow us to obtain the measure of correlation between variables of different types. All share the characteristic of being conceptually very similar to Pearson&#8217;s r coefficient.</p>



<h3 class="wp-block-heading">The Point-Biserial Correlation Coefficient</h3>



<p class="wp-block-paragraph">Let&#8217;s take the case of an analysis in which one of the variables is of quantitative type (measured on an interval or ratio scale) and the second is a <strong>categorical variable with two levels</strong> (or dichotomous variable). In this case, the <strong>point-biserial correlation coefficient</strong> comes to our aid. I will not delve into the concept here, as it is in fact a &#8220;special&#8221; version of Pearson&#8217;s coefficient, leaving the reader to deepen when required by the analysis.</p>



<h3 class="wp-block-heading">The Phi Coefficient</h3>



<p class="wp-block-paragraph">If we need to know if <strong>two dichotomous variables are correlated</strong>, we could then resort to the <strong>phi coefficient</strong>, another &#8220;special&#8221; case of Pearson&#8217;s r coefficient. Many readers will certainly know that two dichotomous variables can also be analyzed using a <a href="https://www.gironi.it/blog/en/the-chi-square-test-goodness-of-fit-and-test-of-independence/">chi-square test</a>.</p>



<h3 class="wp-block-heading">Spearman&#8217;s Rank Correlation Coefficient Rho (and a Note on Kendall&#8217;s Tau)</h3>



Sometimes the data are reported in terms of ranks. Ranks are a form of ordinal data, and since the other types of correlation coefficients do not treat this type of data, here is the need to introduce the use of Spearman&#8217;s rho coefficient.
Spearman&#8217;s correlation follows a simple and ingenious approach: it converts each data set into ranks and then calculates the correlation. It is a non-parametric statistical measure of correlation: the only assumption required is that the variables are sortable, and possibly continuous.
<p>
Here is the formula for Spearman&#8217;s coefficient:
</p>
\(
\\
r_s=1-\frac{6\sum{d}_i^2}{N(N^2-1)}
\\ \\
\)
<p>
where d<sub>i</sub> is the difference between the two ranks of the same observation and N the number of observations. r<sub>s</sub> can also assume values between –1.00 and +1.00, with the same meanings seen for r.
</p>
<p>
This shortcut formula is exact only when there are no tied ranks. With ties, Pearson&#8217;s correlation is computed directly on the ranks, which is what R does. With many ties or small samples, moreover, another statistic is often preferred: <b>Kendall&#8217;s <i>tau</i> coefficient</b>.
</p>



<p class="wp-block-paragraph">In R we do not need different functions: <code>cor()</code> computes all three coefficients, we just specify the method. Computing it in R, on our ice-cream example:</p>



<pre class="wp-block-code"><code>cor(gelati$temperatura, gelati$gelati, method = "pearson")   # 0.932
cor(gelati$temperatura, gelati$gelati, method = "spearman")  # 0.954
cor(gelati$temperatura, gelati$gelati, method = "kendall")   # 0.860</code></pre>



<p class="wp-block-paragraph">Spearman slightly exceeds Pearson: the relationship is <em>monotonic</em> (higher temperatures almost always go with higher sales) even more than it is linear. Kendall&#8217;s tau is lower because it measures something else (how much concordant pairs of observations outnumber discordant ones) and tends to give smaller values than Spearman: the two numbers should not be compared directly.</p>



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



<p class="wp-block-paragraph">To make the mechanism stick, here is an exercise with made-up but realistic data. From Search Console we extracted ten keywords with their average position and CTR (as a percentage):</p>



<pre class="wp-block-code"><code>position,ctr
1.2,28.4
2.5,19.7
3.1,15.2
4.8,9.8
5.5,8.1
6.9,5.9
8.2,4.2
9.0,3.6
10.5,2.8
12.3,1.9</code></pre>



<ul class="wp-block-list">
<li>Fit the regression line of CTR on position with <code>lm(ctr ~ position)</code>.</li>



<li>Interpret the slope: how many CTR points do we lose for each position dropped?</li>



<li>Predict the expected CTR at position 7.</li>



<li>Look at the residuals with <code>residuals()</code>: what pattern do they draw?</li>
</ul>



<p class="wp-block-paragraph">To check your results: the slope is about <strong>&minus;2.15</strong> (each lost position costs two CTR points), the R<sup>2</sup> is 0.82, and the prediction at position 7 is a CTR of <strong>8.7%</strong>. But the most instructive part is the last one: the residuals are positive at the extremes and negative in the middle. That is the typical signature of a <strong>non-linear relationship</strong>: CTR does not fall in a straight line &mdash; it plunges across the top positions and flattens out afterwards. The line is an honest but coarse approximation, and it is precisely the residuals, as we have seen, that give it away.</p>



<h2 class="wp-block-heading" id="faq">Frequently asked questions</h2>



<h3 class="wp-block-heading">What is the difference between correlation and regression?</h3>



<p class="wp-block-paragraph">Correlation measures how much two variables vary together and is symmetric: r between x and y equals r between y and x. Regression instead estimates an equation to predict one variable (the dependent one) from the other, and swapping the roles changes the line.</p>



<h3 class="wp-block-heading">What does an R² of 0.8 mean?</h3>



<p class="wp-block-paragraph">That the model explains 80% of the variability of the dependent variable; the remaining 20% depends on factors the model does not include, or on chance. A high R² does not guarantee that the model is right, nor that the relationship is causal: the residuals must always be checked.</p>



<h3 class="wp-block-heading">What is the least squares method?</h3>



<p class="wp-block-paragraph">It is the criterion used to choose the regression line: among all possible lines, the one that minimises the sum of the squared vertical distances (the residuals) between the observed points and the line itself.</p>



<h3 class="wp-block-heading">Does a strong correlation prove cause and effect?</h3>



<p class="wp-block-paragraph">No. Two variables can be strongly correlated because both depend on a third one, or by pure coincidence. Establishing a causal link requires a controlled experiment, such as an A/B test, or an analysis design built for the purpose.</p>



<h3 class="wp-block-heading">When should we use Spearman instead of Pearson?</h3>



<p class="wp-block-paragraph">When the data are ordinal (ranks, scores, rankings), when the relationship is monotonic but not linear, or when a few extreme values risk distorting Pearson. Spearman works on ranks and is much less sensitive to outliers.</p>



<h3 class="wp-block-heading">Simple or multiple linear regression?</h3>



<p class="wp-block-paragraph">Simple regression uses a single predictor, <a href="https://www.gironi.it/blog/en/multiple-regression-analysis-explained-simply/">multiple regression</a> two or more. When the variable to predict plausibly depends on several factors (spend, seasonality, device), simple regression risks attributing to a single predictor the effect of the others too.</p>



<script type="application/ld+json">{"@context": "https://schema.org", "@type": "FAQPage", "mainEntity": [{"@type": "Question", "name": "What is the difference between correlation and regression?", "acceptedAnswer": {"@type": "Answer", "text": "Correlation measures how much two variables vary together and is symmetric: r between x and y equals r between y and x. Regression instead estimates an equation to predict one variable (the dependent one) from the other, and swapping the roles changes the line."}}, {"@type": "Question", "name": "What does an R² of 0.8 mean?", "acceptedAnswer": {"@type": "Answer", "text": "That the model explains 80% of the variability of the dependent variable; the remaining 20% depends on factors the model does not include, or on chance. A high R² does not guarantee that the model is right, nor that the relationship is causal: the residuals must always be checked."}}, {"@type": "Question", "name": "What is the least squares method?", "acceptedAnswer": {"@type": "Answer", "text": "It is the criterion used to choose the regression line: among all possible lines, the one that minimises the sum of the squared vertical distances (the residuals) between the observed points and the line itself."}}, {"@type": "Question", "name": "Does a strong correlation prove cause and effect?", "acceptedAnswer": {"@type": "Answer", "text": "No. Two variables can be strongly correlated because both depend on a third one, or by pure coincidence. Establishing a causal link requires a controlled experiment, such as an A/B test, or an analysis design built for the purpose."}}, {"@type": "Question", "name": "When should we use Spearman instead of Pearson?", "acceptedAnswer": {"@type": "Answer", "text": "When the data are ordinal (ranks, scores, rankings), when the relationship is monotonic but not linear, or when a few extreme values risk distorting Pearson. Spearman works on ranks and is much less sensitive to outliers."}}, {"@type": "Question", "name": "Simple or multiple linear regression?", "acceptedAnswer": {"@type": "Answer", "text": "Simple regression uses a single predictor, multiple regression two or more. When the variable to predict plausibly depends on several factors (spend, seasonality, device), simple regression risks attributing to a single predictor the effect of the others too."}}]}</script>



<p class="wp-block-paragraph">One variable, after all, rarely tells the whole story: conversions depend on spend, but also on seasonality, device, brand strength. When the predictors become more than one, we enter the territory of <a href="https://www.gironi.it/blog/en/multiple-regression-analysis-explained-simply/">multiple regression</a> &mdash; the next step on this path.</p>



<h3 class="wp-block-heading">You might also like</h3>



<ul class="wp-block-list">
<li><a href="https://www.gironi.it/blog/en/multiple-regression-analysis-explained-simply/">Multiple Regression Analysis, Explained Simply</a></li>



<li><a href="https://www.gironi.it/blog/en/guide-to-statistical-tests-for-a-b-analysis/">Guide to Statistical Tests for A/B Analysis</a></li>



<li><a href="https://www.gironi.it/blog/en/hypothesis-testing-a-step-by-step-guide/">Hypothesis Testing: a Step-by-Step Guide</a></li>
</ul>



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



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



<p class="wp-block-paragraph">To study regression with the rigor it deserves &mdash; estimation, inference, diagnostics &mdash; <a href="https://www.amazon.it/dp/8891906190?tag=consulenzeinf-21&#038;ascsubtag=correlation-and-regression-analysis-linear-regression" rel="nofollow sponsored noopener" target="_blank"><em>Introduzione all&#8217;econometria</em></a> by Stock and Watson (Italian edition) is the reference textbook, with constant attention to the interpretation of results.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gironi.it/blog/en/correlation-and-regression-analysis-linear-regression/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
