Regression Model Building
Regression Model Building and Curvilinear Relationships
Purpose of regression model building
Regression model building is the process of developing an estimated equation that describes the relationship between a dependent variable and one or more independent variables. The goal is to use observed data to construct a model that represents the relationship well, rather than to include predictors or terms automatically.
Two central decisions guide model building:
Functional form: What shape best describes the relationship between the dependent variable and the predictors? It may be linear or may follow a curved pattern.
Predictor selection: Which independent variables, or transformations of those variables, should be included?
A model should not be judged solely by whether its coefficients are statistically significant or whether it has a high R2. Residual analysis is also important: residual patterns can reveal that the chosen functional form does not adequately describe the data.
General regression-model form
Suppose data have been collected for a dependent variable y and k independent variables, x1,x2,…,xk. A general linear regression model can be written as
where:
y is the dependent variable.
zj is a predictor term, which may be one of the original variables or a function of one or more original variables.
β0,β1,…,βp are model parameters to be estimated.
ε represents the error term, or the part of y not explained by the model.
A predictor term zj may simply be an original variable, such as x1, or it may be a transformed term, such as x12. This flexibility allows regression models to represent curved relationships.
Simple first-order model
When there is one predictor and it enters the model without transformation, the model is
This is the simplest first-order regression model. It describes a straight-line relationship between x1 and y.
Example: salesperson experience and product sales
A company wants to examine whether the length of time its salespeople have worked for the company is related to the number of electronic laboratory scales they sell.
Independent variable, x: Months employed.
Dependent variable, y: Number of scales sold.
Data: Observations from 15 randomly selected salespeople.
The expectation is that salespeople with more experience may sell more scales. A scatter plot is a useful first step because it shows the overall pattern between the two variables. In this example, the plotted data show a generally positive association: sales tend to increase as months employed increase.
A positive pattern provides an initial indication of association, but it does not establish that a straight line is the best model. The form of the relationship must also be assessed.
Fitting a simple linear regression model
The first model fitted to the salesperson data is
where x is months employed and y^ is the model’s predicted number of scales sold.
Interpreting the estimated equation
Intercept: The estimated intercept is about 111.2. It is the predicted number of scales sold when months employed equals zero. Whether this value is practically meaningful depends on whether zero months is within a relevant range for the data.
Slope: The estimated slope is about 2.37. For each additional month employed, the model predicts an average increase of about $2.37 scales sold.
The slope describes the model’s estimated association; it does not by itself establish that experience causes increased sales.
Assessing the first model
Overall model significance
An F-test assesses whether the regression model, considered as a whole, provides evidence of a relationship between the predictors and the dependent variable. In the simple model, the reported F-test p-value is approximately 1.24×10−5, which is below the conventional 0.05 threshold. This is evidence that the model as a whole is statistically significant.
Individual predictor significance
A t-test and its p-value assess whether an individual coefficient differs from zero, given the model. The p-value for months employed is below 0.05, so this predictor is statistically significant in the fitted simple model.
Explained variation
The first model has R2≈0.781, meaning that it accounts for approximately 78.1% of the observed variation in scales sold within this sample.
However, statistical significance and a relatively high R2 do not guarantee that the model’s form is appropriate. A model can explain substantial variation and still leave a systematic pattern in its errors.
Residual analysis and model form
A residual is the difference between an observed value and the value predicted by the regression model:
Residual plots help assess whether the model has captured important patterns in the data. One useful diagnostic is a plot of residuals against fitted values, where the horizontal axis shows y^ and the vertical axis shows residuals. Standardized residuals can be used so that residual size is expressed on a comparable scale.
What to look for
For an adequate model, residuals should generally:
Scatter around zero without a clear systematic pattern.
Show no obvious curvature.
Have a roughly similar spread across the range of fitted values.
A roughly patternless, rectangular-looking cloud is consistent with the model having captured the main systematic relationship. A curved pattern suggests that the relationship may not be adequately represented by a straight line.
Diagnosis for the simple model
The standardized residual plot for the salesperson data shows a curved pattern rather than a random cloud. This suggests that the straight-line model may be missing a curvilinear component. Because the sample contains only 15 observations, the pattern should be interpreted cautiously; a small dataset makes it harder to identify the precise form of a relationship.
The key lesson is that residual diagnostics provide information that significance tests and R2 alone cannot provide.
Modeling curvature with a squared predictor
A common way to represent a curved relationship is to add the square of a predictor to the regression equation. For the salesperson data, the second-order model is
The squared term allows the slope of the relationship between x and y to change as x changes. The model is quadratic in the predictor, so its graph can be curved.
The estimated equation is approximately
Here, both x and x2 are predictors. The negative coefficient on x2 indicates that the fitted curve bends downward: the model’s rate of increase in predicted sales becomes smaller as months employed grows.
Interpreting the terms together
The coefficient of x should not be interpreted in isolation from the squared term. The contribution of the predictor to the estimated response is
Thus, the relationship between months employed and predicted sales is not described by one constant increase per month across all values of x. Instead, the estimated change depends on the value of months employed.
Assessing the second-order model
After adding x2, the model’s reported fit improves:
Adjusted R2: Approximately 0.886, or 88.6%.
Overall F-test: The model is statistically significant; the reported p-value is approximately 0.000 (a rounded value, not literally zero).
Months-employed term: Statistically significant.
Squared term: Statistically significant, with a reported p-value of approximately 0.002.
The residual plot for the second-order model no longer shows the same clear curvilinear pattern. Its residuals are more consistent with an approximately patternless cloud, supporting the use of the quadratic form for these data.
The conclusion is not based only on the improved fit statistics. It is supported by the combination of model significance, significance of the added squared term, adjusted R2, and the improved residual pattern.
Linear in parameters does not mean straight-line in predictors
In a general linear regression model, the word linear refers to the way the model is linear in its parameters, not necessarily to a straight-line relationship between the response and every original predictor.
For example,
is linear in the parameters β0, β1, and β2, because each parameter appears to the first power and the parameters are not multiplied together. Yet its relationship between y and x is generally curved because it includes x2.
Therefore:
A model can be linear in its coefficients while representing a nonlinear relationship in the original predictor.
Adding transformed predictor terms, such as x2, can model curvature without changing the model’s linearity in its parameters.
“Linear regression” does not imply that the observed relationship between x and y must always be a straight line.
A practical workflow for selecting a functional form
Plot the observed data. Use a scatter plot to identify the broad shape of the relationship.
Fit an initial model. Begin with a simple linear model when a straight-line pattern is plausible.
Assess overall and individual significance. Examine the F-test for the model and the relevant coefficient tests.
Review fit measures. Consider R2 and adjusted R2, while remembering that they do not establish that the model form is correct.
Inspect residual plots. Look for curvature, changing spread, or other systematic patterns.
Add a suitable term if diagnostics suggest it. A squared predictor is a common starting point for modeling curvature.
Reassess the new model. Check significance, fit measures, and residual behavior again.
A higher-order term should not be added merely because it raises R2. It should also make sense for the observed pattern and improve the model’s diagnostics.
Implementing the analysis in Python
The example uses pandas to read data, matplotlib to plot, and statsmodels to fit ordinary least squares (OLS) regression models.
Fit and inspect a simple linear model
import pandas as pd
import matplotlib.pyplot as plt
import statsmodels.api as sm
data = pd.read_excel("Reynolds.xlsx")
x = data["MonthsEmployed"]
y = data["ScalesSold"]
plt.scatter(x, y)
plt.xlabel("Months employed")
plt.ylabel("Scales sold")
plt.show()
X = sm.add_constant(x)
model_linear = sm.OLS(y, X).fit()
print(model_linear.summary())sm.add_constant(x) adds an intercept to the predictor matrix. The OLS model estimates coefficients by minimizing the sum of squared residuals.
Inspect the simple model’s residuals
fitted_linear = model_linear.fittedvalues
residuals_linear = model_linear.resid_pearson
plt.scatter(fitted_linear, residuals_linear)
plt.axhline(0, color="black")
plt.xlabel("Fitted values")
plt.ylabel("Standardized residuals")
plt.show()A systematic curve in this plot is evidence that the simple linear model may not capture the relationship adequately.
Fit a model with a squared term
data["MonthsEmployed_sq"] = data["MonthsEmployed"] ** 2
X_quad = sm.add_constant(
data[["MonthsEmployed", "MonthsEmployed_sq"]]
)
model_quadratic = sm.OLS(y, X_quad).fit()
print(model_quadratic.summary())The quadratic model includes both the original predictor and its square. Its residuals should then be plotted against its own fitted values to check whether the curved pattern has been removed.
Main conclusions
Model building involves choosing both an appropriate functional form and appropriate predictors.
Statistical significance and R2 are not sufficient for deciding whether a model is adequate; residual plots are essential diagnostics.
A curved residual pattern from a simple linear model can indicate that a transformation, such as a squared predictor, should be considered.
In the salesperson example, adding months employed squared improves the model’s fit and reduces the residual curvature.
Regression models can represent nonlinear relationships between outcomes and predictors while remaining linear in their estimated parameters.

Ask anything
We've read this whole study set, so questions about it get the best answers.