R/betaSandwich-r-sq-vcov-dot.R

Defines functions .RSqCov

#' Sampling Variance-Covariance Matrix of
#' Multiple Correlation Coefficients
#' (R-Squared and Adjusted R-Squared)
#'
#' @author Ivan Jacob Agaloos Pesigan
#'
#' @param object Object of class `rsqbetasandwich`.
#'
#' @family Beta Sandwich Functions
#' @keywords betaSandwich vcov rsq internal
#' @noRd
.RSqCov <- function(object) {
  stopifnot(
    inherits(
      object,
      "rsqbetasandwich"
    )
  )
  vcov <- object$vcov[
    object$fit$lm_process$k,
    object$fit$lm_process$k,
    drop = FALSE
  ]
  jcap <- c(
    1,
    (
      -1 * (
        1 - object$fit$lm_process$n
      ) / (
        object$fit$lm_process$n - object$fit$lm_process$k
      )
    )
  )
  vcov <- jcap %*% vcov %*% t(jcap)
  colnames(vcov) <- rownames(vcov) <- c(
    "rsq",
    "adj"
  )
  return(vcov)
}

Try the betaSandwich package in your browser

Any scripts or data that you put into this service are public.

betaSandwich documentation built on Oct. 15, 2023, 1:07 a.m.