Package 'powerMediation'

Title: Power/Sample Size Calculation for Mediation Analysis
Description: Functions to calculate power and sample size for testing (1) mediation effects; (2) the slope in a simple linear regression; (3) odds ratio in a simple logistic regression; (4) mean change for longitudinal study with 2 time points; (5) interaction effect in 2-way ANOVA; and (6) the slope in a simple Poisson regression.
Authors: Weiliang Qiu <[email protected]>
Maintainer: Weiliang Qiu <[email protected]>
License: GPL (>= 2)
Version: 0.3.4
Built: 2024-08-24 02:43:19 UTC
Source: https://github.com/cran/powerMediation

Help Index


Minimum detectable slope

Description

Calculate minimal detectable slope given sample size and power for simple linear regression.

Usage

minEffect.SLR(n, 
              power, 
              sigma.x, 
              sigma.y, 
              alpha = 0.05, 
              verbose = TRUE)

Arguments

n

sample size.

power

power for testing if λ=0\lambda=0 for the simple linear regression yi=γ+λxi+ϵi,ϵiN(0,σe2).y_i=\gamma+\lambda x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma_{e}^2).

sigma.x

standard deviation of the predictor sd(x)=σxsd(x)=\sigma_x.

sigma.y

marginal standard deviation of the outcome sd(y)=σysd(y)=\sigma_y. (not the conditional standard deviation sd(yx)sd(y|x))

alpha

type I error rate.

verbose

logical. TRUE means printing minimum absolute detectable effect; FALSE means not printing minimum absolute detectable effect.

Details

The test is for testing the null hypothesis λ=0\lambda=0 versus the alternative hypothesis λ0\lambda\neq 0 for the simple linear regressions:

yi=γ+λxi+ϵi,ϵiN(0,σe2)y_i=\gamma+\lambda x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{e})

Value

lambda.a

minimum absolute detectable effect.

res.uniroot

results of optimization to find the optimal minimum absolute detectable effect.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Dupont, W.D. and Plummer, W.D.. Power and Sample Size Calculations for Studies Involving Linear Regression. Controlled Clinical Trials. 1998;19:589-601.

See Also

power.SLR, power.SLR.rho, ss.SLR, ss.SLR.rho.

Examples

minEffect.SLR(n = 100, power = 0.8, sigma.x = 0.2, sigma.y = 0.5, 
    alpha = 0.05, verbose = TRUE)

Minimum detectable slope for mediator in linear regression based on Vittinghoff, Sen and McCulloch's (2009) method

Description

Calculate minimal detectable slope for mediator given sample size and power in simple linear regression based on Vittinghoff, Sen and McCulloch's (2009) method.

Usage

minEffect.VSMc(n, 
               power, 
               sigma.m, 
               sigma.e, 
               corr.xm, 
               alpha = 0.05, 
               verbose = TRUE)

Arguments

n

sample size.

power

power for testing b2=0b_2=0 for the linear regression yi=b0+b1xi+b2mi+ϵi,ϵiN(0,σe2)y_i=b0+b1 x_i + b2 m_i + \epsilon_i, \epsilon_i\sim N(0, \sigma_e^2).

sigma.m

standard deviation of the mediator.

sigma.e

standard deviation of the random error term in the linear regression yi=b0+b1xi+b2mi+ϵi,ϵiN(0,σe2)y_i=b0+b1 x_i + b2 m_i + \epsilon_i, \epsilon_i\sim N(0, \sigma_e^2).

corr.xm

correlation between the predictor xx and the mediator mm.

alpha

type I error rate.

verbose

logical. TRUE means printing minimum absolute detectable effect; FALSE means not printing minimum absolute detectable effect.

Details

The test is for testing the null hypothesis b2=0b_2=0 versus the alternative hypothesis b20b_2\neq 0 for the linear regressions:

yi=b0+b1xi+b2mi+ϵi,ϵiN(0,σe2)y_i=b_0+b_1 x_i + b_2 m_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{e})

Vittinghoff et al. (2009) showed that for the above linear regression, testing the mediation effect is equivalent to testing the null hypothesis H0:b2=0H_0: b_2=0 versus the alternative hypothesis Ha:b20H_a: b_2\neq 0, if the correlation corr.xm between the primary predictor and mediator is non-zero.

The full model is

yi=b0+b1xi+b2mi+ϵi,ϵiN(0,σe2)y_i=b_0+b_1 x_i + b_2 m_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{e})

The reduced model is

yi=b0+b1xi+ϵi,ϵiN(0,σe2)y_i=b_0+b_1 x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{e})

Vittinghoff et al. (2009) mentioned that if confounders need to be included in both the full and reduced models, the sample size/power calculation formula could be accommodated by redefining corr.xm as the multiple correlation of the mediator with the confounders as well as the predictor.

Value

b2

minimum absolute detectable effect.

res.uniroot

results of optimization to find the optimal sample size.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Vittinghoff, E. and Sen, S. and McCulloch, C.E.. Sample size calculations for evaluating mediation. Statistics In Medicine. 2009;28:541-557.

See Also

powerMediation.VSMc, ssMediation.VSMc

Examples

# example in section 3 (page 544) of Vittinghoff et al. (2009).
  # minimum effect is =0.1
  minEffect.VSMc(n = 863, power = 0.8, sigma.m = 1, 
    sigma.e = 1, corr.xm = 0.3, alpha = 0.05, verbose = TRUE)

Minimum detectable slope for mediator in cox regression based on Vittinghoff, Sen and McCulloch's (2009) method

Description

Calculate minimal detectable slope for mediator given sample size and power in cox regression based on Vittinghoff, Sen and McCulloch's (2009) method.

Usage

minEffect.VSMc.cox(n, 
                   power, 
                   sigma.m, 
                   psi, 
                   corr.xm, 
                   alpha = 0.05, 
                   verbose = TRUE)

Arguments

n

sample size.

power

power for testing b2=0b_2=0 for the cox regression log(λ)=log(λ0)+b1xi+b2mi\log(\lambda)=\log(\lambda_0)+b1 x_i + b2 m_i, where λ\lambda is the hazard function and λ0\lambda_0 is the baseline hazard function.

sigma.m

standard deviation of the mediator.

psi

the probability that an observation is uncensored, so that the number of event d=npsid= n * psi, where nn is the sample size.

corr.xm

correlation between the predictor xx and the mediator mm.

alpha

type I error rate.

verbose

logical. TRUE means printing minimum absolute detectable effect; FALSE means not printing minimum absolute detectable effect.

Details

The test is for testing the null hypothesis b2=0b_2=0 versus the alternative hypothesis b20b_2\neq 0 for the cox regressions:

log(λ)=log(λ0)+b1xi+b2mi\log(\lambda)=\log(\lambda_0)+b_1 x_i + b_2 m_i

Vittinghoff et al. (2009) showed that for the above cox regression, testing the mediation effect is equivalent to testing the null hypothesis H0:b2=0H_0: b_2=0 versus the alternative hypothesis Ha:b20H_a: b_2\neq 0, if the correlation corr.xm between the primary predictor and mediator is non-zero.

The full model is

log(λ)=log(λ0)+b1xi+b2mi\log(\lambda)=\log(\lambda_0)+b_1 x_i + b_2 m_i

The reduced model is

log(λ)=log(λ0)+b1xi\log(\lambda)=\log(\lambda_0)+b_1 x_i

Vittinghoff et al. (2009) mentioned that if confounders need to be included in both the full and reduced models, the sample size/power calculation formula could be accommodated by redefining corr.xm as the multiple correlation of the mediator with the confounders as well as the predictor.

Value

b2

minimum absolute detectable effect.

res.uniroot

results of optimization to find the optimal sample size.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Vittinghoff, E. and Sen, S. and McCulloch, C.E.. Sample size calculations for evaluating mediation. Statistics In Medicine. 2009;28:541-557.

See Also

powerMediation.VSMc.cox, ssMediation.VSMc.cox

Examples

# example in section 6 (page 547) of Vittinghoff et al. (2009).
  # minimum effect is = log(1.5) = 0.4054651

  minEffect.VSMc.cox(n = 1399, power = 0.7999916, 
    sigma.m = sqrt(0.25 * (1 - 0.25)), psi = 0.2, corr.xm = 0.3, 
    alpha = 0.05, verbose = TRUE)

Minimum detectable slope for mediator in logistic regression based on Vittinghoff, Sen and McCulloch's (2009) method

Description

Calculate minimal detectable slope for mediator given sample size and power in logistic regression based on Vittinghoff, Sen and McCulloch's (2009) method.

Usage

minEffect.VSMc.logistic(n, 
                        power, 
                        sigma.m, 
                        p, 
                        corr.xm, 
                        alpha = 0.05, 
                        verbose = TRUE)

Arguments

n

sample size.

power

power for testing b2=0b_2=0 for the logistic regression log(pi/(1pi))=b0+b1xi+b2mi\log(p_i/(1-p_i))=b0+b1 x_i + b2 m_i.

sigma.m

standard deviation of the mediator.

p

the marginal prevalence of the outcome.

corr.xm

correlation between the predictor xx and the mediator mm.

alpha

type I error rate.

verbose

logical. TRUE means printing minimum absolute detectable effect; FALSE means not printing minimum absolute detectable effect.

Details

The test is for testing the null hypothesis b2=0b_2=0 versus the alternative hypothesis b20b_2\neq 0 for the logistic regressions:

log(pi/(1pi))=b0+b1xi+b2mi\log(p_i/(1-p_i))=b_0+b_1 x_i + b_2 m_i

Vittinghoff et al. (2009) showed that for the above logistic regression, testing the mediation effect is equivalent to testing the null hypothesis H0:b2=0H_0: b_2=0 versus the alternative hypothesis Ha:b20H_a: b_2\neq 0, if the correlation corr.xm between the primary predictor and mediator is non-zero.

The full model is

log(pi/(1pi))=b0+b1xi+b2mi\log(p_i/(1-p_i))=b_0+b_1 x_i + b_2 m_i

The reduced model is

log(pi/(1pi))=b0+b1xi\log(p_i/(1-p_i))=b_0+b_1 x_i

Vittinghoff et al. (2009) mentioned that if confounders need to be included in both the full and reduced models, the sample size/power calculation formula could be accommodated by redefining corr.xm as the multiple correlation of the mediator with the confounders as well as the predictor.

Value

b2

minimum absolute detectable effect.

res.uniroot

results of optimization to find the optimal sample size.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Vittinghoff, E. and Sen, S. and McCulloch, C.E.. Sample size calculations for evaluating mediation. Statistics In Medicine. 2009;28:541-557.

See Also

powerMediation.VSMc.logistic, ssMediation.VSMc.logistic

Examples

# example in section 4 (page 545) of Vittinghoff et al. (2009).
  # minimum effect is log(1.5)= 0.4054651 

  minEffect.VSMc.logistic(n = 255, power = 0.8, sigma.m = 1, 
    p = 0.5, corr.xm = 0.5, alpha = 0.05, verbose = TRUE)

Minimum detectable slope for mediator in poisson regression based on Vittinghoff, Sen and McCulloch's (2009) method

Description

Calculate minimal detectable slope for mediator given sample size and power in poisson regression based on Vittinghoff, Sen and McCulloch's (2009) method.

Usage

minEffect.VSMc.poisson(n, 
                       power, 
                       sigma.m, 
                       EY, 
                       corr.xm, 
                       alpha = 0.05, 
                       verbose = TRUE)

