matlab线性回归模型
时间: 2023-07-30 21:07:01 浏览: 51
在MATLAB中,可以使用`fitlm`函数来构建线性回归模型。以下是一个简单的例子:
```matlab
% 创建样本数据
x = [1 2 3 4 5]';
y = [1.1 1.9 3.2 4.1 5.2]';
% 构建线性回归模型
mdl = fitlm(x,y);
% 显示模型摘要
disp(mdl)
% 绘制散点图和拟合曲线
plot(x,y,'o')
hold on
plot(mdl)
hold off
```
在这个例子中,我们创建了一组包含5个样本点的数据。然后使用`fitlm`函数来构建线性回归模型,并将结果存储在`mdl`变量中。最后,我们使用`disp`函数来显示模型摘要,并使用`plot`函数绘制散点图和拟合曲线。
输出结果如下:
```
Linear regression model:
y ~ 1 + x1
Estimated Coefficients:
Estimate SE tStat pValue
________ _______ _______ ________
(Intercept) 0.88095 0.31125 2.8316 0.050117
x1 1.02024 0.14737 6.9203 0.002303
Number of observations: 5, Error degrees of freedom: 3
Root Mean Squared Error: 0.173
R-squared: 0.971, Adjusted R-Squared 0.963
F-statistic vs. constant model: 122, p-value = 0.0023
```
可以看到,模型拟合结果包含估计的系数、标准误差、t值和p值等信息。最后几行显示了模型的性能指标,如均方根误差、$R^2$值和F统计量等。