STATISTICAL WORKSHEETS

Comparing a flat response with a constant predictor in regression

A response list that never changes still produces a clean horizontal fitted line, while a predictor list that never changes leaves the slope undefined. This worksheet shows both cases and explains why they behave differently.

Two flat columns, two different outcomes

Linear regression fits a line y equals intercept plus slope times x to paired data. Two superficially similar situations behave very differently. If every y is the same while x varies, the best line is horizontal and the fit is perfectly well defined. If every x is the same while y varies, the data sit on a vertical stack of points, and no single slope can describe a relationship that has no horizontal spread to measure. The linear regression calculator accepts the first case and rejects the second with a message that it needs different x values. Understanding why helps in spotting data problems early, such as a sensor stuck at one reading, an experiment where the controlled variable was never actually changed, or a spreadsheet column that was filled down by mistake.

Fitting a constant response

Take x equal to 1, 2, 3 and y equal to 5, 5, 5. The mean of x is 2 and the mean of y is 5. Every y deviates from its mean by zero, so the numerator of the slope formula, the sum of (x minus x-bar) times (y minus y-bar), is zero. The denominator, the sum of (x minus x-bar) squared, is 1 plus 0 plus 1, which is 2. The slope is zero divided by two, which is zero. The intercept is y-bar minus slope times x-bar, which is 5. The fitted line is y equals 5 everywhere, it passes through all three points exactly, and the residuals are all zero. Nothing is wrong with this calculation. A flat response is a legitimate finding: within this range of x, y did not change.

Why a constant predictor cannot give a slope

Now take x equal to 1, 1, 1 and y equal to 3, 5, 7. The mean of x is 1, and every deviation of x from its mean is zero. The denominator of the slope formula, the sum of squared x deviations, is therefore zero, and dividing by zero is undefined. The geometric reason is just as direct. All the points lie on the vertical line x equals 1. Any non-vertical line crosses that vertical line at exactly one height, so infinitely many lines with different slopes pass through the same single point, such as a line through the mean of y. Nothing in the data distinguishes among them. The data do not identify a slope, and the calculator reports an error about needing different x values instead of inventing one.

The language of identifiability

Statisticians say a parameter is identifiable when the data can in principle determine it. In simple regression the slope is identifiable only if x has some variation. The same idea extends to multiple regression, where perfectly collinear predictors make individual coefficients unidentifiable even though the overall fit can still be computed. The constant-x case is the simplest instance and a good place to build intuition. It also shows that the problem lies in the design of the data collection and not in the arithmetic. No better software or more digits will recover a slope when the predictor never moved. The remedy is to collect observations at more than one x value, and ideally at values spread widely enough that the slope estimate is stable.

Variation in x also controls precision

Even when x varies, its spread determines how well the slope is pinned down. The standard error of the slope is inversely related to the square root of the sum of squared x deviations. Narrow spread inflates that error. With x equal to 1, 2, 3 the sum of squares is 2, while with x equal to 10, 20, 30 it is 200. Measuring a relationship across a tiny window of x gives a slope that could swing widely with small changes in y. The fully constant case is the extreme end of this scale, where the denominator reaches zero. This is why experimental designs often include deliberately spread-out settings of the controlled variable rather than clustering them around one convenient value.

A second flat-response example

Consider a calibration-style table where x is an applied setting and y is a reading, with x equal to 2, 4, 6, 8 and y equal to 12, 12, 12, 12. The mean of x is 5 and the sum of squared deviations is 9 plus 1 plus 1 plus 9, which is 20. The numerator is zero because y never departs from its mean of 12. The slope is zero and the intercept is 12. The numbers are illustrative. A fit like this tells you the reading did not respond to the setting over the range tried. It does not prove that the reading could never respond. A wider range, a more sensitive instrument or a different setting might reveal a relationship that this window could not.

Keeping correlation separate

