[R] extend summary.lm for hccm?

John Fox jfox at mcmaster.ca
Sun Dec 24 15:45:44 CET 2006


Dear Dirk and Ivo,

It's true that the sandwich package has more extensive facilities for
sandwich variance estimation than the hccm function in the car package, but
I think that the thrust of Ivo's question is to get a model summary that
automatically uses the adjusted standard errors rather than having to
compute them and use them "manually."  Here's one approach, which could be
modified slightly if Ivo wants "hc0" as the default; it could also be
adapted to use the sandwich package.

I hope this helps,
 John

----------- snip --------------

summaryHCCM <- function(model, ...) UseMethod("summaryHCCM")

summaryHCCM.lm <- function(model, type=c("hc3", "hc0", "hc1", "hc2", "hc4"),

    ...){
    if (!require(car)) stop("Required car package is missing.")
    type <- match.arg(type)
    V <- hccm(model, type=type)
    sumry <- summary(model)
    table <- coef(sumry)
    table[,2] <- sqrt(diag(V))
    table[,3] <- table[,1]/table[,2]
    table[,4] <- 2*pt(abs(table[,3]), df.residual(model), lower.tail=FALSE)
    sumry$coefficients <- table
    print(sumry)
    cat("Note: Heteroscedasticity-consistant standard errors using
adjustment",
        type, "\n")
    }    

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
-------------------------------- 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Dirk 
> Eddelbuettel
> Sent: Saturday, December 23, 2006 11:16 PM
> To: ivo welch
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] extend summary.lm for hccm?
> 
> 
> On 23 December 2006 at 20:46, ivo welch wrote:
> | I wonder whether it is possible to extend the summary 
> method for the 
> | lm function, so that it uses an option "hccm" (well, model 
> "hc0").  In 
> | my line of work, it is pretty much required in reporting of 
> almost all 
> | linear regressions these days, which means that it would be 
> very nice 
> | not to have to manually library car, then sqrt the diagonal, and 
> | recompute T-stats; instead, I would love to get everything 
> in the same 
> | format as the current output---except errors heteroskedasticity 
> | adjusted.
> | 
> | easy or hard?
> 
> Did you consider the 'sandwich' package? A simple
> 
> 	> install.packages("sandwich")
> 	> library(sandwich)
> 	> ?vcovHC
> 	> ?vcovHAC
> 	
> should get you there.
> 
> Dirk
> 
> --
> Hell, there are no rules here - we're trying to accomplish something. 
>                                                   -- Thomas A. Edison
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list