Created
July 21, 2023 13:18
-
-
Save josherrickson/28ac463f9a4c86c87c0f1ab66d150c6d to your computer and use it in GitHub Desktop.
summary.lm with vcov. argument
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
summary.lm <- function(object, correlation = FALSE, symbolic.cor = FALSE, ..., vcov. = NULL) { | |
ss <- stats::summary.lm(object, correlation, symbolic.cor, ...) | |
if (!is.null(vcov.)) { | |
if (is.function(vcov.)) { | |
vcov. <- vcov.(object, ...) | |
} | |
ss$cov.unscaled <- vcov./ss$sigma^2 | |
ss$coefficients[,2] <- sqrt(diag(vcov.)) | |
ss$coefficients[,3] <- ss$coefficients[,1]/ss$coefficients[,2] | |
ss$coefficients[,4] <- 2 * pt(abs(ss$coefficients[,3]), ss$df[2], lower.tail = FALSE) | |
} | |
ss | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This overloads
stats::summary.lm
to add thevcov.
argument. It can be either a variance calculating function, or a variance/covariance matrix. E.g.