Skip to content
Prev 57405 / 398498 Next

Testing for normality of residuals in a regression model

John Fox wrote:

            
I'm not sure if this are BLUE residuals, but the following function 
transform to a
smaller set of independent, homoscedastic residuals and the calls 
shapiro.test:
I've proposed to make this a method for shapiro.test for "lm" objects, 
but it is
not accepted.

 shapiro.test.lm
function (obj)
{
    eff <- effects(obj)
    rank <- obj$rank
    df.r <- obj$df.residual
    if (df.r < 3)
        stop("To few degrees of freedom for residual for the test.")
    data.name <- deparse(substitute(obj))
    x <- eff[-(1:rank)]
    res <- shapiro.test(x)
    res$data.name <- data.name
    res$method <- paste(res$method, " for residuals of linear model")
    res
}

Kjetil