Defines functions adjust_pmat

Documented in adjust_pmat

#' adjust_p
#' @param pmat matrix of p-values to adjust
#' @param p_adjust character describing adjustment to make. See stats::p.adjust

adjust_pmat <- function(pmat, p_adjust){
    ps <- pmat[upper.tri(pmat, diag = FALSE)]
    ps_adj <- stats::p.adjust(ps, method = p_adjust)

    pmat[upper.tri(pmat, diag = FALSE)] <- ps_adj

    pmat[lower.tri(pmat)] <-
      t(pmat)[lower.tri(pmat, diag = FALSE)]
     if(!isSymmetric(pmat)) stop("p-matrix no longer symmetric due to error with p.adjust")
    if(any(rownames(pmat) %in% colnames(pmat))) warning("At least one row variable was also specified as a column variable in a non-symmetrical matrix and p_adjust != 'none'. P-values have been adjusted assuming that ALL pairs (n = ", length(pmat),") in the matrix are unique and valid.")
        pmat[] <- stats::p.adjust(pmat, method = p_adjust)

Try the corx package in your browser

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

corx documentation built on July 9, 2023, 6:32 p.m.