Arguments

n

sample size.

power

power for testing b2=0b_2=0 for the poisson regression log(E(Yi))=b0+b1xi+b2mi\log(E(Y_i))=b0+b1 x_i + b2 m_i.

sigma.m

standard deviation of the mediator.

EY

the marginal mean of the outcome

corr.xm

correlation between the predictor xx and the mediator mm.

alpha

type I error rate.

verbose

logical. TRUE means printing minimum absolute detectable effect; FALSE means not printing minimum absolute detectable effect.

Details

The test is for testing the null hypothesis b2=0b_2=0 versus the alternative hypothesis b20b_2\neq 0 for the poisson regressions:

log(E(Yi))=b0+b1xi+b2mi\log(E(Y_i))=b_0+b_1 x_i + b_2 m_i

Vittinghoff et al. (2009) showed that for the above poisson regression, testing the mediation effect is equivalent to testing the null hypothesis H0:b2=0H_0: b_2=0 versus the alternative hypothesis Ha:b20H_a: b_2\neq 0, if the correlation corr.xm between the primary predictor and mediator is non-zero.

The full model is

log(E(Yi))=b0+b1xi+b2mi\log(E(Y_i))=b_0+b_1 x_i + b_2 m_i

The reduced model is

log(E(Yi))=b0+b1xi\log(E(Y_i))=b_0+b_1 x_i

Vittinghoff et al. (2009) mentioned that if confounders need to be included in both the full and reduced models, the sample size/power calculation formula could be accommodated by redefining corr.xm as the multiple correlation of the mediator with the confounders as well as the predictor.

Value

b2

minimum absolute detectable effect.

res.uniroot

results of optimization to find the optimal sample size.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Vittinghoff, E. and Sen, S. and McCulloch, C.E.. Sample size calculations for evaluating mediation. Statistics In Medicine. 2009;28:541-557.

See Also

powerMediation.VSMc.poisson, ssMediation.VSMc.poisson

Examples

# example in section 5 (page 546) of Vittinghoff et al. (2009).
  # minimum effect is = log(1.35) = 0.3001046
  minEffect.VSMc.poisson(n = 1239, power = 0.7998578, 
    sigma.m = sqrt(0.25 * (1 - 0.25)), 
    EY = 0.5, corr.xm = 0.5, 
    alpha = 0.05, verbose = TRUE)

Power for testing slope for simple linear regression

Description

Calculate power for testing slope for simple linear regression.

Usage

power.SLR(n, 
          lambda.a, 
          sigma.x, 
          sigma.y, 
          alpha = 0.05, 
          verbose = TRUE)

Arguments

n

sample size.

lambda.a

regression coefficient in the simple linear regression yi=γ+λxi+ϵi,ϵiN(0,σe2).y_i=\gamma+\lambda x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma_{e}^2).

sigma.x

standard deviation of the predictor sd(x)sd(x).

sigma.y

marginal standard deviation of the outcome sd(y)sd(y). (not the marginal standard deviation sd(yx)sd(y|x))

alpha

type I error rate.

verbose

logical. TRUE means printing power; FALSE means not printing power.

Details

The power is for testing the null hypothesis λ=0\lambda=0 versus the alternative hypothesis λ0\lambda\neq 0 for the simple linear regressions:

yi=γ+λxi+ϵi,ϵiN(0,σe2)y_i=\gamma+\lambda x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{e})

Value

power

power for testing if b2=0b_2=0.

delta

λσxn/σy2(λσx)2\lambda\sigma_x\sqrt{n}/\sqrt{\sigma_y^2-(\lambda\sigma_x)^2}.

s

σy2(λσx)2\sqrt{\sigma_y^2-(\lambda\sigma_x)^2}.

t.cr

Φ1(1α/2)\Phi^{-1}(1-\alpha/2), where Φ\Phi is the cumulative distribution function of the standard normal distribution.

rho

correlation between the predictor xx and outcome yy =λσx/σy=\lambda\sigma_x/\sigma_y.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Dupont, W.D. and Plummer, W.D.. Power and Sample Size Calculations for Studies Involving Linear Regression. Controlled Clinical Trials. 1998;19:589-601.

See Also

minEffect.SLR, power.SLR.rho, ss.SLR.rho, ss.SLR.

Examples

power.SLR(n=100, lambda.a=0.8, sigma.x=0.2, sigma.y=0.5, 
    alpha = 0.05, verbose = TRUE)

Power for testing slope for simple linear regression

Description

Calculate power for testing slope for simple linear regression.

Usage

power.SLR.rho(n, 
              rho2, 
              alpha = 0.05, 
              verbose = TRUE)

Arguments

n

sample size.

rho2

square of the correlation between the outcome and the predictor.

alpha

type I error rate.

verbose

logical. TRUE means printing power; FALSE means not printing power.

Details

The power is for testing the null hypothesis λ=0\lambda=0 versus the alternative hypothesis λ0\lambda\neq 0 for the simple linear regressions:

yi=γ+λxi+ϵi,ϵiN(0,σe2)y_i=\gamma+\lambda x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{e})

Value

power

power for testing if b2=0b_2=0.

delta

n/1/ρ21\sqrt{n}/\sqrt{1/\rho^2-1}.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Dupont, W.D. and Plummer, W.D.. Power and Sample Size Calculations for Studies Involving Linear Regression. Controlled Clinical Trials. 1998;19:589-601.

See Also

minEffect.SLR, power.SLR, ss.SLR.rho, ss.SLR.

Examples

power.SLR.rho(n=100, rho2=0.6, alpha = 0.05, verbose = TRUE)

Power Calculation for Interaction Effect in 2x2 Two-Way ANOVA Given Effect Sizes

Description

Power calculation for interaction effect in 2x2 two-way ANOVA given effect sizes.

Usage

powerInteract2by2(n, tauBetaSigma, alpha = 0.05, nTests = 1, verbose = FALSE)

Arguments

n

integer. Number of subjects per group.

tauBetaSigma

Effect sizes (τβ)ij/σ,i=1,,a,j=1,,b\left(\tau\beta\right)_{ij}/\sigma, i=1, \ldots, a, j=1,\ldots, b, where a=b=2a=b=2 and σ\sigma is the standard deviation of random error. Rows are for factor 1 and columns are for factor 2. Note that i=1a(τβ)ij=j=1b(τβ)ij=0\sum_{i=1}^a \left(\tau\beta\right)_{ij} = \sum_{j=1}^b \left(\tau\beta\right)_{ij}=0. We can get (τβ)11=θ\left(\tau\beta\right)_{11}=\theta, (τβ)12=θ\left(\tau\beta\right)_{12}=-\theta, (τβ)21=θ\left(\tau\beta\right)_{21}=-\theta, (τβ)22=θ\left(\tau\beta\right)_{22}=\theta. So tauBetaSigma=θ/σ\theta/\sigma

alpha

family-wise type I error rate.

nTests

integer. For high-throughput omics study, we perform two-way ANOVA for each of 'nTests' probes. We use Bonferroni correction to control for family-wise type I error rate. That is, for each probe, type I error rate would be alpha/nTests.

verbose

logical. Indicating if intermediate results should be printed out.

Details

We assume the following model:

yijk=μ+τi+βj+(τβ)ij+ϵijk,y_{ijk}=\mu+\tau_i + \beta_j + \left(\tau\beta\right)_{ij} + \epsilon_{ijk},

where i=1,,a,j=1,,b,k=1,,ni=1,\ldots, a, j=1,\ldots, b, k=1, \ldots, n, i=1aτi=0\sum_{i=1}^{a}\tau_i = 0, j=1bβj=0\sum_{j=1}^{b}\beta_j = 0, i=1a(τβ)ij=0\sum_{i=1}^{a} \left(\tau\beta\right)_{ij} = 0, j=1b(τβ)ij=0\sum_{j=1}^{b} \left(\tau\beta\right)_{ij} = 0, and ϵijki.i.dN(0,σ2)\epsilon_{ijk}\stackrel{i.i.d}{\sim} N\left(0, \sigma^2\right).

The group means are

μij=μ+τi+βj+(τβ)ij,i=1,a,j=1,,b.\mu_{ij} = \mu+\tau_i + \beta_j + \left(\tau\beta\right)_{ij}, i=1 \ldots, a, j=1,\ldots, b.

Note that μ=i=1aj=1bμij/(ab)\mu = \sum_{i=1}^{a}\sum_{j=1}^b \mu_{ij} / (ab), τi=j=1bμij/bμ\tau_i = \sum_{j=1}^b \mu_{ij}/b - \mu, and βj=i=1aμij/aμ\beta_j = \sum_{i=1}^a \mu_{ij}/a - \mu.

The null hypothesis H0H_0: all (τβ)ij,i=1,,a,j=1,,b\left(\tau\beta\right)_{ij}, i=1, \ldots, a, j=1,\ldots, b are equal to zero. The alternative hypothesis HaH_a: at least one (τβ)ij\left(\tau\beta\right)_{ij} is different from zero.

The F test statistic is

F=MSAB/MSEHaF(a1)(b1),ab(n1),ncp,F=MS_{AB}/MS_{E}\stackrel{H_a}{\sim} F_{(a-1)(b-1), ab(n - 1), ncp},

where ncp is the non-centrality parameter of the F test statistic:

ncp=ni=1aj=1b[(τβ)ijσ]2.ncp=n\sum_{i=1}^{a}\sum_{j=1}^{b}\left[\frac{\left(\tau\beta\right)_{ij}}{\sigma}\right]^2.

For the scenario a=b=2a=b=2, we have (τβ)11=θ\left(\tau\beta\right)_{11}=\theta, (τβ)12=θ\left(\tau\beta\right)_{12}=-\theta, (τβ)21=θ\left(\tau\beta\right)_{21}=-\theta, (τβ)22=θ\left(\tau\beta\right)_{22}=\theta. Hence, the non-centrality parameter can be simplified to

ncp=4n(θσ)2.ncp=4n\left(\frac{\theta}{\sigma}\right)^2.

The power for testing the null hypothesis H0H_0 versus the alternative hypothesis HaH_a is

power=Pr(F>F0Ha),power=Pr\left(F > F_0 | H_a\right),

where the rejection region boundary F0F_0 satisfies:

Pr(F>F0H0)=α/nTests.Pr\left(F > F_0 | H_0\right) = \alpha/nTests.

Value

A list with 5 elements:

power

the power of the two-way ANOVA test

df1

the first degree of freedom of the F test statistic (df1=(a-1)(b-1))

df2

the second degree of freedom of the F test statistic (df1=a*b(n-1))

F0

the rejection region boundary

ncp

the non-centrality parameter

Author(s)

Weiliang Qiu [email protected]

References

Chow SC, Shao J, and Wang H. Sample size calculations in clinical research. 2nd edition. Chapman & Hall/CRC. 2008

Montgomery DC. Design and Analysis of Experiments. 8th edition. John Wiley & Sons. Inc.

Examples

n = 25
tauBetaSigma = 0.3

# power = 0.8437275
res2 = powerInteract2by2(n = n, tauBetaSigma = tauBetaSigma, 
    alpha = 0.05, nTests = 1, verbose = TRUE)

Calculating power for simple logistic regression with binary predictor

Description

Calculating power for simple logistic regression with binary predictor.

Usage

powerLogisticBin(n, 
                 p1, 
                 p2, 
                 B, 
                 alpha = 0.05)

