LinearModelFit: Linear Regression—Wolfram Documentation (original) (raw)

BUILT-IN SYMBOL

LinearModelFit

LinearModelFit[{{x1,y1},{x2,y2},…},{f1,f2,…},x]

constructs a linear model of the form that fits the yi for successive xi values.

LinearModelFit[data,{f1,f2,…},{x1,x2,…}]

constructs a linear model where the fi depend on the variables xk.

LinearModelFit[{m,v}]

constructs a linear model from the design matrix m and response vector v.

Details and Options

Options
Properties

Examples

open allclose all

Basic Examples (1)

Fit a linear model to some data:

Obtain the functional form:

Evaluate the model at a point:

Visualize the fitted function with the data:

Extract information about the fitting:

Plot the residuals:

Scope (18)

Data (8)

Fit a model of one variable assuming increasing integer independent values:

This is equivalent to:

Fit a model of more than one variable, assuming the response is the last one:

This is equivalent to:

Specify a column as the response:

Fit a list of rules:

Fit a rule of input values and responses:

Fit a model with categorical predictor variables:

Fit a model given a design matrix and response vector:

Fit the model referring to the basis functions as x and y:

Fit a Tabular object by specifying the response column:

Model (3)

Find the best fit linear coefficient for a function:

Fit data to a linear combination of linear functions of independent variables:

This is equivalent to explicitly specifying a constant function:

Fit data to a linear combination of nonlinear functions of independent variables:

Properties (7)

Data & Fitted Functions (1)

Fit a linear model:

Obtain a list of available properties for a linear model:

Extract the original data:

Obtain and plot the best fit:

Obtain the fitted function as a pure function:

Get the design matrix and response vector for the fitting:

Residuals (1)

Examine residuals for a fit:

Visualize the raw fit residuals:

Visualize scaled residuals in stem plots:

Plot the absolute differences between the standardized and Studentized residuals:

Sums of Squares (1)

Fit a linear model to some data:

Extract the estimated error variance and coefficient of variation:

Obtain an analysis of variance table for the model:

Get the F-statistics from the table:

Parameter Estimation Diagnostics (1)

Obtain a formatted table of parameter information:

Obtain the -statistics of fitted parameters:

Influence Measures (1)

Fit some data containing extreme values to a linear model:

Use single deletion variances to check the impact on the error variance of removing each point:

Check Cook distances to identify highly influential points:

Use DFFITS values to assess the influence of each point on the fitted values:

Use DFBETAS values to assess the influence of each point on each estimated parameter:

Prediction Values (1)

Fit a linear model:

Plot the predicted values against the observed values:

Obtain tabular results for the mean prediction confidence intervals:

Obtain tabular results for the single prediction confidence intervals:

Get the single prediction intervals from the table:

Extract 99% mean prediction bands:

Goodness-of-Fit Measures (1)

Obtain a table of goodness-of-fit measures for a linear model:

Compute goodness-of-fit measures for all possible linear submodels:

Rank the models by :

Rank the models by adjusted , which penalizes for adding terms:

Generalizations & Extensions (1)

Perform other mathematical operations on the functional form of the model:

Integrate symbolically and numerically:

Find a predictor value that gives a particular value for the model:

Options (11)

ConfidenceLevel (1)

The default gives 95% confidence intervals:

Use 99% intervals instead:

Set the level to 90% within FittedModel:

IncludeConstantBasis (1)

Fit a simple linear regression model:

Fit the linear model with intercept zero:

LinearOffsetFunction (1)

Fit data to a linear model:

Fit data to a linear model with a known Sqrt[x] term:

NominalVariables (1)

Fit data treating the first variable as a nominal variable:

Treat both variables as nominal:

VarianceEstimatorFunction (1)

Use the default unbiased estimate of error variance:

Assume a known error variance:

Estimate the variance by the mean squared error:

Weights (5)

Fit a model using equal weights:

Give explicit weights for the data points:

Use Around values to give different weights to data points:

Find the weights that were used to account for the uncertainty in the data:

Use Around values in both the independent values and responses:

Fit a model of more than one variable with Around values:

Try the FixedPoint algorithm to find the weights for the model:

Reduce the DampingFactor and increase the MaxIterations to reach convergence:

WorkingPrecision (1)

Use WorkingPrecision to get higher precision in parameter estimates:

Obtain the fitted function:

Reduce the precision in property computations after the fitting:

Applications (6)

Fit the first 100 primes to a linear model:

Visualize the fit:

The systematic trend in the residuals violates the assumption of independent normal errors:

Fit a linear model of multiple variables:

Visually inspect the residuals by data point:

Plot the residuals against each predictor variable:

Plot Cook's distances to diagnose leverage:

Find the positions of distances above a given cutoff value:

Extract the associated data points:

Use - plots to check the assumption of normal errors:

Compare standardized residuals to standard normal values:

Do the comparison with Studentized residuals:

Simulate some data with a continuous and a nominal variable:

Fit an analysis of covariance model to the data:

Obtain an analysis of variance table for the model:

Group the data by treatment:

Visualize the grouped data and associated curves:

Use properties to compute additional results:

Extract the design matrix and residuals:

Compute White's heteroskedasticity-consistent covariance estimate:

Compare with the covariance assuming homoskedasticity:

Compare standard errors based on the two covariance estimates:

Perform a Breusch–Pagan test:

Fit a model:

Fit the squared errors to a model with the same predictors:

Compute the Breusch–Pagan test statistic:

Compute the -value:

Properties & Relations (9)

Wolfram Research (2008), LinearModelFit, Wolfram Language function, https://reference.wolfram.com/language/ref/LinearModelFit.html (updated 2025).

Text

Wolfram Research (2008), LinearModelFit, Wolfram Language function, https://reference.wolfram.com/language/ref/LinearModelFit.html (updated 2025).

CMS

Wolfram Language. 2008. "LinearModelFit." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/LinearModelFit.html.

APA

Wolfram Language. (2008). LinearModelFit. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/LinearModelFit.html

BibTeX

@misc{reference.wolfram_2025_linearmodelfit, author="Wolfram Research", title="{LinearModelFit}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/LinearModelFit.html}", note=[Accessed: 04-May-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_linearmodelfit, organization={Wolfram Research}, title={LinearModelFit}, year={2025}, url={https://reference.wolfram.com/language/ref/LinearModelFit.html}, note=[Accessed: 04-May-2025 ]}