pow | R Documentation |
Calculates power and local alphas based on simulated p values
(which should be provided as created by the
POSSA::sim
function). The calculation for
sequential testing involves a staircase procedure during which an initially
provided set of local alphas is continually adjusted until the (approximate)
specified global type 1 error rate (e.g., global alpha = .05) is reached:
the value of adjustment is decreasing while global type 1 error rate is
larger than specified, and increasing while global type 1 error rate is
smaller than specified; a smaller step is chosen whenever the direction
(increase vs. decrease) changes; the procedure stops when the global type 1
error rate is close enough to the specified one (e.g., matches it up to 4
fractional digits) or when the specified smallest step is passed. The
adjustment works via a dedicated ("adjust
") function that either
replaces missing (NA
) values with varying alternatives or (when there
are no missing values) in some manner varyingly modifies the initial values
(e.g. by addition or multiplication).
pow(
p_values,
alpha_locals = NULL,
alpha_global = 0.05,
adjust = TRUE,
adj_init = NULL,
staircase_steps = NULL,
alpha_precision = 5,
fut_locals = NULL,
multi_logic_a = "all",
multi_logic_fut = "all",
multi_logic_global = "any",
group_by = NULL,
alpha_loc_nonstop = NULL,
round_to = 5,
iter_limit = 100,
seed = 8,
prog_bar = FALSE,
hush = FALSE
)
p_values |
A |
alpha_locals |
A number, a numeric vector, or a named |
alpha_global |
Global alpha (expected type 1 error rate in total);
|
adjust |
The function via which the initial vector local alphas is
modified with each step of the staircase procedure. Three arguments are
passed to it: |
adj_init |
The initial adjustment value that is used as the " |
staircase_steps |
Numeric vector that specifies the (normally decreasing)
sequence of step sizes for the staircase that narrows down on the specified
global error error by decreasing or increasing the adjustment value
(initially: |
alpha_precision |
During the staircase procedure, at any point when the
simulated global type 1 error rate first matches the given
|
fut_locals |
Specifies local futility bounds that may stop the experiment
at the given interim looks if the corresponding p value is above the given
futility bound value. When |
multi_logic_a |
When multiple p values are evaluated for local alpha
stopping rules, |
multi_logic_fut |
Same as |
multi_logic_global |
Similar as |
group_by |
When given as a character element or vector, specifies the
factors by which to group the analysis: the |
alpha_loc_nonstop |
Optional "non-stopper" alphas via which to evaluate p
values per look, but without stopping the data collection regardless of
statistical significance. Must be a list with names indicating p value
column name pairs, similarly as for the |
round_to |
Number of fractional digits (default: |
iter_limit |
In some specific cases of unideal/wrong input, the staircase
may get stuck at a given step's loop process. The |
seed |
Number for |
prog_bar |
Logical, |
hush |
Logical. If |
The returns a list
(with class "possa_pow_list"
)
that includes all details of the calculated power, T1ER, and sample
information. This list can be printed legibly (via POSSA's
print()
method).
For the replicability, in case the adjust
function uses any
randomization, set.seed
is executed in the beginning of this
function, each time it is called; see the seed
parameter.
This function uses, internally, the data.table
R package.
sim
# below is a (very) minimal example
# for more, see the vignettes via https://github.com/gasparl/possa#usage
# create sampling function
customSample = function(sampleSize) {
list(
sample1 = rnorm(sampleSize, mean = 0, sd = 10),
sample2_h0 = rnorm(sampleSize, mean = 0, sd = 10),
sample2_h1 = rnorm(sampleSize, mean = 5, sd = 10)
)
}
# create testing function
customTest = function(sample1, sample2_h0, sample2_h1) {
c(
p_h0 = t.test(sample1, sample2_h0, 'less', var.equal = TRUE)$p.value,
p_h1 = t.test(sample1, sample2_h1, 'less', var.equal = TRUE)$p.value
)
}
# run simulation
dfPvals = sim(
fun_obs = customSample,
n_obs = 80,
fun_test = customTest,
n_iter = 1000
)
# get power info
pow(dfPvals)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.