此为 Mathematica 7 文档,内容基于更早版本的 Wolfram 语言
查看最新文档(版本11.2)
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]=