Contents
- Why does linearity matter in regression?
- How to test linearity in SPSS
- How to read both rows of the table
- When a high R-squared hides a curve
- Other ways to check linearity
- How to fix a nonlinear relationship
- Frequently asked questions
- What is a linearity test?
- How is Deviation from Linearity interpreted?
- Does a high R-squared mean the relationship is linear?
- What should be done when the data are not linear?
- Is the linearity test needed for every independent variable?
- Is a model with X² still a linear regression?
- References
Versi bahasa Indonesia: Pentingnya Linearitas pada Regresi dan Cara Jitu Mengatasinya
Short answer: the linearity test is a classical assumption check that confirms whether the relationship between X and Y is genuinely linear. In SPSS, the test is run through Analyze, Compare Means, Means, with Test for linearity ticked. The relationship is considered linear when the Linearity row is significant (Sig. < 0.05) and the Deviation from Linearity row is not significant (Sig. > 0.05). When the relationship is not linear, the data can be transformed, a polynomial term can be added, or a nonlinear regression can be used.
| Linearity row | Deviation from Linearity row | Conclusion |
|---|---|---|
| Sig. < 0.05 | Sig. > 0.05 | Linear relationship; assumption met |
| Sig. < 0.05 | Sig. < 0.05 | Linear component exists, but a nonlinear pattern remains |
| Sig. > 0.05 | Sig. < 0.05 | Relationship is mainly nonlinear |
| Sig. > 0.05 | Sig. > 0.05 | No clear relationship between X and Y |
Why does linearity matter in regression?
Linear regression is built on the assumption that Y changes along a straight line as X changes. The model is written as Ŷ = a + bX for the predicted value and Y = a + bX + e for the observed value, where e is the error, the difference between the observed and predicted values. When the model describes the data well, the errors are small and show no pattern. When the true relationship is curved, a straight line systematically overestimates Y in some ranges and underestimates it in others, and the coefficient b no longer describes the relationship correctly. Thus, however high the R-squared of a model, a violation of linearity can produce misleading estimates and predictions.
A common belief holds that a high R-squared guarantees linearity. The reasoning seems natural: if the line explains 70% of the variation, the relationship must be close to linear. However, the remaining 30% of the variation may form a clear curved pattern, which means that a different model would describe the data better. R-squared measures how much variation the line captures, not whether a line is the right shape. Consequently, linearity requires its own test.
How to test linearity in SPSS
The procedure in SPSS is: (1) open Analyze, Compare Means, Means; (2) enter Y in the Dependent List and X in the Independent List; (3) click Options and tick Test for linearity; and (4) click Continue and OK. The relevant output is the ANOVA table, which splits the variation between groups of X into a Linearity component and a Deviation from Linearity component.


How to read both rows of the table
Many explanations look only at the Deviation from Linearity row and conclude that the relationship is linear when its Sig. value exceeds 0.05. This reading is correct but incomplete, since the whole table should be read. The Linearity row tests whether a straight-line component exists in the relationship between X and Y. A Sig. value below 0.05 confirms that such a component exists. The Deviation from Linearity row tests whether the group means of Y depart from that straight line in a systematic way, namely whether a nonlinear component remains after the line is fitted. A Sig. value above 0.05 indicates that no significant departure remains.
In the first output above, the Linearity row is significant and the Deviation from Linearity row is not. The relationship therefore has a linear component and no significant nonlinear remainder, so the linearity assumption is met.
However, both rows can be significant at the same time. In that case, X and Y have a linear component, yet the means still deviate from the line in a systematic pattern. The straight line captures part of the relationship but not all of it, and another functional form is likely to describe the data better.

When a high R-squared hides a curve

The output above shows a model with R-squared = 0.645, which appears adequate since nearly two thirds of the variation is explained. Yet the linearity test indicates that the relationship is not linear, which suggests that the remaining 0.355 of unexplained variation follows a pattern. A scatter plot of X and Y confirms the suspicion.

The plot reveals a quadratic, U-shaped relationship. Y first decreases as X rises from zero to the bottom of the curve, then increases up to X = 4,000. The straight line describes the rising part reasonably well, which explains the decent R-squared, but it misrepresents the falling part entirely.
The pattern is familiar from agricultural data. Consider the cost per kilogram of a crop plotted against farm size. On very small plots, cost per kilogram is high because fixed costs such as a pump or a sprayer are spread over little output. As farm size grows, cost per kilogram falls. Beyond a certain size, it rises again as hired labor and supervision become more expensive. A straight line through such data would suggest that larger farms are simply more costly, missing the efficient middle range that matters most for policy.
Thus, a high R-squared does not guarantee linearity, and any transformation that raises R-squared should be checked again to confirm that it actually straightens the relationship. The purpose of the linearity assumption is twofold: the relationship between X and Y should be linear, and the remaining error should no longer show any systematic pattern.
Other ways to check linearity
The SPSS Means procedure works with one X at a time and requires repeated values of X to form groups. For multiple regression, two further checks are more common. Firstly, a plot of residuals against predicted values should show a random cloud around zero; a curved band indicates nonlinearity. Secondly, the Ramsey RESET test adds powers of the predicted values to the model and tests whether they are jointly significant; a significant result indicates a misspecified functional form.
import statsmodels.formula.api as smf
from statsmodels.stats.diagnostic import linear_reset
model = smf.ols("Y ~ X1 + X2", data=df).fit()
print(linear_reset(model, power=2, use_f=True)) # p < 0.05 suggests nonlinearity
# Adding a quadratic term when the plot shows a curve
quad = smf.ols("Y ~ X1 + I(X1**2) + X2", data=df).fit()
print(quad.summary())
How to fix a nonlinear relationship
Several remedies exist, and the choice should follow the shape of the relationship and its theoretical meaning. Firstly, a transformation can straighten the relationship: a logarithm suits relationships that rise quickly and then level off, while an inverse suits relationships that approach a limit. Secondly, a polynomial term such as X² captures a U-shaped or inverted U-shaped pattern, as in the example above, and the turning point can be calculated as −b1 / (2b2). Thirdly, curve estimation in SPSS compares several functional forms at once and helps identify the best candidate. Finally, a genuinely nonlinear regression model can be estimated when the relationship follows a known form, such as a logistic growth curve. Consequently, nonlinearity is not a reason to abandon regression but a reason to choose a better functional form.
Related guides on Catatan Budi: multiple linear regression, heteroscedasticity: detection and fixes, variance inflation factor (VIF), and R-squared vs adjusted vs predicted R-squared.
Frequently asked questions
What is a linearity test?
A linearity test checks whether the relationship between an independent variable (X) and a dependent variable (Y) follows a straight line. It is required because linear regression assumes a linear relationship.
How is Deviation from Linearity interpreted?
In the SPSS Test for linearity output, a Sig. value above 0.05 on the Deviation from Linearity row means that the group means do not depart significantly from a straight line. A value below 0.05 indicates a nonlinear pattern.
Does a high R-squared mean the relationship is linear?
No. A high R-squared shows that the model explains much of the variation in Y, yet the relationship can still be curved. Linearity should be checked separately with a plot or a formal test.
What should be done when the data are not linear?
Try a transformation (logarithm, square, or inverse), add a polynomial term, use curve estimation to compare functional forms, or switch to nonlinear regression.
Is the linearity test needed for every independent variable?
Yes, in principle, since each predictor may relate to Y differently. In multiple regression, a residual plot and the RESET test provide an efficient overall check, followed by partial plots for individual variables when a problem appears.
Is a model with X² still a linear regression?
Yes. Linear regression requires linearity in the parameters, not in the variables. A model such as Y = a + b1X + b2X² is still estimated by ordinary least squares, since each coefficient enters the equation linearly. The curve appears in the relationship between X and Y, while the estimation method remains the same. Consequently, adding a squared term is the simplest way to handle a U-shaped pattern without leaving the familiar regression framework.
References
- Gujarati, D. N., and Porter, D. C. (2009). Basic Econometrics (5th ed.). McGraw-Hill.
- Ramsey, J. B. (1969). Tests for specification errors in classical linear least-squares regression analysis. Journal of the Royal Statistical Society, Series B, 31(2), 350–371.
- Field, A. (2018). Discovering Statistics Using IBM SPSS Statistics (5th ed.). SAGE.
Discussion
No comments yet. Have a question about this topic? Write it below and I will do my best to answer.