how to extract "F-statistic vs. constant model" value for fitnlm programmatically

11 ビュー (過去 30 日間)
M K P Dev
M K P Dev 2021 年 8 月 2 日
編集済み: Ive J 2021 年 8 月 17 日
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])

回答 (2 件)

dpb
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 件のコメント
M K P Dev
M K P Dev 2021 年 8 月 2 日
I try [p,F]=coefTest(mdl)
but the results do not match the summary section.
I have been trying to find a solution for almost a week noow but could not find it.
Would be thankful if you could do it.
dpb
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
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])
mdl =
Nonlinear regression model: y ~ b1 + b2/x Estimated Coefficients: Estimate SE tStat pValue ________ _______ ______ __________ b1 1.8838 0.11958 15.753 6.7965e-09 b2 0.26553 0.75651 0.351 0.73222 Number of observations: 13, Error degrees of freedom: 11 Root Mean Squared Error: 0.0589 R-Squared: 0.0111, Adjusted R-Squared -0.0788 F-statistic vs. constant model: 0.123, p-value = 0.732
% 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)
F-stat = 0.123 with a p-value of 0.732

カテゴリ

Help Center および File ExchangeStandard State-Space Model についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by