how to extract "F-statistic vs. constant model" value for fitnlm programmatically
7 ビュー (過去 30 日間)
古いコメントを表示
how to extract "F-statistic vs. constant model" value for fitnlm programmatically:
y = [2.091666958,1.929444472,1.954580163,1.903415586,1.875379629,1.875379629,1.903415586,1.875379629,1.942330552,1.903415586,1.903415586,1.929750906,1.942330552]'
x = [7.163732175,7.009281649,5.203296758,7.0004477,7.087439702,7,7.012988611,7.002354474,5.274252552,5.38274806,7.000976802,7,5.321121833]'
myfun = 'y~b1 + b2/x';
mdl2 = fitnlm(x,y,myfun ,[1 , 1])
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/700477/image.jpeg)
0 件のコメント
回答 (2 件)
dpb
2021 年 8 月 2 日
編集済み: dpb
2021 年 8 月 2 日
For some unknown reason, TMW didn't package the summary statistics with the model -- you have to run anova on the returned model
anova(mdl2,'summary')
It's documented, but only in properties of LinearModel, not mentioned in the doc for fitlm except as the reference to the fact that the return object is one...
ADDENDUM
I missed the "n" for nonlinear...but, like the linear model, the overall statistics are packaged with the NonLinearModel object instead. Why, still anybody's guess; they had to calculate to print; why didn't wrap into the model object...
[p,F]=coefTest(mdl2)
ADDENDUM SECOND:
The above does not produce the same F statistic as is output by fitnlm; would have to do more spelunking to ascertain just what is difference.
4 件のコメント
dpb
2021 年 8 月 2 日
See above ADDENDUM -- not sure when will have time to try to delve through the documentation to see if can divine what TMW actually did in the one/does in the other.
Is maddening when they do stuff like this, though, agreed.
Might go ahead and submit a support request if somebody else here (John d'Errico, maybe???) doesn't see the thread and know in a day or so...
Ive J
2021 年 8 月 17 日
編集済み: Ive J
2021 年 8 月 17 日
I don't know if MATLAB has another helper function to fetch F-test stat., but you can extract it with information available in fitnlm output:
% your data
y = [2.091666958,1.929444472,1.954580163,1.903415586,1.875379629,1.875379629,1.903415586,1.875379629,1.942330552,1.903415586,1.903415586,1.929750906,1.942330552]';
x = [7.163732175,7.009281649,5.203296758,7.0004477,7.087439702,7,7.012988611,7.002354474,5.274252552,5.38274806,7.000976802,7,5.321121833]';
myfun = 'y~b1 + b2/x';
mdl = fitnlm(x,y,myfun ,[1 , 1])
% Sum of Squares for Model (SSM) = SST - SSE
SSM = mdl.SST - mdl.SSE;
% Degrees of Freedom for Model: DFM = number of model parameters (p) - 1
DFM = mdl.NumVariables - 1;
% Mean of Squares for Model: MSM = SSM / DFM
MSM = SSM/DFM;
% calculate F-statistic
F = MSM/mdl.MSE;
% calculate p-value
pval = 1 - fcdf(F, DFM, mdl.DFE);
% report the summary stat
fprintf('F-stat = %.3f with a p-value of %.3f\n', F, pval)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Analysis of Variance and Covariance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!