Written and maintained by CASRAI Editorial Board
Last updated
A non linear relationship (also written nonlinear relationship) is an association between two variables that a straight line cannot describe: the change in Y for a one-unit change in X is not constant, so the points on a scatterplot follow a curve. The practical consequence is that the Pearson correlation coefficient can look weak, or be exactly zero, for a relationship that is strong and perfectly predictable. This guide defines the idea, works one example by hand, and shows how to detect and model a curve in Excel, R and Python.
What is a non linear relationship?
A relationship is linear when it can be written Y = a + bX, a constant slope b at every value of X. It is non-linear when the slope itself changes with X. NIST’s e-Handbook of Statistical Methods describes the clearest case: when the data form a U shape, “no imaginable simple straight line could ever adequately describe the relationship between X and Y” and “a curved (or curvilinear, or non-linear) function is needed.” Curvilinear and non-linear are used interchangeably for this situation.
Nonlinear relationship vs linear relationship
In a linear relationship, a line drawn through the middle of the points on a scatterplot is straight. In a curvilinear relationship, as the textbook An Introduction to Psychological Statistics (Foster et al., on LibreTexts) puts it, that line “will be curved rather than straight.” The same text notes that a linear relation “is what we will always assume when we calculate correlations” and that the correlations it presents “are only valid for linear relations.” Everything below follows from that sentence.
Common shapes and their equations
- Quadratic (U or inverted U): Y = a + bX + cX². The curve turns once. The sign of c sets the direction: positive c opens upward, negative c opens downward.
- Exponential: Y = a·ebX. The curve steepens (b > 0) or flattens towards zero (b < 0) as X increases; taking ln Y turns it into a straight line in X.
- Logarithmic: Y = a + b·ln X. Y rises quickly at small X, then flattens.
- Cubic and higher polynomials: Y = a + bX + cX² + dX³ allow an S shape or two turns.
For the first model to try, NIST is explicit: “the simplest such curvilinear function is a quadratic model,” and “the data analysis principle of parsimony suggests that we try fitting a quadratic function first.” The other forms above are standard mathematical families; which one suits your data is decided by the plot and by comparing fits, not by a rule.
Why Pearson r misses a non-linear relationship
Pearson’s r measures how closely the points hug a straight line, on a scale from -1.00 to 1.00. It is built from covariance around a line, so a symmetric curve can produce a value of exactly 0. Take X = -3, -2, -1, 0, 1, 2, 3 and Y = X² (9, 4, 1, 0, 1, 4, 9). The mean of X is 0, the mean of Y is 28 / 7 = 4, and the cross-products X(Y – 4) are -15, 0, 3, 0, -3, 0, 15, which sum to 0. So r = 0 even though Y is fully determined by X. This is the same trap covered from the “no correlation” side in no correlation examples, and in the FAQ of scatterplot interpretation. The lesson: a correlation of zero means no linear association, not no association.
Worked example: a line versus a curve on the same data
These eight points are constructed for illustration (they are not measurements): X = 1 to 8 and Y = 3, 9, 13, 17, 18, 17, 12, 8, rising and then falling like an inverted U.
Step 1, the linear fit. Mean X = 36 / 8 = 4.5 and mean Y = 97 / 8 = 12.125. The sum of squares of X is Sxx = 42, the sum of squares of Y is Syy = 192.875, and the cross-product sum is Sxy = 31.5.
- r = Sxy / √(Sxx × Syy) = 31.5 / √(42 × 192.875) = 31.5 / √8100.75 = 31.5 / 90.004 = 0.350
- Slope b = Sxy / Sxx = 31.5 / 42 = 0.75; intercept = 12.125 – 0.75 × 4.5 = 8.75, so ŷ = 8.75 + 0.75X
- R² = r² = 0.350² = 0.122. The residual sum of squares is 169.25 out of 192.875 total.
Step 2, the quadratic fit (least squares with X and X² as predictors): ŷ = -6.161 + 9.696X – 0.994X². The residual sum of squares drops to 3.244, so R² = 1 – 3.244 / 192.875 = 0.983. The turning point sits at X = -b / (2c) = -9.696 / (2 × -0.994) ≈ 4.88.
Step 3, adjust for the extra term. Adjusted R² = 1 – (1 – R²)(n – 1) / (n – p – 1), where n = 8 observations and p is the number of predictors. Linear (p = 1): 1 – 0.878 × 7 / 6 = -0.024. Quadratic (p = 2): 1 – 0.017 × 7 / 5 = 0.976. The curve is not a gain from simply adding a parameter.
Step 4, test the added term. Comparing the two nested models, F = (169.25 – 3.244) / 1 ÷ (3.244 / 5) = 255.9 on 1 and 5 degrees of freedom, p < .001.
Interpretation: reading the numbers side by side
| Quantity (example data) | Linear model | Quadratic model | How to read the gap |
|---|---|---|---|
| R² | 0.122 | 0.983 | A line explains about 12% of the variation in Y; the curve explains about 98%. |
| Adjusted R² | -0.024 | 0.976 | Penalises the extra term; the quadratic still wins by a wide margin. |
| Residual sum of squares | 169.25 | 3.244 | Prediction error falls by a factor of about 52. |
| Pearson r | 0.350 | not defined for a curve | r summarises only the straight-line part of the pattern. |
When r is modest but the scatterplot shows a clear arc, report the curve, not the r. To see how a poorly specified line shows up in residuals, see the linearity assumption guide; for how R² is read, see how to interpret R-squared.
Assumptions and common mistakes
- Judging by r alone. Always plot first. The same r can come from very different shapes.
- Extrapolating a curve. A fitted quadratic keeps turning beyond your data; the fit says nothing outside the observed X range.
- Adding terms until R² rises. R² never falls when you add a term, so compare adjusted R² or an F test, as in step 4.
- Transforming and forgetting the scale. If you take logs to straighten a curve, the slope is now on the log scale; see log and other data transformations.
- Ignoring the quadratic-first rule. Per NIST’s parsimony principle, try the quadratic before a more complex curve.
How to report a non-linear relationship (example)
An illustrative report for the example above: “A linear model explained little of the variation in Y, R² = .12, whereas adding a quadratic term improved the fit substantially, F(1, 5) = 255.86, p < .001; the quadratic model’s R² was .98 (adjusted R² = .98).” Report the fitted equation and the plot, and say which model you chose and why. Follow your journal’s or instructor’s style guide for symbol formatting and rounding.
How to calculate it in Excel, R or Python
Excel
Put X in A2:A9 and Y in B2:B9. Pearson r: =CORREL(A2:A9,B2:B9). Quadratic coefficients (returned as the X² coefficient, the X coefficient, then the intercept): =LINEST(B2:B9,A2:A9^{1,2}). Quadratic R²: =INDEX(LINEST(B2:B9,A2:A9^{1,2},TRUE,TRUE),3,1).
R
x = 1:8
y = c(3, 9, 13, 17, 18, 17, 12, 8)
cor(x, y) # 0.350
fit1 = lm(y ~ x)
fit2 = lm(y ~ x + I(x^2))
summary(fit2)$adj.r.squared # 0.976
anova(fit1, fit2) # F = 255.86 on 1 and 5 df
scatter.smooth(x, y) # loess curve for a visual check
Python
import numpy as np
x = np.array([1, 2, 3, 4, 5, 6, 7, 8])
y = np.array([3, 9, 13, 17, 18, 17, 12, 8])
print(np.corrcoef(x, y)[0, 1]) # 0.350
n = len(y)
sst = ((y - y.mean())**2).sum()
for degree in (1, 2):
fit = np.polyfit(x, y, degree)
sse = ((y - np.polyval(fit, x))**2).sum()
r2 = 1 - sse / sst
adj = 1 - (1 - r2) * (n - 1) / (n - degree - 1)
print(degree, fit.round(3), round(r2, 3), round(adj, 3))
Running the Python above prints R² = 0.122 (adjusted -0.024) for the line and 0.983 (adjusted 0.976) for the quadratic, matching the hand calculation. For the definition and range of r itself, see correlation coefficient.
FAQ
What is a non linear relationship?
It is an association in which the effect of X on Y changes with the value of X, so the scatterplot follows a curve rather than a line. NIST calls the simplest fix a quadratic model.
Can correlation be zero with a nonlinear relationship?
Yes. For X = -3 to 3 and Y = X², Pearson r is exactly 0 although Y is a perfect function of X. Zero r rules out only a linear association.
How do you test for nonlinearity?
Plot Y against X (and the residuals against the fitted values), fit a model with an X² term, and compare it with the straight-line model using adjusted R² and an F test, as in the worked example.
Is a curvilinear relationship the same as a non-linear relationship?
For two-variable scatterplots, yes: NIST uses “curved (or curvilinear, or non-linear)” for the same situation.
Sources
- NIST/SEMATECH e-Handbook of Statistical Methods, Scatter Plot: Quadratic Relationship (checked 2026-10-29).
- Foster et al., An Introduction to Psychological Statistics, 12.03 Three Characteristics, LibreTexts (checked 2026-10-29).








