#' Create 2 x 2 Tables from DAG based SR data
#'
#' Creates a data frame with all 2 x 2 contigency tables given a simulated data
#' set from \code{simulateSRS}. The tables are organized
#' as follows:
#' \tabular{lccc}{
#' \tab event \eqn{j} \tab not event \eqn{j} \tab \emph{total}\cr
#' drug \eqn{i} \tab \code{a} \tab \code{c} \tab \code{a} + \code{c}\cr
#' not drug \eqn{i} \tab \code{b} \tab \code{d} \tab \code{b} + \code{d}\cr
#' \emph{total} \tab \code{a} + \code{b} \tab \code{c} + \code{d} \tab \code{n_reports}
#' }
#'
#' @param sr The output generated by the \code{\link{simulateSRS}} function
#'
#' @return A data frame where each row represents a 2 x 2 table. The columns represent:
#' \item{\code{drug_id}}{The ID of the drug}
#' \item{\code{event_id}}{The ID of the event}
#' \item{\code{prob_drug}}{The marginal probability of that drug}
#' \item{\code{prob_event}}{The marginal probability of that event}
#' \item{\code{or}}{The increase of the odds ratio when the drug is on the report}
#' \item{\code{associated}}{\code{TRUE} is there is a non-zero correlation, \code{FALSE} otherwise}
#' \item{\code{a}}{Number of times the drug and event appeared together in a report}
#' \item{\code{b}}{Number of times the event appeared without the drug in a report}
#' \item{\code{c}}{Number of times the drug appeared without the event in a report}
#' \item{\code{d}}{Number of times the drug and event both did not appear in a report}
#'
#' @examples
#' sr <- simulateSRS()
#' tables <- create2x2Tables(sr)
#'
#' @seealso \code{\link{simulateSRS}}
#' @export
convert2Tables <- function(sr) {
return(dplyr::as_tibble(
create2x2TablesDAGRcpp(
as.matrix(sr$sr),
sr$prob_drugs,
sr$prob_events,
as.integer(sr$nodes$in_degree),
as.integer(sr$nodes$parent_id),
sr$nodes$beta1
)
))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.