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

14 views (last 30 days)
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])

Answers (2)

dpb on 2 Aug 2021
Edited: dpb on 2 Aug 2021
For some unknown reason, TMW didn't package the summary statistics with the model -- you have to run anova on the returned model
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...
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.
dpb on 2 Aug 2021
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...

Sign in to comment.

Ive J
Ive J on 17 Aug 2021
Edited: Ive J on 17 Aug 2021
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
% 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




Community Treasure Hunt

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

Start Hunting!