opw: Perform Optimal Pvalue Weighting

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/opw.R

Description

A function to perform weighted pvalue multiple hypothesis test. This function compute the probabilities of the ranks of the covariate statistics given the effect sizes, and consequently the weights if neighter the weights nor the probabilities are given. Then provides the number of rejected null hypothesis and the list of the rejected pvalues as well as the corresponing covariate statistics.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
opw(
  pvalue,
  covariate,
  weight = NULL,
  ranksProb = NULL,
  mean_covariateEffect = NULL,
  mean_testEffect = NULL,
  effectType = c("continuous", "binary"),
  x0 = NULL,
  alpha = 0.05,
  nrep = 10000,
  tail = 2L,
  delInterval = 0.001,
  method = c("BH", "BON"),
  ...
)

Arguments

pvalue

Numeric vector of pvalues of the test statistics

covariate

Numeric vector of covariate statistics

weight

An optional numeric weight vector not required

ranksProb

An optional numeric vector of the ranks probability of the covariates given the mean effect

mean_covariateEffect

Numeric, value of the mean covariate effect of the true alternatives

mean_testEffect

Numeric, value of the mean test effect of the true alterantives

effectType

Character ("continuous" or "binary"), type of effect sizes

x0

Numeric, a initial value for the Newton-Raphson mehod.

alpha

Numeric, significance level of the hypothesis test

nrep

Integer, number of replications for importance sampling, default value is 10,000, can be increased to obtain smoother probability curves

tail

Integer (1 or 2), right-tailed or two-tailed hypothesis test. default is right-tailed test.

delInterval

Numeric, interval between the delta values of a sequence. Note that, delta is a LaGrange multiplier, necessary to normalize the weight

method

Character ("BH" or "BON"), type of methods is used to obtain the results; Benjemini-Hochberg or Bonferroni

...

Arguments passed to internal functions

Details

If one wants to test

H_0: epsilon_i = 0 vs. H_a: epsilon_i > 0,

then the mean_testEffect and mean_covariateEffect should be mean of the test and covariate effect sizes, respectively. This is called hypothesis testing for the continuous effect sizes.

If one wants to test

H_0: epsilon_i = 0 vs. H_a: epsilon_i = epsilon,

then mean_testEffect and mean_covariateEffect should be median or any discrete value of the test and covariate effect sizes. This is called hypothesis testing for the Binary effect sizes, where epsilon refers to a fixed value.

The main goal of the function is to compute the probabilities of the ranks from the pvalues and the covariate statistics, consequently the weights. Although weights ranksProb are optional, opw has the options so that one can compute the probabilities and the weights externally if necessary (see examples).

Internally, opw function compute the ranksProb and consequently the weights, then uses the pvalues to make conclusions about hypotheses. Therefore, if ranksProb is given then mean_covariateEffect and are redundant, and should not be provided to the funciton. Although ranksProb is not required to the function, One can compute ranksProb by using the function prob_rank_givenEffect.

The function internally compute mean_covariateEffect and mean_testEffect from a simple linear regression with box-cox transformation between the test and covariate statistics, where the covariates are regressed on the test statistics. Thus, covariates need to be positive to apply boxcox from the R library MASS. Then the estimated mean_covariateEffect and mean_testEffect are used to obtian the ranksProb and the weights. Thus, in order to apply the function properly, it is crucial to understand the uses mean_covariateEffect and mean_testEffect. If mean_covariateEffect and mean_testEffect are not provided then the test statistics computed from the pvalues will be used to compute the relationship between the covariate statistics and the test statistics.

If one of the mean effects mean_covariateEffect and mean_testEffect are not provided then the missing mean effect will be computed internally.

Value

totalTests Integer, total number of hypothesis tests evaluated.

nullProp Numeric, estimated propotion of the true null. hypothesis.

rejections Integer, total number of rejections.

mean_testEffect Numeric, mean of the alternative test effects. Note: for binary case, it is median of the alternative test effects.

mean_covariateEffect Numeric, mean of the covariate effects corresponding to the mean of the alternative test effects.

rejections_list Data frame, list of rejected p-values and the corresponding covariate statistics and the adjusted p-values if method = "BH" used.

dataOut Data frame, ordered covariate and the corresponding pvalues, ranks probabilities, weights, weight-adjusted pvalues, and decision of null rejection.

Author(s)

Mohamad S. Hasan, shakilmohamad7@gmail.com

See Also

prob_rank_givenEffect weight_binary weight_continuous qvalue dnorm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# generate pvalues and covariate statistics
m = 1000
set.seed(3)
covariates = runif(m, min = 1, max = 3)          # covariate statistics
H = rbinom(m, size = 1, prob = 0.1)             # hypothesis true or false
tests = rnorm(m, mean = H * covariates)            # Z-score
pvals = 1 - pnorm(tests)                        # pvalue

# general use
results <- opw(pvalue = pvals, covariate = covariates, effectType = "continuous",
                                              method = "BH")

# supply the mean effects for both the covariates and the tests externally
library(qvalue)
ranks <- 1:m
nullProp = qvalue(p = pvals, pi0.method = "bootstrap")$pi0
m0 = ceiling(nullProp*m)
m1 = m - m0
mod <- lm(log(covariates) ~ tests)
et = mean(sort(tests, decreasing = TRUE)[1:m1], na.rm = TRUE)
ey = mod$coef[[1]] + mod$coef[[2]]*et
results2 <- opw(pvalue = pvals, covariate = covariates,
               mean_covariateEffect = ey, mean_testEffect = et, tail = 2,
               effectType = "continuous", method = "BH")

# supply the rank probabilities externally
probs <- sapply(ranks, prob_rank_givenEffect, et = ey, ey = ey,
                                        nrep = 10000, m0 = m0, m1 = m1)
results3 <- opw(pvalue = pvals, covariate = covariates, ranksProb = probs,
                 effectType = "continuous", tail = 2, method = "BH")

# supply weight externally
wgt <- weight_continuous(alpha = .05, et = et, m = m, ranksProb = probs)
results4 <- opw(pvalue = pvals, covariate = covariates, weight = wgt,
                        effectType = "continuous", alpha = .05, method = "BH")

mshasan/OPWeight documentation built on March 3, 2021, 12:41 a.m.