R/Rfun_iHpTargetDiffM2.R

#' Find the difference between the achieved power and the desired power for rejecting H2 using the improved trimmed or truncated weighted Hochberg procedure with allowance for different data maturities
#'
#' @param n the sample size
#' @param alpha1 the weighted significance levels assigned to H1
#' @param alpha the significance level
#' @param k a pre-specified constant in the improved trimmed weighted Hochberg procedure
#' @param beta2 one minus the desired power for rejecting H2
#' @param deltavec a numeric vector of two values representing the effect sizes for the two hypotheses
#' @param rho the correlation coefficient between two test statistics
#' @param maturity  a numeric vector of two values representing the data maturities for the two hypotheses
#'
#' @returns the difference between the achieved power and the desired power for rejecting H2
#' @export
#'
#' @importFrom mvtnorm pmvnorm
#' @importFrom mvtnorm Miwa
#' @author Jiangtao Gou
#' @references
#' Gou, J., Chang, Y., Li, T., and Zhang, F. (2025). Improved trimmed weighted Hochberg procedures with two endpoints and sample size optimization. Technical Report.
iHpTarget2m <- function (n, alpha1, alpha, k, beta2, deltavec, rho, maturity) {
  # iHpTarget1m
  # iHpTarget2m
  # 2024-12-20
  # Applied in R20241124d3.R
  sigma <- matrix(c(1, rho, rho, 1), nrow = 2)
  lower <- pmax( c( qnorm(1 - alpha) - deltavec[1]*sqrt(maturity[1]*n), qnorm(1 - alpha) - deltavec[2]*sqrt(maturity[2]*n) ), c(-1000, -1000))
  upper <- c(1000, 1000)
  Part2Rslt <- mvtnorm::pmvnorm(lower = lower, upper = upper, mean = rep(0, 2), sigma = sigma, algorithm = mvtnorm::Miwa(steps = 128))
  Part2 <- as.numeric(Part2Rslt)
  if (abs(alpha - alpha1) < 1e-15) {
    return (Part2 - 1 + beta2)
  }
  #
  lower <- pmax( c( qnorm(alpha1) - deltavec[1]*sqrt(maturity[1]*n), qnorm(1 - (alpha - alpha1)*(1+k*alpha1)) - deltavec[2]*sqrt(maturity[2]*n) ), c(-1000, -1000))
  upper <- pmin( c(qnorm(1 - alpha) - deltavec[1]*sqrt(maturity[1]*n) , 1000 ), c(1000, 1000))
  Part1Rslt <- mvtnorm::pmvnorm(lower = lower, upper = upper, mean = rep(0, 2), sigma = sigma, algorithm = mvtnorm::Miwa(steps = 128))
  Part1 <- as.numeric(Part1Rslt)
  return (Part1 + Part2 - 1 + beta2)
}

Try the itrimhoch package in your browser

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

itrimhoch documentation built on June 8, 2025, 11:54 a.m.