| distribution | R Documentation |
Constructs a list which defines the test statistic reference distribution under the null hypothesis.
asymptotic()
simulated(method = "approximate", nsims = 1000L, ncores = 1L, ...)
method |
(Scalar string: |
nsims |
(Scalar integer: |
ncores |
(Scalar integer: |
... |
Optional arguments for internal use. |
The default asymptotic test is performed for distribution = asymptotic().
When setting argument distribution = simulated(method = "exact"), the
exact randomization test is defined by:
Independent two-sample tests
Calculate the observed test statistic.
Check if length(combn(x=n1+n2, m=n1))<1e6
If TRUE continue with the exact randomization test.
If FALSE revert to the approximate randomization test.
For all combn(x=n1+n2, m=n1) permutations:
Assign corresponding group labels.
Calculate the test statistic.
Calculate the exact randomization test p-value as the mean of the logical
vector resampled_test_stats >= observed_test_stat.
Dependent two-sample tests
Calculate the observed test statistic.
Check if npairs < 21 (maximum 2^20 resamples)
If TRUE continue with the exact randomization test.
If FALSE revert to the approximate randomization test.
For all 2^npairs permutations:
Assign corresponding pair labels.
Calculate the test statistic.
Calculate the exact randomization test p-value as the mean of the logical
vector resampled_test_stats >= observed_test_stat.
For argument distribution = simulated(method = "approximate"), the
approximate randomization test is defined by:
Independent two-sample tests
Calculate the observed test statistic.
For nsims iterations:
Randomly assign group labels.
Calculate the test statistic.
Insert the observed test statistic to the vector of resampled test statistics.
Calculate the approximate randomization test p-value as the mean of
the logical vector resampled_test_stats >= observed_test_stat.
Dependent two-sample tests
Calculate the observed test statistic.
For nsims iterations:
Randomly assign pair labels.
Calculate the test statistic.
Insert the observed test statistic to the vector of resampled test statistics.
Calculate the approximate randomization test p-value as the mean of
the logical vector resampled_test_stats >= observed_test_stat.
In the power analysis setting, power(), we can simulate data for
groups 1 and 2 using their known distributions under the assumptions of the
null hypothesis. Unlike above where nonparametric randomization tests
are performed, in this setting approximate parametric tests are performed.
For example, power(wald_test_nb(distribution = simulated())) would result
in an approximate parametric Wald test defined by:
For each relevant design row in data:
For simulated(nsims=integer()) iterations:
Simulate new data for group 1 and group 2 under the null hypothesis.
Calculate the Wald test statistic, \chi^2_{null}.
Collect all \chi^2_{null} into a vector.
For each of the sim_nb(nsims=integer()) simulated datasets:
Calculate the Wald test statistic, \chi^2_{obs}.
Calculate the p-value based on the empirical null distribution of test statistics, \chi^2_{null}.
(the mean of the logical vector null_test_stats >= observed_test_stat)
Collect all p-values into a vector.
Calculate power as sum(p <= alpha) / nsims.
Return all results from power().
Randomization tests use the positive-biased p-value estimate in the style of \insertCitedavison_1997;textualdepower (see also \insertCitephipson_2010;textualdepower):
\hat{p} = \frac{1 + \sum_{i=1}^B \mathbb{I} \{\chi^2_i \geq \chi^2_{obs}\}}{B + 1}.
The number of resamples defines the minimum observable p-value
(e.g. nsims=1000L results in min(p-value)=1/1001).
It's recommended to set \text{nsims} \gg \frac{1}{\alpha}.
list
davison_1997depower
\insertRefphipson_2010depower
#----------------------------------------------------------------------------
# asymptotic() examples
#----------------------------------------------------------------------------
library(depower)
set.seed(1234)
data <- sim_nb(
n1 = 60,
n2 = 40,
mean1 = 10,
ratio = 1.5,
dispersion1 = 2,
dispersion2 = 8
)
data |>
wald_test_nb(distribution = asymptotic())
#----------------------------------------------------------------------------
# simulated() examples
#----------------------------------------------------------------------------
data |>
wald_test_nb(distribution = simulated(nsims = 200L))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.