Arguments

n

total number of sample size.

p1

pr(diseasedX=0)pr(diseased|X=0), i.e. the event rate at X=0X=0 in logistic regression logit(p)=a+bXlogit(p) = a + b X, where XX is the binary predictor.

p2

pr(diseasedX=1)pr(diseased|X=1), the event rate at X=1X=1 in logistic regression logit(p)=a+bXlogit(p) = a + b X, where XX is the binary predictor.

B

pr(X=1)pr(X=1), i.e. proportion of the sample with X=1X=1

alpha

Type I error rate.

Details

The logistic regression mode is

log(p/(1p))=β0+β1X\log(p/(1-p)) = \beta_0 + \beta_1 X

where p=prob(Y=1)p=prob(Y=1), XX is the binary predictor, p1=pr(diseasedX=0)p_1=pr(diseased | X=0), p2=pr(diseasedX=1)p_2=pr(diseased| X = 1), B=pr(X=1)B=pr(X=1), and p=(1B)p1+Bp2p = (1 - B) p_1+B p_2. The sample size formula we used for testing if β1=0\beta_1=0, is Formula (2) in Hsieh et al. (1998):

n=(Z1α/2[p(1p)/B]1/2+Zpower[p1(1p1)+p2(1p2)(1B)/B]1/2)2/[(p1p2)2(1B)]n=(Z_{1-\alpha/2}[p(1-p)/B]^{1/2} + Z_{power}[p_1(1-p_1)+p_2(1-p_2)(1-B)/B]^{1/2})^2/[ (p_1-p_2)^2 (1-B) ]

where nn is the required total sample size and ZuZ_u is the uu-th percentile of the standard normal distribution.

Value

Estimated power.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Hsieh, FY, Bloch, DA, and Larsen, MD. A SIMPLE METHOD OF SAMPLE SIZE CALCULATION FOR LINEAR AND LOGISTIC REGRESSION. Statistics in Medicine. 1998; 17:1623-1634.

See Also

powerLogisticBin

Examples

## Example in Table I Design (Balanced design with high event rates) 
    ## of Hsieh et al. (1998 )
    ## the power = 0.95
    powerLogisticBin(n = 1281, p1 = 0.4, p2 = 0.5, B = 0.5, alpha = 0.05)

Calculating power for simple logistic regression with continuous predictor

Description

Calculating power for simple logistic regression with continuous predictor.

Usage

powerLogisticCon(n, 
                 p1, 
                 OR, 
                 alpha = 0.05)

Arguments

n

total sample size.

p1

the event rate at the mean of the continuous predictor XX in logistic regression logit(p)=a+bXlogit(p) = a + b X.

OR

Expected odds ratio. log(OR)\log(OR) is the change in log odds for the difference between at the mean of XX and at one SD above the mean.

alpha

Type I error rate.

Details

The logistic regression mode is

log(p/(1p))=β0+β1X\log(p/(1-p)) = \beta_0 + \beta_1 X

where p=prob(Y=1)p=prob(Y=1), XX is the continuous predictor, and log(OR)\log(OR) is the the change in log odds for the difference between at the mean of XX and at one SD above the mean. The sample size formula we used for testing if β1=0\beta_1=0 or equivalently OR=1OR=1, is Formula (1) in Hsieh et al. (1998):

n=(Z1α/2+Zpower)2/[p1(1p1)[log(OR)]2]n=(Z_{1-\alpha/2} + Z_{power})^2/[ p_1 (1-p_1) [log(OR)]^2 ]

where nn is the required total sample size, OROR is the odds ratio to be tested, p1p_1 is the event rate at the mean of the predictor XX, and ZuZ_u is the uu-th percentile of the standard normal distribution.

Value

Estimated power.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Hsieh, FY, Bloch, DA, and Larsen, MD. A SIMPLE METHOD OF SAMPLE SIZE CALCULATION FOR LINEAR AND LOGISTIC REGRESSION. Statistics in Medicine. 1998; 17:1623-1634.

See Also

SSizeLogisticCon

Examples

## Example in Table II Design (Balanced design (1)) of Hsieh et al. (1998 )
    ## the power is 0.95
    powerLogisticCon(n=317, p1=0.5, OR=exp(0.405), alpha=0.05)

Power calculation for longitudinal study with 2 time point

Description

Power calculation for testing if mean changes for 2 groups are the same or not for longitudinal study with 2 time point.

Usage

powerLong(es, 
          n, 
          rho = 0.5, 
          alpha = 0.05)

Arguments

es

effect size of the difference of mean change.

n

sample size per group.

rho

correlation coefficient between baseline and follow-up values within a treatment group.

alpha

Type I error rate.

Details

The power formula is based on Equation 8.31 on page 336 of Rosner (2006).

power=Φ(Z1α/2+δnσd2)power=\Phi\left(-Z_{1-\alpha/2}+\frac{\delta\sqrt{n}}{\sigma_d \sqrt{2}}\right)

where σd=σ12+σ222ρσ1σ2\sigma_d = \sigma_1^2+\sigma_2^2-2\rho\sigma_1\sigma_2, δ=μ1μ2\delta=|\mu_1 - \mu_2|, μ1\mu_1 is the mean change over time tt in group 1, μ2\mu_2 is the mean change over time tt in group 2, σ12\sigma_1^2 is the variance of baseline values within a treatment group, σ22\sigma_2^2 is the variance of follow-up values within a treatment group, ρ\rho is the correlation coefficient between baseline and follow-up values within a treatment group, and ZuZ_u is the u-th percentile of the standard normal distribution.

We wish to test μ1=μ2\mu_1 = \mu_2.

When σ1=σ2=σ\sigma_1=\sigma_2=\sigma, then formula reduces to

power=Φ(Z1α/2+dn21ρ)power=\Phi\left(-Z_{1-\alpha/2} + \frac{|d|\sqrt{n}}{2\sqrt{1-\rho}}\right)

where d=δ/σd=\delta/\sigma.

Value

power for testing for difference of mean changes.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Rosner, B. Fundamentals of Biostatistics. Sixth edition. Thomson Brooks/Cole. 2006.

See Also

ssLong, ssLongFull, powerLongFull.

Examples

# Example 8.34 on page 336 of Rosner (2006)
    # power=0.75
    powerLong(es=5/15, n=75, rho=0.7, alpha=0.05)

Power calculation for testing if mean changes for 2 groups are the same or not for longitudinal study with more than 2 time points

Description

Power calculation for testing if mean changes for 2 groups are the same or not for longitudinal study with more than 2 time points.

Usage

powerLong.multiTime(es, m, nn, sx2, rho = 0.5, alpha = 0.05)

Arguments

es

effect size

m

number of subjects

nn

number of observations per subject

sx2

within subject variance

rho

within subject correlation

alpha

type I error rate

Details

We are interested in comparing the slopes of the 2 groups AA and BB:

β1A=β1B\beta_{1A} = \beta_{1B}

where

YijA=β0A+β1AxjA+ϵijA,j=1,,nn;i=1,,mY_{ijA}=\beta_{0A}+\beta_{1A} x_{jA} + \epsilon_{ijA}, j=1, \ldots, nn; i=1, \ldots, m

and

YijB=β0B+β1BxjB+ϵijB,j=1,,nn;i=1,,mY_{ijB}=\beta_{0B}+\beta_{1B} x_{jB} + \epsilon_{ijB}, j=1, \ldots, nn; i=1, \ldots, m

The power calculation formula is (Equation on page 30 of Diggle et al. (1994)):

power=Φ[z1α+mnnsx2es22(1ρ)]power=\Phi\left[ -z_{1-\alpha} + \sqrt{\frac{m nn s_x^2 es^2}{2(1-\rho)}} \right]

where es=d/σes=d/\sigma, dd is the meaninful differnce of interest, sigma2sigma^2 is the variance of the random error, ρ\rho is the within-subject correlation, and sx2s_x^2 is the within-subject variance.

Value

power

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Diggle PJ, Liang KY, and Zeger SL (1994). Analysis of Longitundinal Data. page 30. Clarendon Press, Oxford

See Also

ssLong.multiTime

Examples

# power=0.8
  powerLong.multiTime(es=0.5/10, m=196, nn=3, sx2=4.22, rho = 0.5, alpha = 0.05)

Power calculation for longitudinal study with 2 time point

Description

Power calculation for testing if mean changes for 2 groups are the same or not for longitudinal study with 2 time point.

Usage

powerLongFull(delta, 
              sigma1, 
              sigma2, 
              n, 
              rho = 0.5, 
              alpha = 0.05)

Arguments

delta

absolute difference of the mean changes between the two groups: δ=μ1μ2\delta=|\mu_1 - \mu_2| where μ1\mu_1 is the mean change over time tt in group 1, μ2\mu_2 is the mean change over time tt in group 2.

sigma1

the standard deviation of baseline values within a treatment group

sigma2

the standard deviation of follow-up values within a treatment group

n

sample size per group

rho

correlation coefficient between baseline and follow-up values within a treatment group.

alpha

Type I error rate.

Details

The power formula is based on Equation 8.31 on page 336 of Rosner (2006).

power=Φ(Z1α/2+δnσd2)power=\Phi\left(-Z_{1-\alpha/2}+\frac{\delta\sqrt{n}}{\sigma_d \sqrt{2}}\right)

where σd=σ12+σ222ρσ1σ2\sigma_d = \sigma_1^2+\sigma_2^2-2\rho\sigma_1\sigma_2, δ=μ1μ2\delta=|\mu_1 - \mu_2|, μ1\mu_1 is the mean change over time tt in group 1, μ2\mu_2 is the mean change over time tt in group 2, σ12\sigma_1^2 is the variance of baseline values within a treatment group, σ22\sigma_2^2 is the variance of follow-up values within a treatment group, ρ\rho is the correlation coefficient between baseline and follow-up values within a treatment group, and ZuZ_u is the u-th percentile of the standard normal distribution.

We wish to test μ1=μ2\mu_1 = \mu_2.

Value

power for testing for difference of mean changes.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Rosner, B. Fundamentals of Biostatistics. Sixth edition. Thomson Brooks/Cole. 2006.

See Also

ssLong, ssLongFull, powerLong.

Examples

# Example 8.33 on page 336 of Rosner (2006)
    # power=0.80
    powerLongFull(delta=5, sigma1=15, sigma2=15, n=85, rho=0.7, alpha=0.05)

Power for testing mediation effect (Sobel's test)

Description

Calculate power for testing mediation effect based on Sobel's test.

Usage

powerMediation.Sobel(n, 
                     theta.1a, 
                     lambda.a, 
                     sigma.x, 
                     sigma.m,
                     sigma.epsilon, 
                     alpha = 0.05, 
                     verbose = TRUE)

Arguments

n

sample size.

theta.1a

regression coefficient for the predictor in the linear regression linking the predictor xx to the mediator mm (mi=θ0+θ1axi+ei,eiN(0,σe2)m_i=\theta_0+\theta_{1a} x_i + e_i, e_i\sim N(0, \sigma^2_e)).

lambda.a

regression coefficient for the mediator in the linear regression linking the predictor xx and the mediator mm to the outcome yy (yi=γ+λami+λ2xi+ϵi,ϵiN(0,σϵ2)y_i=\gamma+\lambda_{a} m_i+ \lambda_2 x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{\epsilon})).

sigma.x

standard deviation of the predictor.

sigma.m

standard deviation of the mediator.

sigma.epsilon

standard deviation of the random error term in the linear regression linking the predictor xx and the mediator mm to the outcome yy (yi=γ+λami+λ2xi+ϵi,ϵiN(0,σϵ2)y_i=\gamma+\lambda_a m_i+ \lambda_2 x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{\epsilon})).

alpha

type I error.

verbose

logical. TRUE means printing power; FALSE means not printing power.

Details

The power is for testing the null hypothesis θ1λ=0\theta_1\lambda=0 versus the alternative hypothesis θ1aλa0\theta_{1a}\lambda_a\neq 0 for the linear regressions:

mi=θ0+θ1axi+ei,eiN(0,σe2)m_i=\theta_0+\theta_{1a} x_i + e_i, e_i\sim N(0, \sigma^2_e)

yi=γ+λami+λ2xi+ϵi,ϵiN(0,σϵ2)y_i=\gamma+\lambda_a m_i+ \lambda_2 x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{\epsilon})

Test statistic is based on Sobel's (1982) test:

Z=θ^1aλa^σ^θ1aλaZ=\frac{\hat{\theta}_{1a}\hat{\lambda_a}}{\hat{\sigma}_{\theta_{1a}\lambda_a}}

where σ^θ1aλa\hat{\sigma}_{\theta_{1a}\lambda_a} is the estimated standard deviation of the estimate θ^1aλa^\hat{\theta}_{1a}\hat{\lambda_a} using multivariate delta method:

σθ1aλa=θ1a2σλa2+λa2σθ1a2\sigma_{\theta_{1a}\lambda_a}=\sqrt{\theta_{1a}^2\sigma_{\lambda_a}^2+\lambda_a^2\sigma_{\theta_{1a}}^2}

and σθ1a2=σe2/(nσx2)\sigma_{\theta_{1a}}^2=\sigma_e^2/(n\sigma_x^2) is the variance of the estimate θ^1a\hat{\theta}_{1a}, and σλa2=σϵ2/(nσm2(1ρmx2))\sigma_{\lambda_a}^2=\sigma_{\epsilon}^2/(n\sigma_m^2(1-\rho_{mx}^2)) is the variance of the estimate λa^\hat{\lambda_a}, σm2\sigma_m^2 is the variance of the mediator mim_i.

From the linear regression mi=θ0+θ1axi+eim_i=\theta_0+\theta_{1a} x_i+e_i, we have the relationship σe2=σm2(1ρmx2)\sigma_e^2=\sigma_m^2(1-\rho^2_{mx}). Hence, we can simply the variance σθ1a,λa\sigma_{\theta_{1a}, \lambda_a} to

σθ1aλa=θ1a2σϵ2nσm2(1ρmx2)+λa2σm2(1ρmx2)nσx2\sigma_{\theta_{1a}\lambda_a}=\sqrt{\theta_{1a}^2\frac{\sigma_{\epsilon}^2}{n\sigma_m^2(1-\rho_{mx}^2)}+\lambda_a^2\frac{\sigma_{m}^2(1-\rho_{mx}^2)}{n\sigma_x^2}}

Value

power

power of the test for the parameter θ1aλa\theta_{1a}\lambda_a

delta

θ1λ/(sd(θ^1a)sd(λ^a))\theta_1\lambda/(sd(\hat{\theta}_{1a})sd(\hat{\lambda}_a))

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Sobel, M. E. Asymptotic confidence intervals for indirect effects in structural equation models. Sociological Methodology. 1982;13:290-312.

See Also

ssMediation.Sobel, testMediation.Sobel

Examples

powerMediation.Sobel(n=248, theta.1a=0.1701, lambda.a=0.1998, 
   sigma.x=0.57, sigma.m=0.61, sigma.epsilon=0.2, 
   alpha = 0.05, verbose = TRUE)

Power for testing mediation effect in linear regression based on Vittinghoff, Sen and McCulloch's (2009) method

Description

Calculate Power for testing mediation effect in linear regression based on Vittinghoff, Sen and McCulloch's (2009) method.

Usage

powerMediation.VSMc(n, 
                    b2, 
                    sigma.m, 
                    sigma.e, 
                    corr.xm, 
                    alpha = 0.05, 
                    verbose = TRUE)

Arguments

n

sample size.

b2

regression coefficient for the mediator mm in the linear regression yi=b0+b1xi+b2mi+ϵi,ϵiN(0,σe2)y_i=b0+b1 x_i + b2 m_i + \epsilon_i, \epsilon_i\sim N(0, \sigma_e^2).

sigma.m

standard deviation of the mediator.

sigma.e

standard deviation of the random error term in the linear regression yi=b0+b1xi+b2mi+ϵi,ϵiN(0,σe2)y_i=b0+b1 x_i + b2 m_i + \epsilon_i, \epsilon_i\sim N(0, \sigma_e^2).

corr.xm

correlation between the predictor xx and the mediator mm.

alpha

type I error rate.

verbose

logical. TRUE means printing power; FALSE means not printing power.

Details

The power is for testing the null hypothesis b2=0b_2=0 versus the alternative hypothesis b20b_2\neq 0 for the linear regressions:

yi=b0+b1xi+b2mi+ϵi,ϵiN(0,σe2)y_i=b_0+b_1 x_i + b_2 m_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{e})

Vittinghoff et al. (2009) showed that for the above linear regression, testing the mediation effect is equivalent to testing the null hypothesis H0:b2=0H_0: b_2=0 versus the alternative hypothesis Ha:b20H_a: b_2\neq 0.

The full model is

yi=b0+b1xi+b2mi+ϵi,ϵiN(0,σe2)y_i=b_0+b_1 x_i + b_2 m_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{e})

The reduced model is

yi=b0+b1xi+ϵi,ϵiN(0,σe2)y_i=b_0+b_1 x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{e})

Vittinghoff et al. (2009) mentioned that if confounders need to be included in both the full and reduced models, the sample size/power calculation formula could be accommodated by redefining corr.xm as the multiple correlation of the mediator with the confounders as well as the predictor.

Value

power

power for testing if b2=0b_2=0.

delta

b2σm1ρxm2/σeb_2\sigma_m\sqrt{1-\rho_{xm}^2}/\sigma_e, where σm\sigma_m is the standard deviation of the mediator mm, ρxm\rho_{xm} is the correlation between the predictor xx and the mediator mm, and σe\sigma_e is the standard deviation of the random error term in the linear regression.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Vittinghoff, E. and Sen, S. and McCulloch, C.E.. Sample size calculations for evaluating mediation. Statistics In Medicine. 2009;28:541-557.

See Also

minEffect.VSMc, ssMediation.VSMc

Examples

# example in section 3 (page 544) of Vittinghoff et al. (2009).
  # power=0.8
  powerMediation.VSMc(n = 863, b2 = 0.1, sigma.m = 1, sigma.e = 1, 
    corr.xm = 0.3, alpha = 0.05, verbose = TRUE)

Power for testing mediation effect in cox regression based on Vittinghoff, Sen and McCulloch's (2009) method

Description

Calculate Power for testing mediation effect in cox regression based on Vittinghoff, Sen and McCulloch's (2009) method.

Usage

powerMediation.VSMc.cox(n, 
                        b2, 
                        sigma.m, 
                        psi, 
                        corr.xm, 
                        alpha = 0.05, 
                        verbose = TRUE)

Arguments

n

sample size.

b2

regression coefficient for the mediator mm in the cox regression log(λ)=log(λ0)+b1xi+b2mi\log(\lambda)=\log(\lambda_0)+b1 x_i + b2 m_i, where λ\lambda is the hazard function and λ0\lambda_0 is the baseline hazard function.

sigma.m

standard deviation of the mediator.

psi

the probability that an observation is uncensored, so that the number of event d=npsid= n * psi, where nn is the sample size.

corr.xm

correlation between the predictor xx and the mediator mm.

alpha

type I error rate.

verbose

logical. TRUE means printing power; FALSE means not printing power.

Details

The power is for testing the null hypothesis b2=0b_2=0 versus the alternative hypothesis b20b_2\neq 0 for the cox regressions:

log(λ)=log(λ0)+b1xi+b2mi\log(\lambda)=\log(\lambda_0)+b_1 x_i + b_2 m_i

where λ\lambda is the hazard function and λ0\lambda_0 is the baseline hazard function.

Vittinghoff et al. (2009) showed that for the above cox regression, testing the mediation effect is equivalent to testing the null hypothesis H0:b2=0H_0: b_2=0 versus the alternative hypothesis Ha:b20H_a: b_2\neq 0.

The full model is

log(λ)=log(λ0)+b1xi+b2mi\log(\lambda)=\log(\lambda_0)+b_1 x_i + b_2 m_i

The reduced model is

log(λ)=log(λ0)+b1xi\log(\lambda)=\log(\lambda_0)+b_1 x_i

Vittinghoff et al. (2009) mentioned that if confounders need to be included in both the full and reduced models, the sample size/power calculation formula could be accommodated by redefining corr.xm as the multiple correlation of the mediator with the confounders as well as the predictor.

Value

power

power for testing if b2=0b_2=0.

delta

b2σm(1ρxm2)psib_2\sigma_m\sqrt{(1-\rho_{xm}^2) psi}

, where σm\sigma_m is the standard deviation of the mediator mm, ρxm\rho_{xm} is the correlation between the predictor xx and the mediator mm, and psipsi is the probability that an observation is uncensored, so that the number of event d=npsid= n * psi, where nn is the sample size.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Vittinghoff, E. and Sen, S. and McCulloch, C.E.. Sample size calculations for evaluating mediation. Statistics In Medicine. 2009;28:541-557.

See Also

minEffect.VSMc.cox, ssMediation.VSMc.cox

Examples

# example in section 6 (page 547) of Vittinghoff et al. (2009).
  # power = 0.7999916
  powerMediation.VSMc.cox(n = 1399, b2 = log(1.5), 
    sigma.m = sqrt(0.25 * (1 - 0.25)), psi = 0.2, corr.xm = 0.3,
    alpha = 0.05, verbose = TRUE)

Power for testing mediation effect in logistic regression based on Vittinghoff, Sen and McCulloch's (2009) method

Description

Calculate Power for testing mediation effect in logistic regression based on Vittinghoff, Sen and McCulloch's (2009) method.

Usage

powerMediation.VSMc.logistic(n, 
                             b2, 
                             sigma.m, 
                             p, 
                             corr.xm, 
                             alpha = 0.05, 
                             verbose = TRUE)

Arguments

n

sample size.

b2

regression coefficient for the mediator mm in the logistic regression log(pi/(1pi))=b0+b1xi+b2mi\log(p_i/(1-p_i))=b0+b1 x_i + b2 m_i.

sigma.m

standard deviation of the mediator.

p

the marginal prevalence of the outcome.

corr.xm

correlation between the predictor xx and the mediator mm.

alpha

type I error rate.

verbose

logical. TRUE means printing power; FALSE means not printing power.

Details

The power is for testing the null hypothesis b2=0b_2=0 versus the alternative hypothesis b20b_2\neq 0 for the logistic regressions:

log(pi/(1pi))=b0+b1xi+b2mi\log(p_i/(1-p_i))=b0+b1 x_i + b2 m_i

Vittinghoff et al. (2009) showed that for the above logistic regression, testing the mediation effect is equivalent to testing the null hypothesis H0:b2=0H_0: b_2=0 versus the alternative hypothesis Ha:b20H_a: b_2\neq 0.

The full model is

