View source: R/fastglm-methods.R
| vcovHC.fastglm | R Documentation |
Methods for 'sandwich::vcovHC()' on objects of class '"fastglm"' and '"fastglmFit"'. Load 'sandwich' ('library(sandwich)') before calling 'vcovHC(fit)'; otherwise no 'vcovHC' generic is in scope.
vcovHC.fastglm(object, type = c("HC3", "HC2", "HC1", "HC0"), ...)
vcovHC.fastglmFit(object, type = c("HC3", "HC2", "HC1", "HC0"), ...)
object |
a fitted object of class '"fastglm"' or '"fastglmFit"'. |
type |
one of '"HC0"', '"HC1"', '"HC2"', '"HC3"'. Default '"HC3"' matches 'sandwich::vcovHC.glm'. |
... |
not used. |
Computes the Eicker-Huber-White sandwich estimator 'bread ‘cov.unscaled') and 'meat = X’ diag(omega_i) X'. With 's_i = w_i^2 * r_i' the score contribution from observation 'i', the omegas are:
'omega_i = s_i^2'
'HC0' rescaled by 'n / (n - p)'
'omega_i = s_i^2 / (1 - h_i)'
'omega_i = s_i^2 / (1 - h_i)^2'
where 'r_i' is the working residual '(y - mu) / mu.eta(eta)', 'w_i^2 = prior.weight * mu.eta(eta)^2 / variance(mu)' is the IRLS working weight, and ‘h_i = w_i^2 * x_i’ (X' W X)^(-1) x_i' is the IRLS leverage. Equivalent to 'sandwich::vcovHC.glm'.
Requires the model matrix 'x' stored on the fitted object (set automatically by 'fastglm()', 'fastglmPure()', and 'fastglm_fit()' since version 0.0.6).
A 'p x p' heteroskedasticity-consistent variance-covariance matrix.
if (requireNamespace("sandwich", quietly = TRUE)) {
x <- cbind(1, matrix(rnorm(500 * 4), ncol = 4))
y <- rbinom(500, 1, plogis(x %*% c(0.2, 0.3, -0.4, 0.1, 0.2)))
fit <- fastglm(x, y, family = binomial())
sandwich::vcovHC(fit)
sandwich::vcovHC(fit, type = "HC0")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.