如何保存从fitlm MATLAB获得的估计系数
正如标题所示,我在Matlab中使用“fitlm”,它工作得非常好。当我运行代码时,估计的系数会写出来,如下所示:如何保存从fitlm MATLAB获得的估计系数,matlab,save,linear-regression,Matlab,Save,Linear Regression,正如标题所示,我在Matlab中使用“fitlm”,它工作得非常好。当我运行代码时,估计的系数会写出来,如下所示: mdl1 = Linear regression model: y ~ 1 + x1 Estimated Coefficients: Estimate SE tStat pValue ________ _________ ______ __
mdl1 =
Linear regression model:
y ~ 1 + x1
Estimated Coefficients:
Estimate SE tStat pValue
________ _________ ______ ______
(Intercept) 2.1999 0.0043976 500.25 0
x1 591.68 0.31096 1902.8 0
Number of observations: 24800, Error degrees of freedom: 24798
Root Mean Squared Error: 0.693
R-squared: 0.993, Adjusted R-Squared 0.993
F-statistic vs. constant model: 3.62e+06, p-value = 0
如何将这些数据保存到文件或表中
谢谢您可以通过从
fitlm
对象访问系数
字段并检索估计值
字段来获取系数:
下面是一个使用MATLAB中的hald
数据集的示例:
>> load hald;
>> lm = fitlm(ingredients,heat)
lm =
Linear regression model:
y ~ 1 + x1 + x2 + x3 + x4
Estimated Coefficients:
Estimate SE tStat pValue
________ _______ ________ ________
(Intercept) 62.405 70.071 0.8906 0.39913
x1 1.5511 0.74477 2.0827 0.070822
x2 0.51017 0.72379 0.70486 0.5009
x3 0.10191 0.75471 0.13503 0.89592
x4 -0.14406 0.70905 -0.20317 0.84407
>> lm.Coefficients.Estimate
ans =
62.4054
1.5511
0.5102
0.1019
-0.1441
另一种方法是
lm.Coefficients({'x1'}, 'Estimate')
这将保留带有变量名的“标题”。表中的索引的工作方式与pandas数据帧中的索引类似,因此,如果您想挑选可用变量的子集,可以编写
lm.Coefficients({'x1', 'x4'}, {'Estimate', 'SE'})
多个这样的表可以连接在一起显示