log(pi/(1pi))=b0+b1xi+b2mi\log(p_i/(1-p_i))=b_0+b_1 x_i + b_2 m_i

The reduced model is

log(pi/(1pi))=b0+b1xi\log(p_i/(1-p_i))=b_0+b_1 x_i

Vittinghoff et al. (2009) mentioned that if confounders need to be included in both the full and reduced models, the sample size/power calculation formula could be accommodated by redefining corr.xm as the multiple correlation of the mediator with the confounders as well as the predictor.

Value

power

power for testing if b2=0b_2=0.

delta

b2σm(1ρxm2)p(1p)b_2\sigma_m\sqrt{(1-\rho_{xm}^2) p (1-p)}

, where σm\sigma_m is the standard deviation of the mediator mm, ρxm\rho_{xm} is the correlation between the predictor xx and the mediator mm, and pp is the marginal prevalence of the outcome.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Vittinghoff, E. and Sen, S. and McCulloch, C.E.. Sample size calculations for evaluating mediation. Statistics In Medicine. 2009;28:541-557.

See Also

minEffect.VSMc.logistic, ssMediation.VSMc.logistic

Examples

# example in section 4 (page 545) of Vittinghoff et al. (2009).
  # power = 0.8005793
  powerMediation.VSMc.logistic(n = 255, b2 = log(1.5), sigma.m = 1, 
    p = 0.5, corr.xm = 0.5, alpha = 0.05, verbose = TRUE)

Power for testing mediation effect in poisson regression based on Vittinghoff, Sen and McCulloch's (2009) method

Description

Calculate Power for testing mediation effect in poisson regression based on Vittinghoff, Sen and McCulloch's (2009) method.

Usage

powerMediation.VSMc.poisson(n, 
                            b2, 
                            sigma.m, 
                            EY, 
                            corr.xm, 
                            alpha = 0.05, 
                            verbose = TRUE)

Arguments

n

sample size.

b2

regression coefficient for the mediator mm in the poisson regression log(E(Yi))=b0+b1xi+b2mi\log(E(Y_i))=b0+b1 x_i + b2 m_i.

sigma.m

standard deviation of the mediator.

EY

the marginal mean of the outcome.

corr.xm

correlation between the predictor xx and the mediator mm.

alpha

type I error rate.

verbose

logical. TRUE means printing power; FALSE means not printing power.

Details

The power is for testing the null hypothesis b2=0b_2=0 versus the alternative hypothesis b20b_2\neq 0 for the poisson regressions:

log(E(Yi))=b0+b1xi+b2mi\log(E(Y_i))=b0+b1 x_i + b2 m_i

Vittinghoff et al. (2009) showed that for the above poisson regression, testing the mediation effect is equivalent to testing the null hypothesis H0:b2=0H_0: b_2=0 versus the alternative hypothesis Ha:b20H_a: b_2\neq 0.

The full model is

log(E(Yi))=b0+b1xi+b2mi\log(E(Y_i))=b_0+b_1 x_i + b_2 m_i

The reduced model is

log(E(Yi))=b0+b1xi\log(E(Y_i))=b_0+b_1 x_i

Vittinghoff et al. (2009) mentioned that if confounders need to be included in both the full and reduced models, the sample size/power calculation formula could be accommodated by redefining corr.xm as the multiple correlation of the mediator with the confounders as well as the predictor.

Value

power

power for testing if b2=0b_2=0.

delta

b2σm(1ρxm2)EYb_2\sigma_m\sqrt{(1-\rho_{xm}^2) EY}

, where σm\sigma_m is the standard deviation of the mediator mm, ρxm\rho_{xm} is the correlation between the predictor xx and the mediator mm, and EYEY is the marginal mean of the outcome.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Vittinghoff, E. and Sen, S. and McCulloch, C.E.. Sample size calculations for evaluating mediation. Statistics In Medicine. 2009;28:541-557.

See Also

minEffect.VSMc.poisson, ssMediation.VSMc.poisson

Examples

# example in section 5 (page 546) of Vittinghoff et al. (2009).
  # power = 0.7998578
  powerMediation.VSMc.poisson(n = 1239, b2 = log(1.35), 
    sigma.m = sqrt(0.25 * (1 - 0.25)), EY = 0.5, corr.xm = 0.5,
    alpha = 0.05, verbose = TRUE)

Power calculation for simple Poisson regression

Description

Power calculation for simple Poisson regression. Assume the predictor is normally distributed.

Usage

powerPoisson(
    beta0, 
    beta1, 
    mu.x1, 
    sigma2.x1, 
    mu.T = 1, 
    phi = 1, 
    alpha = 0.05, 
    N = 50)

Arguments

beta0

intercept

beta1

slope

mu.x1

mean of the predictor

sigma2.x1

variance of the predictor

mu.T

mean exposure time

phi

a measure of over-dispersion

alpha

type I error rate

N

toal sample size

Details

The simple Poisson regression has the following form:

Pr(Yi=yiμi,ti)=exp(μiti)(μiti)yi/(yi!)Pr(Y_i = y_i | \mu_i, t_i) = \exp(-\mu_i t_i) (\mu_i t_i)^{y_i}/ (y_i!)

where

μi=exp(β0+β1x1i)\mu_i=\exp(\beta_0+\beta_1 x_{1i})

We are interested in testing the null hypothesis β1=0\beta_1=0 versus the alternative hypothesis β1=θ1\beta_1 = \theta_1. Assume x1x_{1} is normally distributed with mean μx1\mu_{x_1} and variance σx12\sigma^2_{x_1}. The sample size calculation formula derived by Signorini (1991) is

N=ϕ[z1α/2V(b1β1=0)+zpowerV(b1β1=θ1)]2μTexp(β0)θ12N=\phi\frac{\left[z_{1-\alpha/2}\sqrt{V\left(b_1 | \beta_1=0\right)} +z_{power}\sqrt{V\left(b_1 | \beta_1=\theta_1\right)}\right]^2} {\mu_T \exp(\beta_0) \theta_1^2}

where ϕ\phi is the over-dispersion parameter (=var(yi)/mean(yi)=var(y_i)/mean(y_i)), α\alpha is the type I error rate, b1b_1 is the estimate of the slope β1\beta_1, β0\beta_0 is the intercept, μT\mu_T is the mean exposure time, zaz_{a} is the 100a100*a-th lower percentile of the standard normal distribution, and V(b1β1=θ)V\left(b_1|\beta_1=\theta\right) is the variance of the estimate b1b_1 given the true slope β1=θ\beta_1=\theta.

The variances are

V(b1β1=0)=1σx12V\left(b_1 | \beta_1 = 0\right)=\frac{1}{\sigma^2_{x_1}}

and

V(b1β1=θ1)=1σx12exp[(θ1μx1+θ12σx12/2)]V\left(b_1 | \beta_1 = \theta_1\right)=\frac{1}{\sigma^2_{x_1}} \exp\left[-\left(\theta_1 \mu_{x_1} + \theta_1^2\sigma^2_{x_1}/2\right)\right]

Value

power

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu <[email protected]>

References

Signorini D.F. (1991). Sample size for Poisson regression. Biometrika. Vol.78. no.2, pp. 446-50

See Also

See Also as sizePoisson

Examples

# power = 0.8090542
print(powerPoisson(
    beta0 = 0.1, 
    beta1 = 0.5, 
    mu.x1 = 0, 
    sigma2.x1 = 1, 
    mu.T = 1, 
    phi = 1, 
    alpha = 0.05, 
    N = 28))

Sample size calculation for simple Poisson regression

Description

Sample size calculation for simple Poisson regression. Assume the predictor is normally distributed. Two-sided test is used.

Usage

sizePoisson(
    beta0, 
    beta1, 
    mu.x1, 
    sigma2.x1, 
    mu.T = 1, 
    phi = 1, 
    alpha = 0.05, 
    power = 0.8)

Arguments

beta0

intercept

beta1

slope

mu.x1

mean of the predictor

sigma2.x1

variance of the predictor

mu.T

mean exposure time

phi

a measure of over-dispersion

alpha

type I error rate

power

power

Details

The simple Poisson regression has the following form:

Pr(Yi=yiμi,ti)=exp(μiti)(μiti)yi/(yi!)Pr(Y_i = y_i | \mu_i, t_i) = \exp(-\mu_i t_i) (\mu_i t_i)^{y_i}/ (y_i!)

where

μi=exp(β0+β1x1i)\mu_i=\exp(\beta_0+\beta_1 x_{1i})

We are interested in testing the null hypothesis β1=0\beta_1=0 versus the alternative hypothesis β1=θ1\beta_1 = \theta_1. Assume x1x_{1} is normally distributed with mean μx1\mu_{x_1} and variance σx12\sigma^2_{x_1}. The sample size calculation formula derived by Signorini (1991) is

N=ϕ[z1α/2V(b1β1=0)+zpowerV(b1β1=θ1)]2μTexp(β0)θ12N=\phi\frac{\left[z_{1-\alpha/2}\sqrt{V\left(b_1 | \beta_1=0\right)} +z_{power}\sqrt{V\left(b_1 | \beta_1=\theta_1\right)}\right]^2} {\mu_T \exp(\beta_0) \theta_1^2}

where ϕ\phi is the over-dispersion parameter (=var(yi)/mean(yi)=var(y_i)/mean(y_i)), α\alpha is the type I error rate, b1b_1 is the estimate of the slope β1\beta_1, β0\beta_0 is the intercept, μT\mu_T is the mean exposure time, zaz_{a} is the 100a100*a-th lower percentile of the standard normal distribution, and V(b1β1=θ)V\left(b_1|\beta_1=\theta\right) is the variance of the estimate b1b_1 given the true slope β1=θ\beta_1=\theta.

The variances are

V(b1β1=0)=1σx12V\left(b_1 | \beta_1 = 0\right)=\frac{1}{\sigma^2_{x_1}}

and

V(b1β1=θ1)=1σx12exp[(θ1μx1+θ12σx12/2)]V\left(b_1 | \beta_1 = \theta_1\right)=\frac{1}{\sigma^2_{x_1}} \exp\left[-\left(\theta_1 \mu_{x_1} + \theta_1^2\sigma^2_{x_1}/2\right)\right]

Value

total sample size

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu <[email protected]>

References

Signorini D.F. (1991). Sample size for Poisson regression. Biometrika. Vol.78. no.2, pp. 446-50

See Also

See Also as powerPoisson

Examples

# sample size = 28
print(sizePoisson(
  beta0 = 0.1, 
  beta1 = 0.5,
  mu.x1 = 0, 
  sigma2.x1 = 1,
  mu.T = 1, 
  phi = 1,
  alpha = 0.05, 
  power = 0.8))

Sample size for testing slope for simple linear regression

Description

Calculate sample size for testing slope for simple linear regression.

Usage

ss.SLR(power, 
       lambda.a, 
       sigma.x, 
       sigma.y, 
       n.lower = 2.01, 
       n.upper = 1e+30, 
       alpha = 0.05, 
       verbose = TRUE)

Arguments

power

power for testing if λ=0\lambda=0 for the simple linear regression yi=γ+λxi+ϵi,ϵiN(0,σe2).y_i=\gamma+\lambda x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma_{e}^2).

lambda.a

regression coefficient in the simple linear regression yi=γ+λxi+ϵi,ϵiN(0,σe2).y_i=\gamma+\lambda x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma_{e}^2).

sigma.x

