[R] extend summary.lm for hccm?

John Fox jfox at mcmaster.ca
Mon Dec 25 16:01:59 CET 2006


Dear Achim,

> -----Original Message-----
> From: Achim Zeileis [mailto:Achim.Zeileis at wu-wien.ac.at] 
> Sent: Monday, December 25, 2006 8:38 AM
> To: John Fox
> Cc: 'Dirk Eddelbuettel'; 'ivo welch'; r-help at stat.math.ethz.ch
> Subject: Re: [R] extend summary.lm for hccm?
> 
> On Sun, 24 Dec 2006, John Fox wrote:
> 
> > 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."
> 
> I've written the function coeftest() in package "lmtest" for 
> this purpose.
> With this you can
>   coeftest(obj, vcov = sandwich)

Since coeftest() already exists in a package, I think that this is a
preferable solution.

> or you can put this into a specialized summary() function as 
> John suggested (where you probably would want the F statistic 
> to use the other vcov as well). 

Good point. Here's a modified version that also fixes up the F-test:

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
    p <- nrow(table)
    hyp <- if (has.intercept(model)) cbind(0, diag(p - 1)) else diag(p)
    sumry$fstatistic[1] <- linear.hypothesis(model, hyp,
white.adjust=type)[2,"F"]
    print(sumry)
    cat("Note: Heteroscedasticity-consistant standard errors using
adjustment",
        type, "\n")
    }

Regards,
 John

> See also function waldtest() 
> in "lmtest",
> linear.hypothesis() in "car" and
>   vignette("sandwich", package = "sandwich")
> 
> Although this works, it is still a nuisance to use a 
> different function and not summary() directly. In addition, 
> it would also be nice to plug in different vcovs into 
> confint() or predict() methods. Of course, one could write 
> different generics or overload the methods in certain packages.
> However, I guess that many practitioners want to use 
> different vcov estimators - especially in the social and 
> political scieneces, and econometrics etc. - so that this 
> might justify that the original "lm" (and
> "glm") methods are extended to allow for plugging in 
> different vcov matrices. Maybe we could try to convince 
> R-core to include somthing like this?
> 
> Best wishes,
> Z
> 
> 
>



More information about the R-help mailing list