如何从fitlm MATLAB中获取fstat
我使用的是如何从fitlm MATLAB中获取fstat,matlab,statistics,regression,Matlab,Statistics,Regression,我使用的是lm=fitlm(X,y,'linear') 它工作得很好,输出也很好 lm = Linear regression model: y ~ 1 + x1 + x2 + x3 Estimated Coefficients: Estimate SE tStat pValue (Intercept) 2.1338 0.27403 7.7869 1.6357e-1
lm=fitlm(X,y,'linear')
它工作得很好,输出也很好
lm =
Linear regression model:
y ~ 1 + x1 + x2 + x3
Estimated Coefficients:
Estimate SE tStat pValue
(Intercept) 2.1338 0.27403 7.7869 1.6357e-13
x1 0.07202 0.01757 4.0991 5.5484e-05
x2 -0.35927 0.12078 -2.9746 0.0032094
x3 0.020363 0.0041479 4.9092 1.6168e-06
Number of observations: 264, Error degrees of freedom: 260
Root Mean Squared Error: 0.835
R-squared: 0.154, Adjusted R-Squared 0.144
F-statistic vs. constant model: 15.8, p-value = 1.93e-09
像这样的事情。
但是,我希望获得每个模型(在循环中)的F-statistic
值并导出到文件。我的问题是。。我找不到包含F-statistic
的lm
变量,它是pvalue
;此外,lm.步骤
为空
================================================================================
还有一个问题,在什么条件下我应该使用这个回归结果?如果
x1
是我在回归出其他成分和残差后想要的成分,那么当x1的p值小于0.05或模型的p值小于0.05时,我应该说x1
对y负责吗?如fitlm
文档中建议的那样,您可以在您的模型上使用anova
函数。然后提取值(这些值将用于所有x值)并用您喜欢的任何方法保存:
tbl = anova(lm);
% something like this for just your desired values
A = [double(tbl.F),double(tbl.pValue)];
csvwrite('output.csv',A);
% or this dumps the entire result of anova to file
tbl2 = dataset2table(tbl);
writetable(tbl2, 'output.csv');
对于另一个变量,可以使用多个X输入,则可以使用
anova
上的summary
选项,并从中提取F和p值:
X = cell array of inputs of length n;
F = zeros(n,1);
p = zeros(n,1);
for m = 1:n;
lm = fitlm(X{n},y,'linear')
tbl = anova(lm,'summary');
% you may want to check these indices but should be the right points:
F(n) = double(tbl(2,4));
p(n) = double(tbl(2,5));
end
F-statistic vs.constant model:15.8,p-value=1.93e-09
。f统计数据和该模型的p值。很抱歉,我的问题中使用了一个大的X
。顺便问一下,你能就我的第二个问题给我一些建议吗?我认为你最好在交叉验证网站上作为一个单独的问题询问这一部分,因为这实际上不是关于代码方面的问题: