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

조회 수: 3(최근 30일)
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 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...
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)
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표시숨기기 이전 댓글 수: 3
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:
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

댓글을 달려면 로그인하십시오.

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by