how to extract "F-statistic vs. constant model" value for fitnlm programmatically
26 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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])
0 Kommentare
Antworten (2)
dpb
am 2 Aug. 2021
Bearbeitet: dpb
am 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
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 Kommentare
dpb
am 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...
Ive J
am 17 Aug. 2021
Bearbeitet: Ive J
am 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])
% 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 Kommentare
Siehe auch
Kategorien
Mehr zu Analysis of Variance and Covariance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!