standard deviation of the predictor sd(x)sd(x).

sigma.y

marginal standard deviation of the outcome sd(y)sd(y). (not the marginal standard deviation sd(yx)sd(y|x))

n.lower

lower bound for the sample size.

n.upper

upper bound for the sample size.

alpha

type I error rate.

verbose

logical. TRUE means printing sample size; FALSE means not printing sample size.

Details

The test is for testing the null hypothesis λ=0\lambda=0 versus the alternative hypothesis λ0\lambda\neq 0 for the simple linear regressions:

yi=γ+λxi+ϵi,ϵiN(0,σe2)y_i=\gamma+\lambda x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{e})

Value

n

sample size.

res.uniroot

results of optimization to find the optimal sample size.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Dupont, W.D. and Plummer, W.D.. Power and Sample Size Calculations for Studies Involving Linear Regression. Controlled Clinical Trials. 1998;19:589-601.

See Also

minEffect.SLR, power.SLR, power.SLR.rho, ss.SLR.rho.

Examples

ss.SLR(power=0.8, lambda.a=0.8, sigma.x=0.2, sigma.y=0.5, 
    alpha = 0.05, verbose = TRUE)

Sample size for testing slope for simple linear regression based on R2

Description

Calculate sample size for testing slope for simple linear regression based on R2.

Usage

ss.SLR.rho(power, 
           rho2, 
           n.lower = 2.01, 
           n.upper = 1e+30, 
           alpha = 0.05, 
           verbose = TRUE)

Arguments

power

power.

rho2

square of the correlation between the outcome and the predictor.

n.lower

lower bound of the sample size.

n.upper

upper bound o the sample size.

alpha

type I error rate.

verbose

logical. TRUE means printing sample size; FALSE means not printing sample size.

Details

The test is for testing the null hypothesis λ=0\lambda=0 versus the alternative hypothesis λ0\lambda\neq 0 for the simple linear regressions:

yi=γ+λxi+ϵi,ϵiN(0,σe2)y_i=\gamma+\lambda x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{e})

Value

n

sample size.

res.uniroot

results of optimization to find the optimal sample size.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Dupont, W.D. and Plummer, W.D.. Power and Sample Size Calculations for Studies Involving Linear Regression. Controlled Clinical Trials. 1998;19:589-601.

See Also

minEffect.SLR, power.SLR, power.SLR.rho, ss.SLR.

Examples

ss.SLR.rho(power=0.8, rho2=0.6, alpha = 0.05, verbose = TRUE)

Calculating sample size for simple logistic regression with binary predictor

Description

Calculating sample size for simple logistic regression with binary predictor.

Usage

SSizeLogisticBin(p1, 
                 p2, 
                 B, 
                 alpha = 0.05, 
                 power = 0.8)

Arguments

p1

pr(diseasedX=0)pr(diseased | X = 0), i.e. the event rate at X=0X = 0 in logistic regression logit(p)=a+bXlogit(p) = a + b X, where XX is the binary predictor.

p2

pr(diseasedX=1)pr(diseased | X = 1), the event rate at X=1X = 1 in logistic regression logit(p)=a+bXlogit(p) = a + b X, where XX is the binary predictor.

B

pr(X=1)pr(X = 1), i.e. proportion of the sample with X=1X = 1

alpha

Type I error rate.

power

power for testing if the odds ratio is equal to one.

Details

The logistic regression mode is

log(p/(1p))=β0+β1X\log(p / (1 - p)) = \beta_0 + \beta_1 X

where p=prob(Y=1)p = prob(Y = 1), XX is the binary predictor, p1=pr(diseasedX=0)p_1 = pr(diseased | X = 0), p2=pr(diseasedX=1)p_2 = pr(diseased| X = 1), B=pr(X=1)B = pr(X = 1), and p=(1B)p1+Bp2p = (1 - B) p_1 + B p_2. The sample size formula we used for testing if β1=0\beta_1 = 0, is Formula (2) in Hsieh et al. (1998):

n=(Z1α/2[p(1p)/B]1/2+Zpower[p1(1p1)+p2(1p2)(1B)/B]1/2)2/[(p1p2)2(1B)]n = (Z_{1-\alpha/2}[p(1-p)/B]^{1/2} + Z_{power}[p_1(1-p_1)+p_2(1-p_2)(1-B)/B]^{1/2})^2/[ (p_1-p_2)^2 (1-B) ]

where nn is the required total sample size and ZuZ_u is the uu-th percentile of the standard normal distribution.

Value

total sample size required.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Hsieh, FY, Bloch, DA, and Larsen, MD. A SIMPLE METHOD OF SAMPLE SIZE CALCULATION FOR LINEAR AND LOGISTIC REGRESSION. Statistics in Medicine. 1998; 17:1623-1634.

See Also

powerLogisticBin

Examples

## Example in Table I Design (Balanced design with high event rates) 
    ## of Hsieh et al. (1998 )
    ## the sample size is 1281
    SSizeLogisticBin(p1 = 0.4, p2 = 0.5, B = 0.5, alpha = 0.05, power = 0.95)

Calculating sample size for simple logistic regression with continuous predictor

Description

Calculating sample size for simple logistic regression with continuous predictor.

Usage

SSizeLogisticCon(p1, 
                 OR, 
                 alpha = 0.05, 
                 power = 0.8)

Arguments

p1

the event rate at the mean of the continuous predictor X in logistic regression logit(p)=a+bXlogit(p) = a + b X,

OR

Expected odds ratio. log(OR)\log(OR) is the change in log odds for the difference between at the mean of XX and at one SD above the mean.

alpha

Type I error rate.

power

power for testing if the odds ratio is equal to one.

Details

The logistic regression mode is

log(p/(1p))=β0+β1X\log(p/(1-p)) = \beta_0 + \beta_1 X

where p=prob(Y=1)p=prob(Y=1), XX is the continuous predictor, and log(OR)\log(OR) is the the change in log odds for the difference between at the mean of XX and at one SD above the mean. The sample size formula we used for testing if β1=0\beta_1=0 or equivalently OR=1OR=1, is Formula (1) in Hsieh et al. (1998):

n=(Z1α/2+Zpower)2/[p1(1p1)[log(OR)]2]n=(Z_{1-\alpha/2} + Z_{power})^2/[ p_1 (1-p_1) [log(OR)]^2 ]

where nn is the required total sample size, OROR is the odds ratio to be tested, p1p_1 is the event rate at the mean of the predictor XX, and ZuZ_u is the uu-th percentile of the standard normal distribution.

Value

total sample size required.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Hsieh, FY, Bloch, DA, and Larsen, MD. A SIMPLE METHOD OF SAMPLE SIZE CALCULATION FOR LINEAR AND LOGISTIC REGRESSION. Statistics in Medicine. 1998; 17:1623-1634.

See Also

powerLogisticCon

Examples

## Example in Table II Design (Balanced design (1)) of Hsieh et al. (1998 )
    ## the sample size is 317
    SSizeLogisticCon(p1 = 0.5, OR = exp(0.405), alpha = 0.05, power = 0.95)

Sample size calculation for longitudinal study with 2 time point

Description

Sample size calculation for testing if mean changes for 2 groups are the same or not for longitudinal study with 2 time point.

Usage

ssLong(es, 
       rho = 0.5, 
       alpha = 0.05, 
       power = 0.8)

Arguments

es

effect size of the difference of mean change.

rho

correlation coefficient between baseline and follow-up values within a treatment group.

alpha

Type I error rate.

power

power for testing for difference of mean changes.

Details

The sample size formula is based on Equation 8.30 on page 335 of Rosner (2006).

n=2σd2(Z1α/2+Zpower)2δ2n=\frac{2\sigma_d^2 (Z_{1-\alpha/2} + Z_{power})^2}{\delta^2}

where σd=σ12+σ222ρσ1σ2\sigma_d = \sigma_1^2+\sigma_2^2-2\rho\sigma_1\sigma_2, δ=μ1μ2\delta=|\mu_1 - \mu_2|, μ1\mu_1 is the mean change over time tt in group 1, μ2\mu_2 is the mean change over time tt in group 2, σ12\sigma_1^2 is the variance of baseline values within a treatment group, σ22\sigma_2^2 is the variance of follow-up values within a treatment group, ρ\rho is the correlation coefficient between baseline and follow-up values within a treatment group, and ZuZ_u is the u-th percentile of the standard normal distribution.

We wish to test μ1=μ2\mu_1 = \mu_2.

When σ1=σ2=σ\sigma_1=\sigma_2=\sigma, then formula reduces to

n=4(1ρ)(Z1α/2+Zβ)2d2n=\frac{4(1-\rho)(Z_{1-\alpha/2}+Z_{\beta})^2}{d^2}

where d=δ/σd=\delta/\sigma.

Value

required sample size per group

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Rosner, B. Fundamentals of Biostatistics. Sixth edition. Thomson Brooks/Cole. 2006.

See Also

ssLongFull, powerLong, powerLongFull.

Examples

# Example 8.33 on page 336 of Rosner (2006)
    # n=85
    ssLong(es=5/15, rho=0.7, alpha=0.05, power=0.8)

Sample size calculation for testing if mean changes for 2 groups are the same or not for longitudinal study with more than 2 time points

Description

Sample size calculation for testing if mean changes for 2 groups are the same or not for longitudinal study with more than 2 time points.

Usage

ssLong.multiTime(es, power, nn, sx2, rho = 0.5, alpha = 0.05)

Arguments

es

effect size

power

power

nn

number of observations per subject

sx2

within subject variance

rho

within subject correlation

alpha

type I error rate

Details

We are interested in comparing the slopes of the 2 groups AA and BB:

β1A=β1B\beta_{1A} = \beta_{1B}

where

YijA=β0A+β1AxjA+ϵijA,j=1,,nn;i=1,,mY_{ijA}=\beta_{0A}+\beta_{1A} x_{jA} + \epsilon_{ijA}, j=1, \ldots, nn; i=1, \ldots, m

and

YijB=β0B+β1BxjB+ϵijB,j=1,,nn;i=1,,mY_{ijB}=\beta_{0B}+\beta_{1B} x_{jB} + \epsilon_{ijB}, j=1, \ldots, nn; i=1, \ldots, m

The sample size calculation formula is (Equation on page 30 of Diggle et al. (1994)):

m=2(Z1α+zpower)2(1ρ)nnsx2es2m=\frac{2\left(Z_{1-\alpha}+z_{power}\right)^2 \left(1-\rho\right)}{ nn s_x^2 es^2}

where es=d/σes=d/\sigma, dd is the meaninful differnce of interest, sigma2sigma^2 is the variance of the random error, ρ\rho is the within-subject correlation, and sx2s_x^2 is the within-subject variance.

Value

subject per group

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Diggle PJ, Liang KY, and Zeger SL (1994). Analysis of Longitundinal Data. page 30. Clarendon Press, Oxford

See Also

powerLong.multiTime

Examples

# subject per group = 196
ssLong.multiTime(es=0.5/10, power=0.8, nn=3, sx2=4.22, rho = 0.5, alpha=0.05)

Sample size calculation for longitudinal study with 2 time point

Description

Sample size calculation for testing if mean changes for 2 groups are the same or not for longitudinal study with 2 time point.

Usage

ssLongFull(delta, 
           sigma1, 
           sigma2, 
           rho = 0.5, 
           alpha = 0.05, 
           power = 0.8)

Arguments

delta

