Title: | Finite Sample Power Calculations for Detection Boundary Tests |
---|---|
Description: | Calculates lower bound on power, upper bound on power, and exact power (small sets only) for detection boundary tests (e.g. Berk-Jones, Generalized Berk-Jones, innovated Berk-Jones) used in set-based inference studies. These detection boundary tests are described in Sun et al., (2019) <doi:10.1080/01621459.2019.1660170>. |
Authors: | Ryan Sun [aut, cre] |
Maintainer: | Ryan Sun <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2024-10-17 04:15:57 UTC |
Source: | https://github.com/cran/DBpower |
For detection boundary type tests, find the power given the rejection region bounds and specification of alternative. Do not use for sets larger than 5 elements, will be too slow.
calc_exact_power(bounds, sig_mat, muVec)
calc_exact_power(bounds, sig_mat, muVec)
bounds |
A d=J*1 vector of bounds on the magnitudes of the test statistics, where the first element is the bound for |Z|_(1) and the last element is the bound for |Z|_(J). |
sig_mat |
The covariance matrix of the test statistics under the alternative (assume multivariate normal). |
muVec |
The mean vector of the test statistics under the alternative (assume multivariate normal). |
A list with the elements:
power |
Power under the given alternative. |
errsum |
Largest possible error from integration. |
naSum |
Number of NAs in calculating all integrals. |
sumOverA |
Matrix with power, errsum, naSum for each partition of the rejection region. |
myCov <- matrix(data=0.3, nrow=5, ncol=5) diag(myCov) <- 1 myBounds <- set_GBJ_bounds(alpha = 0.01, J=5, sig_vec = myCov[lower.tri(myCov)]) calc_exact_power(bounds = myBounds, sig_mat = myCov, muVec = c(1, 0, 0, 0, 0))
myCov <- matrix(data=0.3, nrow=5, ncol=5) diag(myCov) <- 1 myBounds <- set_GBJ_bounds(alpha = 0.01, J=5, sig_vec = myCov[lower.tri(myCov)]) calc_exact_power(bounds = myBounds, sig_mat = myCov, muVec = c(1, 0, 0, 0, 0))
Calculate lower bound or upper bound on power when considering only the largest test statistic in magnitude, i.e. only |Z|_(J) and not |Z|_(J-1).
calcb1(lower = TRUE, upper = FALSE, muVec, sigMat, bounds)
calcb1(lower = TRUE, upper = FALSE, muVec, sigMat, bounds)
lower |
Boolean, whether to calculate lower bound. |
upper |
Boolean, whether to calculate upper bound. |
muVec |
Mean vector of test statistics under the alternative (assuming it's MVN). |
sigMat |
Covariance matrix of test statistics under the alternative (assuming it's MVN). |
bounds |
A J*1 vector of bounds on the magnitudes of the test statistics, where the first element is the bound for |Z|_(1) and the last element is the bound for |Z|_(J). |
A list with the elements:
allProbsLower |
J*1 vector of all components summed to calculate lower bound. |
lowerProb |
Lower bound. |
allProbsUpper |
J*1 vector of all components summed to calculate upper bound. |
upperProb |
Upper bound. |
myCov <- matrix(data=0.3, nrow=5, ncol=5) diag(myCov) <- 1 myBounds <- set_GBJ_bounds(alpha = 0.01, J=5, sig_vec = myCov[lower.tri(myCov)]) calcb1(muVec = c(1, 0, 0, 0, 0), sigMat = myCov, bounds=myBounds)
myCov <- matrix(data=0.3, nrow=5, ncol=5) diag(myCov) <- 1 myBounds <- set_GBJ_bounds(alpha = 0.01, J=5, sig_vec = myCov[lower.tri(myCov)]) calcb1(muVec = c(1, 0, 0, 0, 0), sigMat = myCov, bounds=myBounds)
Calculate lower bound or upper bound on power when considering only the two largest test statistic in magnitude, i.e. only |Z|_(J) and |Z|_(J-1).
calcb2(lower = TRUE, upper = FALSE, muVec, sigMat, bounds)
calcb2(lower = TRUE, upper = FALSE, muVec, sigMat, bounds)
lower |
Boolean, whether to calculate lower bound. |
upper |
Boolean, whether to calculate upper bound. |
muVec |
Mean vector of test statistics under the alternative (assuming it's MVN). |
sigMat |
Covariance matrix of test statistics under the alternative (assuming it's MVN). |
bounds |
A J*1 vector of bounds on the magnitudes of the test statistics, where the first element is the bound for |Z|_(1) and the last element is the bound for |Z|_(J). |
A list with the elements:
allProbsLower |
J*1 vector of all components summed to calculate lower bound. |
lowerProb |
Lower bound. |
allProbsUpper |
J*1 vector of all components summed to calculate upper bound. |
upperProb |
Upper bound. |
myCov <- matrix(data=0.3, nrow=5, ncol=5) diag(myCov) <- 1 myBounds <- set_GBJ_bounds(alpha = 0.01, J=5, sig_vec = myCov[lower.tri(myCov)]) calcb2(muVec = c(1, 0, 0, 0, 0), sigMat = myCov, bounds=myBounds)
myCov <- matrix(data=0.3, nrow=5, ncol=5) diag(myCov) <- 1 myBounds <- set_GBJ_bounds(alpha = 0.01, J=5, sig_vec = myCov[lower.tri(myCov)]) calcb2(muVec = c(1, 0, 0, 0, 0), sigMat = myCov, bounds=myBounds)
Create the matrix that linearly transforms the vector of test statistics into a quantity amenable for pmvnorm.
createMj(j, size)
createMj(j, size)
j |
The element of the vector that is the largest. |
size |
The length of the set. |
The transformation matrix of dimension (2J-1)*(2J-1)
createMj(j=3, size=5)
createMj(j=3, size=5)
Create the matrix that linearly transforms the vector of test statistics into a quantity amenable for pmvnorm.
createMjk(j, k, size)
createMjk(j, k, size)
j |
The element of the vector that is the largest. |
k |
The element of the vector that is the second largest. |
size |
The length of the set. |
The transformation matrix of dimension (2J-1)*(2J-1)
createMjk(j=3, k=4, size=5)
createMjk(j=3, k=4, size=5)
Apply this function over 1:J to calculate each portion of the integral we need for the lower bound.
performIntegralLower1(j, muVec, sigMat, lBounds1, uBounds1, lBounds2, uBounds2)
performIntegralLower1(j, muVec, sigMat, lBounds1, uBounds1, lBounds2, uBounds2)
j |
Apply over this integer, the element that will be the largest in magnitude. |
muVec |
Mean vector of test statistics under the alternative (assuming it's MVN). |
sigMat |
Covariance matrix of test statistics under the alternative (assuming it's MVN). |
lBounds1 |
A 2J-1 vector of lower bounds for the first integral (see paper). |
uBounds1 |
A 2J-1 vector of upper bounds for the second integral (see paper). |
lBounds2 |
A 2J-1 vector of lower bounds for the first integral (see paper). |
uBounds2 |
A 2J-1 vector of upper bounds for the second integral (see paper). |
The value of the integration.
Apply this function over all m, j not equal (order matters) to calculate each portion of the integral we need for the lower bound for calc_b2.
performIntegralLower2( x, muVec, sigMat, lBounds1, uBounds1, lBounds2, uBounds2, lBounds3, uBounds3, lBounds4, uBounds4 )
performIntegralLower2( x, muVec, sigMat, lBounds1, uBounds1, lBounds2, uBounds2, lBounds3, uBounds3, lBounds4, uBounds4 )
x |
Apply over this 2*1 vector, the element that will be the largest in magnitude. |
muVec |
Mean vector of test statistics under the alternative (assuming it's MVN). |
sigMat |
Covariance matrix of test statistics under the alternative (assuming it's MVN). |
lBounds1 |
A 2J-1 vector of lower bounds for the first integral (see paper). |
uBounds1 |
A 2J-1 vector of upper bounds for the second integral (see paper). |
lBounds2 |
A 2J-1 vector of lower bounds for the first integral (see paper). |
uBounds2 |
A 2J-1 vector of upper bounds for the second integral (see paper). |
lBounds3 |
A 2J-1 vector of lower bounds for the third integral (see paper). |
uBounds3 |
A 2J-1 vector of upper bounds for the third integral (see paper). |
lBounds4 |
A 2J-1 vector of lower bounds for the fourth integral (see paper). |
uBounds4 |
A 2J-1 vector of upper bounds for the fourth integral (see paper). |
The value of the integration.
Apply this function over 1:J to calculate each portion of the integral we need for the upper bound.
performIntegralUpper1(j, muVec, sigMat, lBounds1, uBounds1, lBounds2, uBounds2)
performIntegralUpper1(j, muVec, sigMat, lBounds1, uBounds1, lBounds2, uBounds2)
j |
Apply over this integer, the element that will be the largest in magnitude. |
muVec |
Mean vector of test statistics under the alternative (assuming it's MVN). |
sigMat |
Covariance matrix of test statistics under the alternative (assuming it's MVN). |
lBounds1 |
A 3J-2 vector of lower bounds for the first integral (see paper), bounds will be longer than for performIntegralLower1. |
uBounds1 |
A 3J-2 vector of upper bounds for the second integral (see paper). |
lBounds2 |
A 3J-2 vector of lower bounds for the first integral (see paper). |
uBounds2 |
A 3J-2 vector of upper bounds for the second integral (see paper). |
The value of the integration.
Apply this function over all m, j not equal (order matters) to calculate each portion of the integral we need for the lower bound for calc_b2.
performIntegralUpper2( x, muVec, sigMat, lBounds1, uBounds1, lBounds2, uBounds2, lBounds3, uBounds3, lBounds4, uBounds4 )
performIntegralUpper2( x, muVec, sigMat, lBounds1, uBounds1, lBounds2, uBounds2, lBounds3, uBounds3, lBounds4, uBounds4 )
x |
Apply over this 2*1 vector, the elements that will be the largest and second largest in magnitude. |
muVec |
Mean vector of test statistics under the alternative (assuming it's MVN). |
sigMat |
Covariance matrix of test statistics under the alternative (assuming it's MVN). |
lBounds1 |
A 3J-2 vector of lower bounds for the first integral (see paper). |
uBounds1 |
A 3J-2 vector of upper bounds for the second integral (see paper). |
lBounds2 |
A 3J-2 vector of lower bounds for the first integral (see paper). |
uBounds2 |
A J3J-2 vector of upper bounds for the second integral (see paper). |
lBounds3 |
A 3J-2 vector of lower bounds for the third integral (see paper). |
uBounds3 |
A 3J-2 vector of upper bounds for the third integral (see paper). |
lBounds4 |
A 3J-2 vector of lower bounds for the fourth integral (see paper). |
uBounds4 |
A 3J-2 vector of upper bounds for the fourth integral (see paper). |
The value of the integration.
Finds the boundary points of the rejection region for the BJ statistic when all elements in a set are independent.
set_BJ_bounds(alpha, J)
set_BJ_bounds(alpha, J)
alpha |
Type I error of test. |
J |
Number of elements in set. |
A J*1 vector of bounds on the magnitudes of the test statistics, where the first element is the bound for |Z|_(1) and the last element is the bound for |Z|_(J).
set_BJ_bounds(alpha = 0.01, J=5)
set_BJ_bounds(alpha = 0.01, J=5)
Finds the boundary points of the rejection region for the GBJ statistic.
set_GBJ_bounds(alpha, J, sig_vec)
set_GBJ_bounds(alpha, J, sig_vec)
alpha |
Type I error of test. |
J |
Number of elements in set. |
sig_vec |
A vector generated from sigma[lower.tri(sigma)] where sigma is the correlation matrix of the test statistics. |
A J*1 vector of bounds on the magnitudes of the test statistics, where the first element is the bound for |Z|_(1) and the last element is the bound for |Z|_(J).
myCov <- matrix(data=0.3, nrow=5, ncol=5) diag(myCov) <- 1 set_GBJ_bounds(alpha = 0.01, J=5, sig_vec = myCov[lower.tri(myCov)])
myCov <- matrix(data=0.3, nrow=5, ncol=5) diag(myCov) <- 1 set_GBJ_bounds(alpha = 0.01, J=5, sig_vec = myCov[lower.tri(myCov)])
Simulate the probability of falling in the region used for the b1 lower bound or the b1 upper bound.
sim_b1(lower = TRUE, upper = TRUE, n, muVec, sigMat, bounds)
sim_b1(lower = TRUE, upper = TRUE, n, muVec, sigMat, bounds)
lower |
Boolean, if true sim lower bound. |
upper |
Boolean, if true sim upper bound. |
n |
Number of simulations. |
muVec |
Mean vector of test statistics under the alternative (assuming it's MVN). |
sigMat |
Covariance matrix of test statistics under the alternative (assuming it's MVN). |
bounds |
A J*1 vector of bounds on the magnitudes of the test statistics, where the first element is the bound for |Z|_(1) and the last element is the bound for |Z|_(J). |
A list with the elements:
lowerBound |
Lower bound on power. |
upperBound |
Upper bound on power. |
myCov <- matrix(data=0.3, nrow=5, ncol=5) diag(myCov) <- 1 myBounds <- set_GBJ_bounds(alpha = 0.01, J=5, sig_vec = myCov[lower.tri(myCov)]) sim_b1(n=5000, muVec = c(1, 0, 0, 0, 0), sigMat = myCov, bounds=myBounds)
myCov <- matrix(data=0.3, nrow=5, ncol=5) diag(myCov) <- 1 myBounds <- set_GBJ_bounds(alpha = 0.01, J=5, sig_vec = myCov[lower.tri(myCov)]) sim_b1(n=5000, muVec = c(1, 0, 0, 0, 0), sigMat = myCov, bounds=myBounds)
Simulate the probability of falling in the region used for the b2 lower bound or the b2 upper bound.
sim_b2(lower = TRUE, upper = FALSE, n, muVec, sigMat, bounds)
sim_b2(lower = TRUE, upper = FALSE, n, muVec, sigMat, bounds)
lower |
Boolean, if true sim lower bound. |
upper |
Boolean, if true sim upper bound. |
n |
Number of simulations. |
muVec |
Mean vector of test statistics under the alternative (assuming it's MVN). |
sigMat |
Covariance matrix of test statistics under the alternative (assuming it's MVN). |
bounds |
A J*1 vector of bounds on the magnitudes of the test statistics, where the first element is the bound for |Z|_(1) and the last element is the bound for |Z|_(J). |
A list with the elements:
lowerBound |
Lower bound on power. |
upperBound |
Upper bound on power. |
myCov <- matrix(data=0.3, nrow=5, ncol=5) diag(myCov) <- 1 myBounds <- set_GBJ_bounds(alpha = 0.01, J=5, sig_vec = myCov[lower.tri(myCov)]) sim_b2(n=5000, muVec = c(1, 0, 0, 0, 0), sigMat = myCov, bounds=myBounds)
myCov <- matrix(data=0.3, nrow=5, ncol=5) diag(myCov) <- 1 myBounds <- set_GBJ_bounds(alpha = 0.01, J=5, sig_vec = myCov[lower.tri(myCov)]) sim_b2(n=5000, muVec = c(1, 0, 0, 0, 0), sigMat = myCov, bounds=myBounds)
Simulate power of detection boundary tests starting from multivariate normal test statistics.
sim_power_mvn( n, muVec, sigMat, nullSigMat = NULL, bounds = NULL, test = NULL, alpha )
sim_power_mvn( n, muVec, sigMat, nullSigMat = NULL, bounds = NULL, test = NULL, alpha )
n |
Number of simulations. |
muVec |
Mean vector of test statistics under the alternative (assuming it's MVN). |
sigMat |
Covariance matrix of test statistics under the alternative (assuming it's MVN). |
nullSigMat |
Assumed correlation matrix of MVN under the null. Only need to specify if specifying test. |
bounds |
A J*1 vector of bounds on the magnitudes of the test statistics, where the first element is the bound for |Z|_(1) and the last element is the bound for |Z|_(J). |
test |
Either "GHC", "HC", "GBJ", or "BJ" or NULL. If provided, will calculate the p-value using the specified test and calculate power this way. |
alpha |
Level of the test. |
A list with the elements:
boundsPower |
Power from using bounds approach. |
testPower |
Power from using specific test p-value approach. |
myCov <- matrix(data=0.3, nrow=5, ncol=5) diag(myCov) <- 1 myBounds <- set_GBJ_bounds(alpha = 0.01, J=5, sig_vec = myCov[lower.tri(myCov)]) sim_power_mvn(n=1000, muVec = c(1, 0, 0, 0, 0), sigMat = myCov, alpha=0.01)
myCov <- matrix(data=0.3, nrow=5, ncol=5) diag(myCov) <- 1 myBounds <- set_GBJ_bounds(alpha = 0.01, J=5, sig_vec = myCov[lower.tri(myCov)]) sim_power_mvn(n=1000, muVec = c(1, 0, 0, 0, 0), sigMat = myCov, alpha=0.01)
Simulate power starting from individual-level data for multiple explanatory factor setting.
sim_stats_mef( B, sigSq, xMat, gMat, alphaVec, betaVec, decompTrue = NULL, checkpoint = FALSE )
sim_stats_mef( B, sigSq, xMat, gMat, alphaVec, betaVec, decompTrue = NULL, checkpoint = FALSE )
B |
Number of simulations. |
sigSq |
Variance of outcome. |
xMat |
Design matrix of non-genetic covariates, n*p. |
gMat |
Matrix of genotypes, n*J. |
alphaVec |
p*1 vector of regression coefficients for xMat. |
betaVec |
J*1 vector of regression coefficients for gMat. |
decompTrue |
The return value of a call to eigen() on the true covariance matrix. Can be null, in which case estimated covariance will be used. |
checkpoint |
Boolean, if true then print message every 50 simulations. |
A list with the elements:
zMat |
B*J matrix of test statistics Z. |
zVecGBJ |
Check on Z statistics, vector should match first row of zMat. |
iMat |
Innovated statistics matrix also of dimension B*J. |
xMat <- cbind(1, rnorm(n = 1000), rbinom(n = 1000, size=1, prob=0.5)) gMat <- matrix(data = rbinom(n=10000, size=2, prob=0.3), nrow=1000) alphaVec <- c(1, 1, 1) betaVec <- rep(0, 10) sim_stats_mef(B=10000, sigSq = 1, xMat = xMat, gMat = gMat, alphaVec = alphaVec, betaVec = betaVec)
xMat <- cbind(1, rnorm(n = 1000), rbinom(n = 1000, size=1, prob=0.5)) gMat <- matrix(data = rbinom(n=10000, size=2, prob=0.3), nrow=1000) alphaVec <- c(1, 1, 1) betaVec <- rep(0, 10) sim_stats_mef(B=10000, sigSq = 1, xMat = xMat, gMat = gMat, alphaVec = alphaVec, betaVec = betaVec)
Simulate power starting from individual-level data for multiple outcomes setting.
sim_stats_mo(B, covY, xMat, gVec, alphaMat, gammaVec, checkpoint = FALSE)
sim_stats_mo(B, covY, xMat, gVec, alphaMat, gammaVec, checkpoint = FALSE)
B |
Number of simulations. |
covY |
Covariance matrix of outcomes. |
xMat |
Design matrix of non-genetic covariates, n*p. |
gVec |
n*1 vector of genotypes. |
alphaMat |
p*K vector of regression coefficients for xMat. |
gammaVec |
K*1 vector of regression coefficients for each outcome. |
checkpoint |
Boolean, if true then print message every 50 simulations. |
A list with the elements:
zMat |
Matrix of test statistics Z. |
zVecGBJ |
Check on Z statistics, vector should match first row of zMat. |
iMat |
Innovated statistics using correlation matrix under the null. |
## Not run: covY <- matrix(data=0.3, nrow=10, ncol=10); diag(covY) <- 1 xMat <- cbind(1, rnorm(n = 1000), rbinom(n = 1000, size=1, prob=0.5)) gVec <- rbinom(n= 1000, size = 2, prob=0.3) alphaMat <-matrix(data = 1, nrow=3, ncol=10) gammaVec <- rep(0, 10) sim_stats_mo(B=10000, covY = covY, xMat = xMat, gVec = gVec, alphaMat = alphaMat, gammaVec = gammaVec) ## End(Not run)
## Not run: covY <- matrix(data=0.3, nrow=10, ncol=10); diag(covY) <- 1 xMat <- cbind(1, rnorm(n = 1000), rbinom(n = 1000, size=1, prob=0.5)) gVec <- rbinom(n= 1000, size = 2, prob=0.3) alphaMat <-matrix(data = 1, nrow=3, ncol=10) gammaVec <- rep(0, 10) sim_stats_mo(B=10000, covY = covY, xMat = xMat, gVec = gVec, alphaMat = alphaMat, gammaVec = gammaVec) ## End(Not run)