Tutorials › Regression Analysis (Undergraduate) › When the Least-Squares Slope Is Zero

Fitting a Simple Linear Regression · Tutorial 92 of 991

When the Least-Squares Slope Is Zero

Use the slope formula to connect zero sample covariance to a horizontal fitted line, then examine what that result does—and does not—say about the relationship between the variables.

Beginner 9 min read

What You'll Learn

  • Define sample covariance using paired predictor and response observations
  • Show why zero sample covariance makes the least-squares slope zero when the predictor varies
  • Calculate a horizontal least-squares line from raw data
  • Recognize curved and irregular patterns that can have zero sample covariance
  • Distinguish absence of a linear trend in a sample from absence of any relationship

What Does a Zero Slope Tell Us?

A least-squares line summarizes a particular feature of paired data: the linear trend in the response as the predictor changes. Sometimes that fitted line is horizontal. This means the line’s predicted response is the same at every predictor value, but it does not necessarily mean that the observed responses are all alike or that the variables have no relationship.

The key quantity is the sample covariance. It measures whether observations with predictor values above their mean tend to have responses above their mean, and whether observations below their predictor mean tend to have responses below their response mean. Positive and negative contributions can balance exactly. When the sample covariance is zero and the predictor values vary, the least-squares slope is zero.

Definition: For \(n\) paired observations \((x_i,y_i)\), the sample covariance is $$ s_{xy}=\frac{\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})}{n-1}. $$ It is zero when the centered cross-products sum to zero. The least-squares slope is the slope of the line that minimizes the sum of squared vertical differences between the observed responses and the fitted responses.

For the slope formula used here, the predictor values must vary, so that \(\sum_{i=1}^{n}(x_i-\bar{x})^2>0\). The fitted line is written \(\hat{y}=b_0+b_1x\), where \(b_0\) is the intercept and \(b_1\) is the slope. The slope formula from centered data is

$$ b_1=\frac{\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})}{\sum_{i=1}^{n}(x_i-\bar{x})^2} =\frac{s_{xy}}{s_x^2}, $$

where \(s_x^2=\sum_{i=1}^{n}(x_i-\bar{x})^2/(n-1)\) is the sample variance of the predictor. The intercept is \(b_0=\bar{y}-b_1\bar{x}\). These are properties of the least-squares calculation on the observed data; they do not require a probability model or additional assumptions about how the observations were generated.

Why Zero Covariance Gives a Horizontal Line

If \(s_{xy}=0\), then the numerator in the slope formula is zero. Because the predictor varies, its centered sum of squares in the denominator is positive. Therefore the ratio is zero and \(b_1=0\). Substituting into the intercept formula gives \(b_0=\bar{y}\). Thus the fitted line is horizontal, at the sample mean of the responses.

Result: When the predictor values vary and the sample covariance is zero, the least-squares line is \(\hat{y}=\bar{y}\). Every fitted value is the sample mean response. This says the best-fitting straight line has no slope; it does not say that every observed response equals \(\bar{y}\).

The result follows directly from the centered-data slope formula. The numerator describes the net linear co-movement: each product is positive when \(x_i\) and \(y_i\) are on the same side of their respective means, and negative when they are on opposite sides. If the sum is zero, those contributions cancel. That cancellation removes the linear slope, even when the individual observations have a clear pattern that a straight line cannot describe.

Worked Example: A Curved Pattern With Zero Slope

Suppose a hypothetical experiment records a predictor \(x\), measured in hours, and a response \(y\), measured in score points. The five observed pairs are \((1,8),(2,5),(3,4),(4,5),(5,8)\). Find the least-squares line and describe what the zero slope means.

Check the predictor variation. The predictor values are not all equal, so the denominator of the slope formula is positive. Their mean is \(\bar{x}=(1+2+3+4+5)/5=3\). The response mean is \(\bar{y}=(8+5+4+5+8)/5=6\).

The centered predictor values are \(-2,-1,0,1,2\); the centered response values are \(2,-1,-2,-1,2\). Therefore

$$ \sum (x_i-\bar{x})(y_i-\bar{y}) =(-2)(2)+(-1)(-1)+(0)(-2)+(1)(-1)+(2)(2) =-4+1+0-1+4=0. $$

The centered predictor sum of squares is

$$ \sum (x_i-\bar{x})^2=(-2)^2+(-1)^2+0^2+1^2+2^2=10. $$

So \(b_1=0/10=0\) score points per hour. The intercept is \(b_0=6-(0)(3)=6\) score points, and the fitted line is \(\hat{y}=6\).

The observations are not all 6 points: the response is 4 at \(x=3\) and 8 at both \(x=1\) and \(x=5\). The pattern is curved, with lower values near the middle and higher values at the ends. The horizontal line summarizes the linear trend but does not capture that curved pattern.

Zero Covariance Does Not Mean No Relationship

Covariance focuses on linear co-movement, not every possible way one variable may change with another. A curved relationship can have observations above the response mean at both low and high predictor values, and observations below the response mean in the middle. The centered cross-products from the two ends may then cancel one another. This is why zero covariance can coexist with a structured, non-linear pattern.