absolute difference of the mean changes between the two groups: δ=μ1μ2\delta=|\mu_1 - \mu_2| where μ1\mu_1 is the mean change over time tt in group 1, μ2\mu_2 is the mean change over time tt in group 2.

sigma1

the standard deviation of baseline values within a treatment group

sigma2

the standard deviation of follow-up values within a treatment group

rho

correlation coefficient between baseline and follow-up values within a treatment group.

alpha

Type I error rate

power

power for testing for difference of mean changes.

Details

The sample size formula is based on Equation 8.30 on page 335 of Rosner (2006).

n=2σd2(Z1α/2+Zpower)2δ2n=\frac{2\sigma_d^2 (Z_{1-\alpha/2} + Z_{power})^2}{\delta^2}

where σd=σ12+σ222ρσ1σ2\sigma_d = \sigma_1^2+\sigma_2^2-2\rho\sigma_1\sigma_2, δ=μ1μ2\delta=|\mu_1 - \mu_2|, μ1\mu_1 is the mean change over time tt in group 1, μ2\mu_2 is the mean change over time tt in group 2, σ12\sigma_1^2 is the variance of baseline values within a treatment group, σ22\sigma_2^2 is the variance of follow-up values within a treatment group, ρ\rho is the correlation coefficient between baseline and follow-up values within a treatment group, and ZuZ_u is the u-th percentile of the standard normal distribution.

We wish to test μ1=μ2\mu_1 = \mu_2.

Value

required sample size per group

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Rosner, B. Fundamentals of Biostatistics. Sixth edition. Thomson Brooks/Cole. 2006.

See Also

ssLong, powerLong, powerLongFull.

Examples

# Example 8.33 on page 336 of Rosner (2006)
    # n=85
    ssLongFull(delta=5, sigma1=15, sigma2=15, rho=0.7, alpha=0.05, power=0.8)

Sample size for testing mediation effectd (Sobel's test)

Description

Calculate sample size for testing mediation effect based on Sobel's test.

Usage

ssMediation.Sobel(power, 
                  theta.1a, 
                  lambda.a, 
                  sigma.x, 
                  sigma.m,
                  sigma.epsilon, 
                  n.lower = 1, 
                  n.upper = 1e+30, 
                  alpha = 0.05, 
                  verbose = TRUE)

Arguments

power

power of the test.

theta.1a

regression coefficient for the predictor in the linear regression linking the predictor xx to the mediator mm (mi=θ0+θ1axi+ei,eiN(0,σe2)m_i=\theta_0+\theta_{1a} x_i + e_i, e_i\sim N(0, \sigma^2_e)).

lambda.a

regression coefficient for the mediator in the linear regression linking the predictor xx and the mediator mm to the outcome yy (yi=γ+λami+λ2xi+ϵi,ϵiN(0,σϵ2)y_i=\gamma+\lambda_a m_i+ \lambda_2 x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{\epsilon})).

sigma.x

standard deviation of the predictor.

sigma.m

standard deviation of the mediator.

sigma.epsilon

standard deviation of the random error term in the linear regression linking the predictor xx and the mediator mm to the outcome yy (yi=γ+λami+λ2xi+ϵi,ϵiN(0,σϵ2)y_i=\gamma+\lambda_a m_i+ \lambda_2 x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{\epsilon})).

n.lower

lower bound of the sample size.

n.upper

upper bound of the sample size.

alpha

type I error rate.

verbose

logical. TRUE means printing power; FALSE means not printing power.

Details

The sample size is for testing the null hypothesis θ1λ=0\theta_1\lambda=0 versus the alternative hypothesis θ1aλa0\theta_{1a}\lambda_a\neq 0 for the linear regressions:

mi=θ0+θ1axi+ei,eiN(0,σe2)m_i=\theta_0+\theta_{1a} x_i + e_i, e_i\sim N(0, \sigma^2_e)

yi=γ+λami+λ2xi+ϵi,ϵiN(0,σϵ2)y_i=\gamma+\lambda_a m_i+ \lambda_2 x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{\epsilon})

Test statistic is based on Sobel's (1982) test:

Z=θ^1aλa^σ^θ1aλaZ=\frac{\hat{\theta}_{1a}\hat{\lambda_a}}{\hat{\sigma}_{\theta_{1a}\lambda_a}}

where σ^θ1aλa\hat{\sigma}_{\theta_{1a}\lambda_a} is the estimated standard deviation of the estimate θ^1aλa^\hat{\theta}_{1a}\hat{\lambda_a} using multivariate delta method:

σθ1aλa=θ1a2σλa2+λa2σθ1a2\sigma_{\theta_{1a}\lambda_a}=\sqrt{\theta_{1a}^2\sigma_{\lambda_a}^2+\lambda_a^2\sigma_{\theta_{1a}}^2}

and σθ1a2=σe2/(nσx2)\sigma_{\theta_{1a}}^2=\sigma_e^2/(n\sigma_x^2) is the variance of the estimate θ^1a\hat{\theta}_{1a}, and σλa2=σϵ2/(nσm2(1ρmx2))\sigma_{\lambda_a}^2=\sigma_{\epsilon}^2/(n\sigma_m^2(1-\rho_{mx}^2)) is the variance of the estimate λa^\hat{\lambda_a}, σm2\sigma_m^2 is the variance of the mediator mim_i.

From the linear regression mi=θ0+θ1axi+eim_i=\theta_0+\theta_{1a} x_i+e_i, we have the relationship σe2=σm2(1ρmx2)\sigma_e^2=\sigma_m^2(1-\rho^2_{mx}). Hence, we can simply the variance σθ1a,λa\sigma_{\theta_{1a}, \lambda_a} to

σθ1aλa=θ1a2σϵ2nσm2(1ρmx2)+λa2σm2(1ρmx2)nσx2\sigma_{\theta_{1a}\lambda_a}=\sqrt{\theta_{1a}^2\frac{\sigma_{\epsilon}^2}{n\sigma_m^2(1-\rho_{mx}^2)}+\lambda_a^2\frac{\sigma_{m}^2(1-\rho_{mx}^2)}{n\sigma_x^2}}

Value

n

sample size.

res.uniroot

results of optimization to find the optimal sample size.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Sobel, M. E. Asymptotic confidence intervals for indirect effects in structural equation models. Sociological Methodology. 1982;13:290-312.

See Also

powerMediation.Sobel, testMediation.Sobel

Examples

ssMediation.Sobel(power=0.8, theta.1a=0.1701, lambda.a=0.1998, 
   sigma.x=0.57, sigma.m=0.61, sigma.epsilon=0.2, 
   alpha = 0.05, verbose = TRUE)

Sample size for testing mediation effect in linear regression based on Vittinghoff, Sen and McCulloch's (2009) method

Description

Calculate sample size for testing mediation effect in linear regression based on Vittinghoff, Sen and McCulloch's (2009) method.

Usage

ssMediation.VSMc(power, 
                 b2, 
                 sigma.m, 
                 sigma.e, 
                 corr.xm, 
                 n.lower = 1, 
                 n.upper = 1e+30, 
                 alpha = 0.05, 
                 verbose = TRUE)

Arguments

power

power for testing b2=0b_2=0 for the linear regression yi=b0+b1xi+b2mi+ϵi,ϵiN(0,σe2)y_i=b0+b1 x_i + b2 m_i + \epsilon_i, \epsilon_i\sim N(0, \sigma_e^2).

b2

regression coefficient for the mediator mm in the linear regression yi=b0+b1xi+b2mi+ϵi,ϵiN(0,σe2)y_i=b0+b1 x_i + b2 m_i + \epsilon_i, \epsilon_i\sim N(0, \sigma_e^2).

sigma.m

standard deviation of the mediator.

sigma.e

standard deviation of the random error term in the linear regression yi=b0+b1xi+b2mi+ϵi,ϵiN(0,σe2)y_i=b0+b1 x_i + b2 m_i + \epsilon_i, \epsilon_i\sim N(0, \sigma_e^2).

corr.xm

correlation between the predictor xx and the mediator mm.

n.lower

lower bound for the sample size.

n.upper

upper bound for the sample size.

alpha

type I error rate.

verbose

logical. TRUE means printing sample size; FALSE means not printing sample size.

Details

The test is for testing the null hypothesis b2=0b_2=0 versus the alternative hypothesis b20b_2\neq 0 for the linear regressions:

yi=b0+b1xi+b2mi+ϵi,ϵiN(0,σe2)y_i=b_0+b_1 x_i + b_2 m_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{e})

Vittinghoff et al. (2009) showed that for the above linear regression, testing the mediation effect is equivalent to testing the null hypothesis H0:b2=0H_0: b_2=0 versus the alternative hypothesis Ha:b20H_a: b_2\neq 0.

The full model is

yi=b0+b1xi+b2mi+ϵi,ϵiN(0,σe2)y_i=b_0+b_1 x_i + b_2 m_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{e})

The reduced model is

yi=b0+b1xi+ϵi,ϵiN(0,σe2)y_i=b_0+b_1 x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{e})

Vittinghoff et al. (2009) mentioned that if confounders need to be included in both the full and reduced models, the sample size/power calculation formula could be accommodated by redefining corr.xm as the multiple correlation of the mediator with the confounders as well as the predictor.

Value

n

sample size.

res.uniroot

results of optimization to find the optimal sample size.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Vittinghoff, E. and Sen, S. and McCulloch, C.E.. Sample size calculations for evaluating mediation. Statistics In Medicine. 2009;28:541-557.

See Also

minEffect.VSMc, powerMediation.VSMc

Examples

# example in section 3 (page 544) of Vittinghoff et al. (2009).
  # n=863
  ssMediation.VSMc(power = 0.80, b2 = 0.1, sigma.m = 1, sigma.e = 1, 
    corr.xm = 0.3, alpha = 0.05, verbose = TRUE)

Sample size for testing mediation effect in cox regression based on Vittinghoff, Sen and McCulloch's (2009) method

Description

Calculate sample size for testing mediation effect in cox regression based on Vittinghoff, Sen and McCulloch's (2009) method.

Usage

ssMediation.VSMc.cox(power, 
                     b2, 
                     sigma.m, 
                     psi, 
                     corr.xm, 
                     n.lower = 1, 
                     n.upper = 1e+30, 
                     alpha = 0.05, 
                     verbose=TRUE)

Arguments

power

power for testing b2=0b_2=0 for the cox regression log(λ)=log(λ0)+b1xi+b2mi\log(\lambda)=\log(\lambda_0)+b1 x_i + b2 m_i, where λ\lambda is the hazard function and λ0\lambda_0 is the baseline hazard function.

b2

regression coefficient for the mediator mm in the cox regression log(λ)=log(λ0)+b1xi+b2mi\log(\lambda)=\log(\lambda_0)+b1 x_i + b2 m_i, where λ\lambda is the hazard function and λ0\lambda_0 is the baseline hazard function.

sigma.m

standard deviation of the mediator.

psi

the probability that an observation is uncensored, so that the number of event d=npsid= n * psi, where nn is the sample size.

corr.xm

correlation between the predictor xx and the mediator mm.

n.lower

lower bound for the sample size.

n.upper

upper bound for the sample size.

alpha

type I error rate.

verbose

logical. TRUE means printing sample size; FALSE means not printing sample size.

Details

The test is for testing the null hypothesis b2=0b_2=0 versus the alternative hypothesis b20b_2\neq 0 for the cox regressions:

