Heteroscedasticity-consistent covariance matrix estimation for singleRStaticCountData class
Heteroscedasticity-consistent covariance matrix estimation for singleRStaticCountData class
S3 method for vcovHC to handle singleRStaticCountData class objects. Works exactly like vcovHC.default the only difference being that this method handles vector generalised linear models. Updating the covariance matrix in variance/standard error estimation for population size estimator can be done via redoPopEstimation()
## S3 method for class 'singleRStaticCountData'estfun(x,...)## S3 method for class 'singleRStaticCountData'bread(x,...)## S3 method for class 'singleRStaticCountData'vcovHC( x, type = c("HC3","const","HC","HC0","HC1","HC2","HC4","HC4m","HC5"), omega =NULL, sandwich =TRUE,...)
Arguments
x: a fitted singleRStaticCountData class object.
...: for vcovHC additional optional arguments passed to the following functions:
estfun -- for empirical estimating functions.
hatvalues -- for diagonal elements of projection matrix.
sandwich -- only if sandwich argument in function call was set to TRUE.
vcov -- when calling bread internally.
type: a character string specifying the estimation type, same as in sandwich::vcovHC.default. HC3 is the default value.
omega: a vector or a function depending on the arguments residuals (i.e. the derivative of log-likelihood with respect to each linear predictor), diaghat (the diagonal of the corresponding hat matrix) and df (the residual degrees of freedom), same as in sandwich::vcovHC.default.
sandwich: logical. Should the sandwich estimator be computed? If set to FALSE only the meat matrix is returned. Same as in sandwich::vcovHC()
Returns
Variance-covariance matrix estimation corrected for heteroscedasticity of regression errors
Examples
set.seed(1)N <-10000gender <- rbinom(N,1,0.2)eta <--1+0.5*gender
counts <- rpois(N, lambda = exp(eta))df <- data.frame(gender, eta, counts)df2 <- subset(df, counts >0)mod1 <- estimatePopsize( formula = counts ~1+ gender, data = df2, model ="ztpoisson", method ="optim", popVar ="analytic")require(sandwich)HC <- sandwich::vcovHC(mod1, type ="HC4")Fisher <- vcov(mod1,"Fisher")# variance covariance matrix obtained from #Fisher (expected) information matrixHC
Fisher
# usual resultssummary(mod1)# updated resultssummary(mod1, cov = HC,popSizeEst = redoPopEstimation(mod1, cov = HC))# estimating equationsmod1_sims <- sandwich::estfun(mod1)head(mod1_sims)# bread methodall(vcov(mod1,"Fisher")* nrow(df2)== sandwich::bread(mod1, type ="Fisher"))