Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica HowTo
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 Mathematica, 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:
In[1]:=
Click for copyable input
Use LinearModelFit to construct a linear model for the data:
In[2]:=
Click for copyable input
Out[2]=
Extract the functional form of the model:
In[3]:=
Click for copyable input
Out[3]=
Plot the functional form of the model:
In[4]:=
Click for copyable input
Out[4]=
Show the data and the line of best fit:
In[5]:=
Click for copyable input
Out[5]=
Obtain information about the parameter estimates:
In[6]:=
Click for copyable input
Out[6]=
Extract and plot the standardized residuals and fit residuals:
In[7]:=
Click for copyable input
Out[7]=
Plot the Cook distances by observation number:
In[8]:=
Click for copyable input
Out[8]=
Alternatively, plot the Cook distances versus predictor value:
In[9]:=
Click for copyable input
Out[9]=
The previous examples demonstrated a selection of properties supported by LinearModelFit; many more are available:
In[10]:=
Click for copyable input
Out[10]=
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team