Solved – GLM standard errors

covariancegeneralized linear modelr

I have a question about how to get the standard errors of the coefficients in my GLM model. I have the fisher information matrix which I calculated by hand, but it is unscaled.
How can I scale the fisher information matrix so that I get the same standard errors from the GLM function?

Best Answer

How can I scale the fisher information matrix so that I get the same standard errors from the GLM function?

Time your unscaled co-variance matrix the dispersion paramter as done in summary.glm. The relevant code from summary.glm is

if (is.null(dispersion)) 
    dispersion <- if (object$family$family %in% c("poisson", 
        "binomial")) 
        1
    else if (df.r > 0) {
        est.disp <- TRUE
        if (any(object$weights == 0)) 
            warning("observations with zero weight not used for calculating dispersion")
        sum((object$weights * object$residuals^2)[object$weights > 
            0])/df.r
    }
    else {
        est.disp <- TRUE
        NaN
    }
# [other code...]
if (p > 0) {
    p1 <- 1L:p
    Qr <- qr.lm(object)
    coef.p <- object$coefficients[Qr$pivot[p1]]
    covmat.unscaled <- chol2inv(Qr$qr[p1, p1, drop = FALSE])
    dimnames(covmat.unscaled) <- list(names(coef.p), names(coef.p))
    covmat <- dispersion * covmat.unscaled
    # [more code ...]

The chol2inv(Qr$qr[p1, p1, drop = FALSE]) computes $(R^\top R)^{-1}=(X^\top WX)^{-1}$ which you make a comment about. Here, $R$ is the upper triangular matrix from the QR decomposition $QR=\sqrt{W}X$.


atiretoo answers only holds when the dispersion paramter is one as with the Poisson and Binomial distribution.