R/SummaryPoints.R

Defines functions summary.SummaryPts print.SummaryPts SummaryPts.reitsma SummaryPts.default SummaryPts

Documented in print.SummaryPts SummaryPts SummaryPts.default SummaryPts.reitsma summary.SummaryPts

SummaryPts <-function(object, ...) UseMethod("SummaryPts")

SummaryPts.default <- function(object, mu,Sigma,alphasens = 1, alphafpr = 1,
                           n.iter = 10^6, FUN, ...){
  samples <- rmvnorm(n.iter, mu, Sigma)
  sens <- inv.trafo(alphasens,samples[,1])
  fpr <- inv.trafo(alphafpr,samples[,2])
  out <- lapply(FUN, function(x){x(sens, fpr)})
  class(out) <- "SummaryPts"
  out
}

SummaryPts.reitsma <- function(object, n.iter = 10^6, FUN = NULL, ...){
  fit <- object
  if(length(coef(fit)) > 2){
    stop("SummaryPts is not be used for meta-regression!")}
  if(is.null(FUN)){FUN <- list(posLR = function(sens,fpr){sens/fpr},
                               negLR = function(sens,fpr){(1-sens)/(1-fpr)},
                               invnegLR = function(sens, fpr){(1-fpr)/(1-sens)},
                               DOR = function(sens, fpr){sens*(1-fpr)/((1-sens)*fpr)})}
  SummaryPts.default(mu = coef(fit)[1:2], Sigma = vcov(fit), 
                         alphasens = fit$alphasens, 
                         alphafpr = fit$alphafpr,
                         n.iter = n.iter, FUN = FUN)
  }

print.SummaryPts <- function(x, ...){
print(lapply(x, mean))
}

summary.SummaryPts <- function(object, level = 0.95, digits = 3, ...){
  x <- object
  quantiles <- c((1-level)/2, 1-(1-level)/2) 
  qq <- t(sapply(x, function(x){stats::quantile(x, probs = quantiles)}))
  qq <- signif(cbind(sapply(x,mean), sapply(x,median), qq), digits)
  colnames(qq)[1:2] <- c("Mean", "Median")
  qq
}

Try the mada package in your browser

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

mada documentation built on Sept. 9, 2022, 3:01 p.m.