[R] Doing partial-f test for stepwise regression

rolf at math.unb.ca rolf at math.unb.ca
Sun Apr 1 16:06:26 CEST 2007


Petr Klasterecky <klaster at karlin.mff.cuni.cz> wrote:

> And what about to read the help page ?anova ...?
> 
>  >>>
> When given a sequence of objects, 'anova' tests the models against
>       one another in the order specified.
> <<<

        One perfectly reasonable response to ``what about'' is
        that it is not *at all* clear as to what the statement
        in the help page actually means.

> Generally you almost never fit a full model (including all possible 
> interactions etc) - no one can interpret such complicated models.

        This assertion is certainly open to some dispute.

> Anova gives you a comparison between a broader model (the first
> argument to anova) and its submodel(s).

        As I read the above statement, it seems you've got
        it exactly backwards.  Broader model == full model,
        submodel = model under the null hypothesis, is it
        not so?

	You should actually specify the ``reduced'' model (the model
	under the null hypothesis) first, and the full model second.
	E.g.:

         > y <- runif(20)
         > x1 <- runif(20)
         > x2 <- runif(20)
         > x3 <- runif(20)
         > f1 <- lm(y~x1+x2+x3)
         > f2 <- lm(y~x1)
         > anova(f1,f2)
        Analysis of Variance Table

        Model 1: y ~ x1 + x2 + x3
        Model 2: y ~ x1
           Res.Df      RSS Df Sum of Sq      F Pr(>F)
        1     16  0.93225                           
        2     18  1.07998 -2  -0.14774 1.2678 0.3083

        Doing it your way --- full model first --- gives a
        negative sum of squares.  And negative degrees of
        freedom for the effect being tested.

        Not that it really matters --- the anova() function
        gives you the same F statistic and p-value either way.
        And the negative SS is a dead giveaway that something
        is a bit skew-wiff.

                                cheers,

                                        Rolf Turner
                                        rolf at math.unb.ca



More information about the R-help mailing list