log(λ)=log(λ0)+b1xi+b2mi\log(\lambda)=\log(\lambda_0)+b1 x_i + b2 m_i

Vittinghoff et al. (2009) showed that for the above cox regression, testing the mediation effect is equivalent to testing the null hypothesis H0:b2=0H_0: b_2=0 versus the alternative hypothesis Ha:b20H_a: b_2\neq 0.

The full model is

log(λ)=log(λ0)+b1xi+b2mi\log(\lambda)=\log(\lambda_0)+b_1 x_i + b_2 m_i

The reduced model is

log(λ)=log(λ0)+b1xi\log(\lambda)=\log(\lambda_0)+b_1 x_i

Vittinghoff et al. (2009) mentioned that if confounders need to be included in both the full and reduced models, the sample size/power calculation formula could be accommodated by redefining corr.xm as the multiple correlation of the mediator with the confounders as well as the predictor.

Value

n

sample size.

res.uniroot

results of optimization to find the optimal sample size.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Vittinghoff, E. and Sen, S. and McCulloch, C.E.. Sample size calculations for evaluating mediation. Statistics In Medicine. 2009;28:541-557.

See Also

minEffect.VSMc.cox, powerMediation.VSMc.cox

Examples

# example in section 6 (page 547) of Vittinghoff et al. (2009).
  # n = 1399
  ssMediation.VSMc.cox(power = 0.7999916, b2 = log(1.5), 
    sigma.m = sqrt(0.25 * (1 - 0.25)), psi = 0.2, corr.xm = 0.3,
    alpha = 0.05, verbose = TRUE)

Sample size for testing mediation effect in logistic regression based on Vittinghoff, Sen and McCulloch's (2009) method

Description

Calculate sample size for testing mediation effect in logistic regression based on Vittinghoff, Sen and McCulloch's (2009) method.

Usage

ssMediation.VSMc.logistic(power, 
                          b2, 
                          sigma.m, 
                          p, 
                          corr.xm, 
                          n.lower = 1, 
                          n.upper = 1e+30, 
                          alpha = 0.05, 
                          verbose = TRUE)

Arguments

power

power for testing b2=0b_2=0 for the logistic regression log(pi/(1pi))=b0+b1xi+b2mi\log(p_i/(1-p_i))=b0+b1 x_i + b2 m_i.

b2

regression coefficient for the mediator mm in the logistic regression log(pi/(1pi))=b0+b1xi+b2mi\log(p_i/(1-p_i))=b0+b1 x_i + b2 m_i.

sigma.m

standard deviation of the mediator.

p

the marginal prevalence of the outcome.

corr.xm

correlation between the predictor xx and the mediator mm.

n.lower

lower bound for the sample size.

n.upper

upper bound for the sample size.

alpha

type I error rate.

verbose

logical. TRUE means printing sample size; FALSE means not printing sample size.

Details

The test is for testing the null hypothesis b2=0b_2=0 versus the alternative hypothesis b20b_2\neq 0 for the logistic regressions:

log(pi/(1pi))=b0+b1xi+b2mi\log(p_i/(1-p_i))=b_0+b_1 x_i + b_2 m_i

Vittinghoff et al. (2009) showed that for the above logistic regression, testing the mediation effect is equivalent to testing the null hypothesis H0:b2=0H_0: b_2=0 versus the alternative hypothesis Ha:b20H_a: b_2\neq 0.

The full model is

log(pi/(1pi))=b0+b1xi+b2mi\log(p_i/(1-p_i))=b_0+b_1 x_i + b_2 m_i

The reduced model is

log(pi/(1pi))=b0+b1xi\log(p_i/(1-p_i))=b_0+b_1 x_i

Vittinghoff et al. (2009) mentioned that if confounders need to be included in both the full and reduced models, the sample size/power calculation formula could be accommodated by redefining corr.xm as the multiple correlation of the mediator with the confounders as well as the predictor.

Value

n

sample size.

res.uniroot

results of optimization to find the optimal sample size.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Vittinghoff, E. and Sen, S. and McCulloch, C.E.. Sample size calculations for evaluating mediation. Statistics In Medicine. 2009;28:541-557.

See Also

minEffect.VSMc.logistic, powerMediation.VSMc.logistic

Examples

# example in section 4 (page 545) of Vittinghoff et al. (2009).
  # n=255

  ssMediation.VSMc.logistic(power = 0.80, b2 = log(1.5), sigma.m = 1, p = 0.5, 
    corr.xm = 0.5, alpha = 0.05, verbose = TRUE)

Sample size for testing mediation effect in poisson regression based on Vittinghoff, Sen and McCulloch's (2009) method

Description

Calculate sample size for testing mediation effect in poisson regression based on Vittinghoff, Sen and McCulloch's (2009) method.

Usage

ssMediation.VSMc.poisson(power, 
                         b2, 
                         sigma.m, 
                         EY, 
                         corr.xm, 
                         n.lower = 1, 
                         n.upper = 1e+30, 
                         alpha = 0.05, 
                         verbose = TRUE)

Arguments

power

power for testing b2=0b_2=0 for the poisson regression log(E(Yi))=b0+b1xi+b2mi\log(E(Y_i))=b0+b1 x_i + b2 m_i.

b2

regression coefficient for the mediator mm in the poisson regression log(E(Yi))=b0+b1xi+b2mi\log(E(Y_i))=b0+b1 x_i + b2 m_i.

sigma.m

standard deviation of the mediator.

EY

the marginal mean of the outcome.

corr.xm

correlation between the predictor xx and the mediator mm.

n.lower

lower bound for the sample size.

n.upper

upper bound for the sample size.

alpha

type I error rate.

verbose

logical. TRUE means printing sample size; FALSE means not printing sample size.

Details

The test is for testing the null hypothesis b2=0b_2=0 versus the alternative hypothesis b20b_2\neq 0 for the poisson regressions:

log(E(Yi))=b0+b1xi+b2mi\log(E(Y_i))=b_0+b_1 x_i + b_2 m_i

Vittinghoff et al. (2009) showed that for the above poisson regression, testing the mediation effect is equivalent to testing the null hypothesis H0:b2=0H_0: b_2=0 versus the alternative hypothesis Ha:b20H_a: b_2\neq 0.

The full model is

log(E(Yi))=b0+b1xi+b2mi\log(E(Y_i))=b_0+b_1 x_i + b_2 m_i

The reduced model is

log(E(Yi))=b0+b1xi\log(E(Y_i))=b_0+b_1 x_i

Vittinghoff et al. (2009) mentioned that if confounders need to be included in both the full and reduced models, the sample size/power calculation formula could be accommodated by redefining corr.xm as the multiple correlation of the mediator with the confounders as well as the predictor.

Value

n

sample size.

res.uniroot

results of optimization to find the optimal sample size.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Vittinghoff, E. and Sen, S. and McCulloch, C.E.. Sample size calculations for evaluating mediation. Statistics In Medicine. 2009;28:541-557.

See Also

minEffect.VSMc.poisson, powerMediation.VSMc.poisson

Examples

# example in section 5 (page 546) of Vittinghoff et al. (2009).
  # n = 1239
  ssMediation.VSMc.poisson(power = 0.7998578, b2 = log(1.35), 
    sigma.m = sqrt(0.25 * (1 - 0.25)), EY = 0.5, corr.xm = 0.5,
    alpha = 0.05, verbose = TRUE)

P-value and confidence interval for testing mediation effect (Sobel's test)

Description

Calculate p-value and confidence interval for testing mediation effect based on Sobel's test.

Usage

testMediation.Sobel(theta.1.hat, 
                    lambda.hat, 
                    sigma.theta1, 
                    sigma.lambda, 
                    alpha = 0.05)

Arguments

theta.1.hat

estimated regression coefficient for the predictor in the linear regression linking the predictor xx to the mediator mm (mi=θ0+θ1xi+ei,eiN(0,σe2)m_i=\theta_0+\theta_1 x_i + e_i, e_i\sim N(0, \sigma^2_e)).

lambda.hat

estimated regression coefficient for the mediator in the linear regression linking the predictor xx and the mediator mm to the outcome yy (yi=γ+λmi+λ2xi+ϵi,ϵiN(0,σϵ2)y_i=\gamma+\lambda m_i+ \lambda_2 x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{\epsilon})).

sigma.theta1

standard deviation of θ^1\hat{\theta}_1 in the linear regression linking the predictor xx to the mediator mm (mi=θ0+θ1xi+ei,eiN(0,σe2)m_i=\theta_0+\theta_1 x_i + e_i, e_i\sim N(0, \sigma^2_e)).

sigma.lambda

standard deviation of λ^\hat{\lambda} in the linear regression linking the predictor xx and the mediator mm to the outcome yy (yi=γ+λmi+λ2xi+ϵi,ϵiN(0,σϵ2)y_i=\gamma+\lambda m_i+ \lambda_2 x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{\epsilon})).

alpha

significance level of a test.

Details

The test is for testing the null hypothesis θ1λ=0\theta_1\lambda=0 versus the alternative hypothesis θ1aλa0\theta_{1a}\lambda_a\neq 0 for the linear regressions:

mi=θ0+θ1xi+ei,eiN(0,σe2)m_i=\theta_0+\theta_1 x_i + e_i, e_i\sim N(0, \sigma^2_e)

yi=γ+λmi+λ2xi+ϵi,ϵiN(0,σϵ2)y_i=\gamma+\lambda m_i+ \lambda_2 x_i + \epsilon_i, \epsilon_i\sim N(0, \sigma^2_{\epsilon})

Test statistic is based on Sobel's (1982) test:

Z=θ^1λ^σ^θ1λZ=\frac{\hat{\theta}_1\hat{\lambda}}{\hat{\sigma}_{\theta_1\lambda}}

where σ^θ1λ\hat{\sigma}_{\theta_1\lambda} is the estimated standard deviation of the estimate θ^1λ^\hat{\theta}_1\hat{\lambda} using multivariate delta method:

σθ1λ=θ12σλ2+λ2σθ12\sigma_{\theta_1\lambda}=\sqrt{\theta_1^2\sigma_{\lambda}^2+\lambda^2\sigma_{\theta_1}^2}

and σ^θ1\hat{\sigma}_{\theta_1} is the estimated standard deviation of the estimate θ^1\hat{\theta}_1, and σ^λ\hat{\sigma}_{\lambda} is the estimated standard deviation of the estimate λ^\hat{\lambda}.

Value

pval

p-value for testing the null hypothesis θ1λ=0\theta_1\lambda=0 versus the alternative hypothesis θ1aλa0\theta_{1a}\lambda_a\neq 0.

CI.low

Lower bound of the 100(1α)%100 (1-\alpha)\% confidence interval for the parameter θ1λ\theta_1\lambda.

CI.upp

Upper bound of the 100(1α)%100 (1-\alpha)\% confidence interval for the parameter θ1λ\theta_1\lambda.

Note

The test is a two-sided test. For one-sided tests, please double the significance level. For example, you can set alpha=0.10 to obtain one-sided test at 5% significance level.

Author(s)

Weiliang Qiu [email protected]

References

Sobel, M. E. Asymptotic confidence intervals for indirect effects in structural equation models. Sociological Methodology. 1982;13:290-312.

See Also

powerMediation.Sobel, ssMediation.Sobel

Examples

testMediation.Sobel(theta.1.hat=0.1701, lambda.hat=0.1998, 
    sigma.theta1=0.01, sigma.lambda=0.02, alpha=0.05)