R/summary.disease_expose.R

Defines functions summary.disease_expose

Documented in summary.disease_expose

#' @title Summarize a \code{disease_expose} Object
#'
#' @description Summarize disease-exposure data by finding various statistics (incidence, risk ratio, odds ratio, Fisher p-value, Chi-square p-value) for each disease-exposure combination in the \code{disease_expose} object.
#'
#' @param object an object of class \code{disease_expose}, created with \code{\link{disease_expose}}
#' @param ... additional arguments, besides \code{l}, to be passed to \code{\link{rbindlist}}, such as \code{fill}
#'
#' @return A \code{\link{data.frame}} object containing statistics for each disease-exposure combination
#' @export
#'
#' @importFrom data.table rbindlist
#'
#' @section Thanks:
#' Special thanks to Josh Sadowski for providing ideas of statistics to use for this function and for providing the bones of this function, which I have added to and edited to make it my own.
#'
#' @examples
#' de_data <- disease_expose_data # use the example data in the package
#'
#' cleaned_de_data <- clean_disease_expose(data = de_data, disease = "disease", noDisease = "No", exposures = c("exposure1", "exposure2", "exposure3")) # clean the data using specific columns in the dataset
#'
#' \dontrun{
#' de_object <- disease_expose(cleaned_de_data) # the best way to create a disease_expose object is by using the helper and selecting your choices in the Shiny gadget
#' }
#'
#' de_object <- new_disease_expose(cleaned_de_data, disease = 1, exposures = 2:8) # another way to create a disease_expose object is to use the constructor and manually enter the information
#'
#' summary(object = de_object) # create a summary of your disease_expose object
#'
#' summary(object = de_object, idcol = TRUE) # provide an input (idcol) to rbindlist to customize the summary a little more
summary.disease_expose <- function(object, ...) {

  epi_stats_list <- lapply(seq_along(object[,-1]), function(x) {

    current_col <- names(object[x + 1])

    current_epi_stat_obj <- epi_stats(disease = object[,1], exposure = object[,current_col])

  })

  final_epi_stats <- rbindlist(epi_stats_list, ...)

  final_epi_stats <- as.data.frame(final_epi_stats)

  rownames(final_epi_stats) <- c(names(object[-1]))

  return(final_epi_stats)

}
npeters1322/hospEpi documentation built on April 30, 2022, 6:12 p.m.