A constant response gives a regression line with a slope of zero, but it does not give a defined Pearson correlation. The correlation coefficient divides the covariance by the product of the standard deviations of x and y. When y is constant, its standard deviation is zero, so the denominator is zero and the coefficient is undefined. The regression slope uses only the variance of x in its denominator, so it survives. This is a good reminder that different formulas have different failure conditions. A regression fit with a horizontal line is not evidence of zero correlation or of any correlation, because the quantity is simply not defined for that data. The controls on this page concern the fitted slope and intercept only.

Spotting these problems in real tables

Constant columns usually come from ordinary mistakes. A formula filled down copies one value into every row. A filter leaves only one category. A sensor saturates, an instrument is out of range, or a log records a default value when a reading fails. Before fitting, a quick scan of the minimum and maximum of each column catches the problem in seconds. If the minimum equals the maximum for x, stop and collect or restore the data. If it happens for y, ask whether a flat result makes physical sense before accepting it. A flat y with varying x is sometimes the true answer, but it is also what a stuck sensor produces, and the regression output looks the same either way.

What the fitted line does not tell you

Both cases here use tiny samples, and a fit through three points carries little statistical weight even when it is exactly defined. The horizontal line through 5, 5, 5 has no uncertainty estimate in this worksheet, and the extrapolation beyond x equal to 3 is only as good as the assumption that the relationship stays flat. Regression also assumes a straight-line model. A response that is constant over a small range of x may bend sharply outside it. The calculator reports slope and intercept under ordinary least squares and nothing more, so judgments about whether the model suits the process remain with the person who knows the data.

Residuals when the response is flat

A residual is the observed y minus the fitted y at the same x. For the first worksheet case the fitted line is y equal to 5 and every observed y is 5, so all three residuals are zero and the sum of squared residuals is zero. For the calibration style table with y equal to 12 at each of four settings, the same holds. A zero residual sum is a perfect fit, but it is not automatically a sign of a good model. With only a handful of points, a horizontal line fits any data whose y values happen to agree. More informative checks need replicate measurements, wider ranges of x and an independent way to estimate the noise in y. In the flat case the intercept equals the common y value, here 12, so it describes the level of the response everywhere on the fitted line. With a sloped line the intercept is a prediction at x equal to 0, which may lie outside the tested range and mean little physically, so treat it as a parameter of the line first.

A nearly flat response is not a constant one

Not every zero slope comes from identical y values. Take x equal to 1, 2, 3 and y equal to 5, 6, 5. The mean of y is 16/3, about 5.333. The deviations of y are about negative 0.333, 0.667 and negative 0.333. Multiplying by the x deviations of negative 1, 0 and 1 gives 0.333, 0 and negative 0.333, which sum to zero. The slope is zero, and the intercept is about 5.333, but now the residuals are nonzero because the middle point sits above the line. This illustrative case shows that a fitted slope of zero says the best straight line is level. It does not say the data are flat. A plot of the residuals would reveal the hump immediately.

What to do after the calculator rejects the data

The rejection message points at the data and not at the tool. If the x values were meant to differ, check the source for a column that was copied down, a lookup that failed or a unit conversion that collapsed the values. If the x values really were identical, because every measurement was taken at one setting, regression is the wrong summary. In that situation the mean and spread of y at that setting describe what was observed, and no slope can be claimed. To learn how y responds to x, new measurements are needed at other settings, ideally at least three distinct levels so that a straight line can also be checked against curvature.

Reproduce the checks

Constant response, varying predictor

Open the Linear Regression Calculator and enter:

X observations
1,2,3
Y observations
5,5,5

Expected output:

Slope

0

Intercept

5

A horizontal line fits these response values exactly.

Constant predictor

Open the Linear Regression Calculator and enter:

X observations
1,1,1
Y observations
3,5,7

Expected rejection:

different x values

The data do not identify a slope under this formula.

References and implementation scope

The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.

Sources

Related tasks