Why do F statistics of regress fitlm and coefTest functions differ?
1 view (last 30 days)
Show older comments
I'm interested whether or not a linear trend exists in a dataset. Therefore, I've looked at the F statistics of the regress vs. fitlm and coefTest functions with some dummy data without a trend and with a linear trend to get some intuition, which values these functions should return. Doing that, it seems that the F tests of regress, fitlm and the coefTest functions all return different values. For example with constant y values of 0.1 the F values of the regress, fitlm and coeftest are 5.81, -3.29 and 7.61e-16. In this case the p Value of the regress function with 0.04 would indicate a significant trend at the 5% level, if I'm not mistaken. Are they testing different things or why do they differ? Which F test should I use to test for non-zero linear trends in my data?
Here's my simple test code:
% Evaluating F tests for non-zero trends
x = (1:10)';
%% constant y
y = zeros(10,1)+0.1;
X=[x ones(length(x),1)];
[b,bint,r,rint,stats]=regress(y,X);
% F and p value from regress
F_regress_notrend = stats(2);
p_regress_notrend = stats(3);
mdl = fitlm(x,y);
% F and p value from mdl summary
F_mdl_notrend = mdl.ModelFitVsNullModel.Fstat;
p_mdl_notrend = mdl.ModelFitVsNullModel.Pvalue;
% F and p value from coefTest function
[p_coeftest_notrend,F_coeftest_notrend] = coefTest(mdl)
%% y with linear trend
y = 1;
for i=2:10
y(i,1) = y(i-1)+1;
end
X=[x ones(length(x),1)];
[b,bint,r,rint,stats]=regress(y,X);
% F and p value from regress
F_regress_trend = stats(2);
p_regress_trend = stats(3);
mdl = fitlm(x,y);
% F and p value from mdl summary
F_mdl_trend = mdl.ModelFitVsNullModel.Fstat;
p_mdl_trend = mdl.ModelFitVsNullModel.Pvalue;
% F and p value from coefTest function
[p_coeftest_trend,F_coeftest_trend] = coefTest(mdl);
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!