R/p.order.R

Defines functions p.order

# Compute ordered constellation p-values for each gene from the p-values
# associated with the individual lesion types. The returned columns represent
# evidence involving at least one lesion type (p1), at least two lesion types
# (p2), and so on.

p.order <- function(
    P  # Matrix of lesion-type p-values; rows are genes and columns are lesion types.
) {
  k <- ncol(P)

  # When only one lesion type is present, the first-order constellation
  # p-value is identical to the original lesion-type p-value.
  if (k == 1) {
    res <- matrix(
      P[, 1],
      nrow = nrow(P),
      ncol = 1,
      dimnames = dimnames(P)
    )

    return(res)
  }

  # Sort the lesion-type p-values for each gene.
  p.mtx <- apply(P, 1, sort, na.last = TRUE)
  p.mtx <- t(p.mtx)

  # Compute the constellation p-value for each order.
  res <- p.mtx

  for (i in 1:k) {
    res[, i] <- stats::pbeta(
      p.mtx[, i],
      i,
      k - i + 1
    )
  }

  return(res)
}

Try the GRIN2 package in your browser

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

GRIN2 documentation built on Aug. 22, 2026, 5:09 p.m.