R/dadb.R

Defines functions dadb

Documented in dadb

#' Generate a data.frame of diagnostic accuracy study.
#' 
#' Generate a data.frame of diagnostic accuracy study given true negative, true
#' positive, false negative, false positive.
#' 
#' 
#' @param tn True negative
#' @param tp True positive
#' @param fn False negative
#' @param fp False positive
#' @return A data.frame for diagnostic accuracy studies.
#' @examples
#' 
#' db <- dadb(tn=720, tp=190, fn=10 , fp=80)
#' with(db, table(test,refstd))
#' 
#' @export
dadb <- function(tn,tp,fn,fp) {

    test <- factor(rep(c("+", "-"), c(tp + fp, tn + fn)),
                   levels=c("-", "+"))
    refstd <- factor(c(rep("present", tp),
                       rep("absent", fp),
                       rep("present", fn),
                       rep("absent", tn)),
                     levels=c("absent","present"))
    
    rval <- data.frame(refstd, test)
    ## put in order of reference standard
    rval[with(rval, order(refstd, test)), ]
}
lbraglia/lbdiag documentation built on July 29, 2023, 3:35 p.m.