R/vcov.multipleOutcomes.R

Defines functions vcov.multipleOutcomes

Documented in vcov.multipleOutcomes

#' Calculate Variance-Covariance Matrix for a Fitted Model Object
#' @description
#' Returns the variance-covariance matrix of the main parameters of fitted model 
#' objects. The "main" parameters of models correspond to those returned by `coef`. 
#' 
#' @param object an object returned by `multipleOutcomes()`.
#' @param model_index `NULL` if displaying covariance matrix of all fitted models;
#' otherwise, an integer indicating the fitted model.
#' @param ... for debugging only
#'
#' @return a matrix of covariance of all estimates
#' @export
#'
vcov.multipleOutcomes <- function(object, model_index = NULL, ...){

  ret <- object$mcov

  if(!is.null(model_index)){
    id_map <- object$id_map
    if(model_index > length(id_map)){
      stop('Invalid model index.')
    }

    ret <- ret[id_map[[model_index]], id_map[[model_index]]]
    rownames(ret) <- names(id_map[[model_index]])
    colnames(ret) <- names(id_map[[model_index]])
  }

  ret

}

Try the multipleOutcomes package in your browser

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

multipleOutcomes documentation built on June 22, 2024, 10:25 a.m.