The next example uses unevenly spaced predictor values and responses that are not arranged in a simple symmetric curve. The same calculation still applies: it is the sum of the centered cross-products, not the visual regularity of a pattern, that determines the slope.

Worked Example: An Irregular Pattern With a Horizontal Fit

In a hypothetical setting, let \(x\) be a setting measured in units and \(y\) be an output measured in response units. The observed pairs are \((0,6),(1,3),(2,6),(4,5),(7,5)\). Calculate the covariance numerator and the least-squares line.

The predictor mean is \(\bar{x}=(0+1+2+4+7)/5=14/5=2.8\). The response mean is \(\bar{y}=(6+3+6+5+5)/5=25/5=5\). The centered values are:

Observation\(x_i-\bar{x}\)\(y_i-\bar{y}\)Product
1-2.81-2.8
2-1.8-23.6
3-0.81-0.8
41.200
54.200

Adding the products gives \(-2.8+3.6-0.8+0+0=0\), so \(s_{xy}=0/(5-1)=0\). The predictor sum of squares is

$$ (-2.8)^2+(-1.8)^2+(-0.8)^2+(1.2)^2+(4.2)^2 =7.84+3.24+0.64+1.44+17.64=30.8. $$

Consequently \(b_1=0/30.8=0\) response units per predictor unit, and \(b_0=5-(0)(2.8)=5\) response units. The fitted line is \(\hat{y}=5\). The observed response still varies from 3 to 6, and the values change across the predictor range. The zero slope describes the straight-line fit, not the absence of response variation or every possible pattern.

Reading the Result Carefully

A horizontal least-squares line is useful when the goal is to describe the sample’s linear trend. It gives a clear summary: increasing the predictor does not correspond to an increase or decrease in the fitted response along that line. It does not establish that the response is constant, that the variables are unrelated in every sense, or that changing the predictor would have no effect. The last claim would be causal and cannot be inferred from this calculation alone.

It also matters that this is a sample calculation. A zero sample covariance says the cross-products in the observed data sum to zero. It does not, by itself, establish that a population covariance is zero. Nor does it demonstrate that a population relationship is absent. The conclusion should stay close to what was calculated: the least-squares line for these observations has a slope of zero.

Worked Example: Checking a Zero-Slope Claim From Summary Values

A hypothetical data summary gives \(n=6\), \(\bar{x}=10\) units, \(\bar{y}=24\) points, \(\sum (x_i-\bar{x})(y_i-\bar{y})=0\), and \(\sum (x_i-\bar{x})^2=20\) square units. The predictor values vary. Find the fitted line and state a suitable interpretation.

The slope is

$$ b_1=\frac{\sum (x_i-\bar{x})(y_i-\bar{y})}{\sum (x_i-\bar{x})^2} =\frac{0}{20}=0\text{ points per unit}. $$

The intercept is \(b_0=\bar{y}-b_1\bar{x}=24-(0)(10)=24\) points. Thus \(\hat{y}=24\), a horizontal line. For these observations, the fitted response is 24 points at every predictor value. This does not imply that all six observed responses equal 24 points; it only specifies the fitted values from the least-squares line.

Common Mistakes

  • “The slope is zero, so there is no relationship.” This confuses a lack of linear trend with a lack of any pattern. A curved relationship can have zero covariance and a horizontal least-squares line.
  • “A horizontal line means the responses are all equal.” A horizontal fitted line gives the same predicted response at each \(x\). The observed responses can still vary around that line.
  • “Zero covariance means the population covariance is zero.” The calculation concerns the observed sample. It does not automatically establish a population fact.
  • Ignoring units or context. A slope of zero means zero fitted response change per predictor unit for this line. It does not turn the calculation into a causal conclusion.
  • Dividing by zero without checking predictor variation. The slope formula requires a positive centered predictor sum of squares. If it is not positive, this ratio cannot be used; this tutorial’s zero-covariance result assumes the predictor values vary.
Key takeaway: With varying predictor values, zero sample covariance makes the least-squares slope zero and the fitted line equal to \(\bar{y}\). This rules out a nonzero linear slope in the sample, but it does not rule out curved patterns or other forms of association.

Check Your Understanding

Use the slope formula and distinguish what the fitted line says from what it does not say.

  1. If the predictor varies and \(\sum (x_i-\bar{x})(y_i-\bar{y})=0\), what is the least-squares slope? What is the intercept?
  2. For the data \((1,4),(2,1),(3,0),(4,1),(5,4)\), calculate \(\bar{x}\), \(\bar{y}\), and the covariance numerator. What is the fitted line?
  3. Can the observed responses vary when the least-squares line is horizontal? Explain briefly.
  4. Why is zero sample covariance not enough to conclude that the variables have no relationship of any kind?
  5. A horizontal least-squares line is found in a sample. What is one conclusion that is justified, and one conclusion that is not justified?