How to | Perform a Linear Regression

One of the most common statistical models is the linear regression model. A linear model predicts the value of a response variable by the linear combination of predictor variables or functions of predictor variables. In the Wolfram Language, LinearModelFit returns an object that contains fitting information for a linear regression model and allows for easy extraction of results and diagnostics.

Simulate a dataset:

Use LinearModelFit to construct a linear model for the data:

Extract the functional form of the model:

Plot the functional form of the model:

Show the data and the line of best fit:

Obtain information about the parameter estimates:

Extract and plot the standardized residuals and fit residuals:

Plot the Cook distances by observation number:

Alternatively, plot the Cook distances versus predictor value:

The previous examples demonstrated a selection of properties supported by LinearModelFit; many more are available:

  • Basic Statistics
  • Descriptive Statistics
  • Continuous Distributions
  • Discrete Distributions
  • Curve Fitting
  • Convolutions and Correlations
  • How to: Do Statistical Analysis
  • How to: Work with Tables
  • LinearModelFit  Plot  ListPlot

  • Statistics
  • Functions Used in Statistics
  • Descriptive Statistics
  • Statistical Model Analysis
  • Statistical Plots Package
  • "How to" Topics