Multiple Linear Regression

See the effects of several factors - temperature, pressure, line - on strength in one model. Categorical predictors become dummy variables automatically; standardized coefficients show relative influence, VIF flags multicollinearity, and Cook's distance and leverage reveal influential points.

1Data Table

Paste a table copied from Excel into a cell (Ctrl+V). Click a column header (A, B…) before pasting to use the first line as column names. Double-click a header to rename it, right-click to insert/delete rows and columns, and formulas such as =A1*2 work too.

2Multiple Linear Regression Options

Numeric predictors (multiple selection):
Categorical predictors (multiple selection, optional):

How to run a multiple linear regression

  1. Copy the response Y and the predictor columns with their headers.
  2. Choose the response Y and check the numeric and categorical predictors (the order you check them is the term order of the model). Add interactions or new X values to predict if needed.
  3. Click Analyze and review the coefficients, VIF, diagnostic plots and automatic interpretation.

Worked example with sample data

The example data are the temperature (°C), pressure (bar), production line (Line A, B, C) and product strength (MPa) of 30 production runs. Strength is the response, temperature and pressure are numeric predictors, and line is a categorical predictor.

Coefficient plot of the multiple linear regression - coefficient estimates (■) with 95% confidence intervals and the 0 reference line
Coefficient plot of the multiple linear regression - coefficient estimates (■) with 95% confidence intervals and the 0 reference line

The model summary shows R²=0.9217, adjusted R²=0.9092 and an F test p=1.858e-13, so the three factors explain the strength well.

In the coefficient table the temperature coefficient is 0.5144 (strength rises 0.51 MPa per °C) and the pressure coefficient is 3.144; compared with Line A, Line B is +6.14 MPa and Line C is -4.879 MPa. As the coefficient plot shows, all four terms have confidence intervals that do not cross 0, so they are significant.

The standardized coefficients are 0.702 for temperature and 0.354 for pressure, so temperature has the largest relative influence, and every VIF is below 1.6, so multicollinearity is not a concern. The 3 observations whose Cook's distance exceeds 4/n are worth a second look.

How it is calculated

Y ~ X1 + X2 + C(category) is fitted with statsmodels OLS. Categorical predictors become treatment-coded dummy variables with the first level in name order as the reference; with interactions on, the (all terms)**2 formula adds the product of every pair of terms.

Standardized coefficient = coefficient × SD of X / SD of Y; VIF = 1 / (1 - R² of that column regressed on the other columns); the Cook's distance threshold is 4/n and the leverage threshold is 2p/n (p = number of coefficients).

What the results show

(Prediction), the model summary, coefficients, standardized coefficients, VIF, actual vs predicted (equation in the side panel), residual diagnostics, coefficient plot, Cook's distance and leverage plot.

Interpreting the multiple linear regression

  • Use the F P-value for the significance of the whole model and each coefficient's P-value for each term. A categorical term 'C(...)[T.level]' is the difference from the reference level.
  • Terms with VIF of 5 or more share a lot of information with other predictors, so interpret their coefficients with care.
  • Observations whose Cook's distance exceeds 4/n or whose leverage exceeds 2p/n strongly influence the model, so check their data.

Frequently asked questions

How are categorical predictors included?

When checked as categorical predictors, a 0/1 dummy variable is created for each level other than the first level in name order (the reference).

When should I turn on interactions?

When you expect the effect of one factor to depend on the level of another. With many predictors the number of terms grows quickly.

Is variable selection (stepwise) available?

No. The model is fitted with exactly the predictors you choose. Add and remove predictors to compare results.

Other chart tools