If the models can be ordered in a
hierarchical way, the output is an
ANOVA table with the R-squared
estimate of each model, and the
R-squared change of each model
compared to the simpler model
preceding this model in the order.
The class of the output is
hierarchical_lm
, with a print
method. If the models cannot be
ordered this way, NA
is returned.
How it works
It call hierarchical()
firsts to
order the outputs for stats::lm()
,
If they can be ordered in a
hierarchical way, they will be passed
to stats::anova()
. R-squared and
R-squared change will be computed
if they are available in the
summary()
method applied to each
model.
Therefore, in principle, this
function can also be used for the
outputs of other model fitting
functions if their outputs have
stats::anova()
and summary()
methods.
Check Datasets Used
The comparison is meaningful only
if all models are fitted to the
same datasets. There is not way
to guarantee this is the case, given
only the output of lm()
. However,
there are necessary conditions to
claim that the same datasets are used:
the number of cases are the same,
the means, variances, and covariances
of numerical variables, and the
frequency distributions of variables
common to two models are identical.
If at least one of these conditions
is not met, then two models must have
been fitted to two different datasets.
The function will check these
conditions and raise an error if
any of these necessary conditions
are not met.