MathsStatistics & Probability

Multiple Regression
calculator.

Fit one outcome to several predictors at once, and see what each one adds.

How it's worked out

Multiple linear regression predicts an outcome Y from several predictors together. Each coefficient answers one question: how much does Y change for one extra unit of this predictor, with the others held fixed? Typical uses are a house price from size and bedrooms, crop yield from rain and fertilizer, or sales from ads in several channels. With a single predictor, the linear regression tool shows more about the line.

Yˆ\displaystyle \hat{Y}=b0+b1X1+⋯+bkXk\displaystyle {}= b_0 + b_1 X_1 + \cdots + b_k X_k
b\displaystyle b=(X𝖳X)−1X𝖳Y\displaystyle {}= (X^{\mathsf{T}} X)^{-1} X^{\mathsf{T}} Y

In matrix form, Y is the column of outcomes and X holds the predictors, with a first column of ones for the intercept. The tool inverts the matrix by Gauss-Jordan elimination with partial pivoting. With n rows and k predictors, the residual variance is below.

s2\displaystyle s^2=SSresn−k−1\displaystyle {}= \frac{\text{SS}_{\text{res}}}{n - k - 1}
SE(bi)\displaystyle \text{SE}(b_i)=s2[(X𝖳X)−1]ii\displaystyle {}= \sqrt{s^2 \left[(X^{\mathsf{T}} X)^{-1}\right]_{ii}}

Each t statistic is a coefficient over its standard error, on n − k − 1 degrees of freedom. The F statistic tests whether the predictors together explain more than chance would.

F\displaystyle F=SSregks2\displaystyle {}= \frac{\frac{\text{SS}_{\text{reg}}}{k}}{s^2}
VIFj\displaystyle \text{VIF}_j=11−Rj2\displaystyle {}= \frac{1}{1 - R_j^2}

The variance inflation factor comes from fitting predictor j on all the other predictors, and Rj2R_j^2 is the R² of that fit. It shows how much overlap with the others has inflated the variance of that coefficient. A standardized coefficient rescales each slope by the spreads of its predictor and of Y, so you can compare predictors measured in different units.

Worked examples

Pricing ten homes from size and bedrooms

Ten homes have a price in thousands of dollars, a size in hundreds of square feet and a count of bedrooms. The fit is Ŷ = 102.62 + 11.096·Size (×100 sq ft) + 1.3077·Bedrooms. R² is 0.991 and adjusted R² is 0.989, with F = 390.9 on 2 and 7 degrees of freedom.

The size coefficient, 11.096, means each extra 100 square feet adds about $11,096 to the predicted price for homes with the same number of bedrooms. Its p-value is below 0.0001. The bedroom coefficient has p = 0.744 and a VIF of 4.74: larger homes tend to have more bedrooms, so the two share information and the bedroom effect is hard to pull apart from size.

Size has a standardized coefficient of 0.97 and bedrooms 0.03. Leave bedrooms out and adjusted R² goes from 0.9886 to 0.9899, so this model does better without them.

A 1,500 square foot home with 3 bedrooms comes out at 273, with a 95% interval of 262.5 to 283.4 for one home. To reach a price of 300 with 3 bedrooms, the model asks for a size of 17.4. As a check, the residuals add to 5.0022 × 10⁻¹².

Open this example in the tool

Height and weight that overlap

A score Y is measured with height and weight in ten people. Together they explain 98% of the variation, yet the height coefficient comes out at −0.557, which looks as if taller people score lower. Weight has a coefficient of 1.388.

The clue is the VIF of 78.3 on both. In this data, weight rises almost in step with height, so the model struggles to tell them apart, and the height coefficient has p = 0.268. Leave height out and R² only falls from 0.9799 to 0.9757. Leave weight out and it falls further, to 0.949. The fit predicts well; the single coefficients are what you should not lean on.

Open this example in the tool

One predictor, as a check on the method

With a single predictor the method becomes simple regression, so a published result makes a good test. Anscombe's set I has a line of y = 3.00 + 0.500x and an R² of 0.67. This engine gives Ŷ = 3.0001 + 0.50009·X and 0.67, so they agree. With one predictor there is no VIF to report and nothing to leave out.

Open this example in the tool

Reading your result

R² and adjusted R². R² is the fraction of variance the model explains. It never falls when you add a predictor, even a useless one. Adjusted R² penalizes extra terms, so compare models with it.

p-values. Each one tests whether that coefficient differs from zero, given the other predictors. A predictor can be useful alone and still not be significant once a correlated predictor joins the model.

VIF. A VIF above 10 is often called high, and a cutoff of 5 is also common. A high figure does not stop the model from predicting well, but it makes that coefficient unstable. Its square root is how much the standard error has grown because of the overlap.

Actual against fitted. Dots should scatter evenly around the diagonal. A curve or a funnel suggests a missing term or an uneven spread.

Common mistakes

  • Too few rows. A common rule asks for at least 10 to 20 times as many rows as predictors. With fewer, the estimates are probably unstable and unlikely to replicate.
  • Fishing through many predictors. Adding many invites what that same guide calls capitalizing on chance, where some look significant by luck. The risk grows as the sample shrinks.
  • Comparing raw coefficients. A coefficient for a value in thousands and one for a value in units cannot be compared directly. Use the standardized figures.
  • The wrong kind of data. The tests assume the residuals are independent, with even spread and a roughly normal shape. Data over time, grouped data or a yes or no outcome call for other models, such as logistic regression. A coefficient shows association, not cause, and predictions outside your data can be badly wrong.

Questions people ask

Use adjusted R² to compare models with different numbers of predictors. Plain R² rises or stays level when you add a term, while adjusted R² falls if the term does not improve the fit by enough. With a fixed set of predictors, either one describes the fit.

Sources