[R] Possible error in anova.lm?

rkevinburton at charter.net rkevinburton at charter.net
Tue Mar 9 18:01:50 CET 2010

Perhaps those more in the know than I could clarify some confusion. In the ANOVA 'R' code I see:

    mss <- sum(if (is.null(w)) object$fitted.values^2 else w * 
    if (ssr < 1e-10 * mss) 
        warning("ANOVA F-tests on an essentially perfect fit are unreliable")

But in the summary.lm I see:

        mss <- if (attr(z$terms, "intercept")) 
            sum((f - mean(f))^2)
        else sum(f^2)


        mss <- if (attr(z$terms, "intercept")) {
            m <- sum(w * f/sum(w))
            sum(w * (f - m)^2)

At the very least the ANOVA code seems to be inefficient to calculate mss then only use it for a warning. But it seems that it is being calculated incorrectly. It is hard to tell since it is only used to issue the warning. But it may be that the warning is incorrect in some cases if mss is not calculated correctly. Ideas?


More information about the R-help mailing list