R/vcov_beta.R

Defines functions vcov_beta

################################################################################
#
# Function to compute vcov of betas
#
################################################################################

vcov_beta <- function(object){
  # Compute unscaled covariance matrix
  X <- cbind(1, object$gfit)
  unsc.vcov <- qr.solve(crossprod(X * sqrt(object$weights)))
  
  # Deal with intercept
  unsc.vcov[1,] <- unsc.vcov[1,] * attr(stats::terms(object), "intercept")
  unsc.vcov[,1] <- unsc.vcov[,1] * attr(stats::terms(object), "intercept")
  
  # Sigma estimator
  sigsq <- residual_sd(object)
  
  # Compute vcov matrix
  unsc.vcov * sigsq
}
PierreMasselot/cgaim documentation built on March 5, 2025, 10:18 p.m.