Calculates sample size or power for a two-sample proportion test.
Usage
two_prop_size(
pA,
pB,
delta = NULL,
kappa = 1,
alpha,
beta = NULL,
nB = NULL,
test_type = "2-side"
)
Arguments
- pA
Numeric. True proportion of group A.
- pB
Numeric. True proportion of group B.
- delta
Numeric (optional). Margin for
"non-inferiority"
or"equivalence"
test. Required for"non-inferiority"
or"equivalence"
test.- kappa
Numeric. Ratio of sample sizes (nA/nB). Default is 1.
- alpha
Numeric. Type I error rate.
- beta
Numeric (optional). Type II error rate. Required for sample size calculation.
- nB
Integer (optional). Sample size for group B. Required for power calculation.
- test_type
Character.
"2-side"
,"1-side"
,"non-inferiority"
, or"equivalence"
. Default is"2-side"
.
Note
Only one of beta
(for sample size calculation) or nA
/nB
(for power calculation) should be specified.
Required arguments by test_type
:
"2-side"
/"1-side"
:For sample size:
pA
,pB
,alpha
,beta
For power:
pA
,pB
,alpha
,nB
"non-inferiority"
/"equivalence"
:For sample size:
pA
,pB
,delta
,alpha
,beta
For power:
pA
,pB
,delta
,alpha
,nB
Examples
# Sample size for `"2-side"` test
two_prop_size(pA = 0.65, pB = 0.85, kappa = 1,
alpha = 0.05, beta = 0.2, test_type = "2-side")
#> [1] 70
# Power of `"2-side"` test
two_prop_size(pA = 0.65, pB = 0.85, kappa = 1,
alpha = 0.05, nB = 70, test_type = "2-side")
#> [1] 0.8019139
# Sample size for `"1-side"` test
two_prop_size(pA = 0.65, pB = 0.85, kappa = 1,
alpha = 0.05, beta = 0.2, test_type = "1-side")
#> [1] 55
# Power of `"1-sided"` test
two_prop_size(pA = 0.65, pB = 0.85, kappa = 1,
alpha = 0.05, nB = 55, test_type = "1-side")
#> [1] 0.8008219
# Sample size for `"non-inferiority"` test
two_prop_size(pA = 0.85, pB = 0.65, delta = -0.1, kappa = 1,
alpha = 0.05, beta = 0.2, test_type = "non-inferiority")
#> [1] 25
# Power of `"non-inferiority"` test
two_prop_size(pA = 0.85, pB = 0.65, delta = -0.1, kappa = 1,
alpha = 0.05, nB = 25, test_type = "non-inferiority")
#> [1] 0.8085998
# Sample size for `"equivalence"` test
two_prop_size(pA = 0.65, pB = 0.85, delta = 0.05, kappa = 1,
alpha = 0.05, beta = 0.2, test_type = "equivalence")
#> [1] 136
# Power of `"equivalence"` test
two_prop_size(pA = 0.65, pB = 0.85, delta = 0.05, kappa = 1,
alpha = 0.05, nB = 136, test_type = "equivalence")
#> [1] 0.8033294