Performs a randomization test on data from single-case experiments. This function allows for the assessment of treatment effects by comparing the observed outcome difference to a distribution of differences obtained through permutation. It supports various constraints on permutation sequences, such as fixed or observed maximum and minimum consecutive sequences of a particular condition. The function also provides graphical summaries of the raw data and the distribution of mean differences.
randomization_test(
.df,
.out,
.cond,
.time,
num_permutations = NULL,
consec = c("observed", "fixed"),
max_consec = NULL,
min_consec = NULL,
cond_levels = NULL,
cond_labels = NULL,
conf.level = 0.95,
.bins = 30
)
A list containing the original difference in means, the p-value of the test, the distribution of test statistics under the null hypothesis, confidence intervals, and plots of the distribution of mean differences and the raw data.
A data frame containing the variables of interest.
The name of the outcome variable in .df
.
The name of the condition variable in .df
. This variable should
have two levels.
The name of the time variable in .df
.
The number of permutations to perform. If NULL
, all
possible permutations are considered.
Specifies the constraint on consecutive sequences for permutation.
Can be "observed"
for the observed sequence length or "fixed"
for
a specified sequence length. Defaults to "observed"
.
The maximum number of consecutive observations of the same
condition to allow in permutations. If NULL
, no maximum is enforced.
To implement max_consec
, consec
must be set to "fixed"
.
The minimum number of consecutive observations of the same
condition to allow in permutations. If NULL
, no minimum is enforced.
To implement min_consec
, consec
must be set to "fixed"
.
Explicitly sets the levels of the condition variable. If
NULL
, the levels are derived from the data.
Labels for the condition levels. If NULL
, levels are used
as labels.
The confidence level for the confidence interval calculation. Defaults to 0.95.
The number of bins to use for the histogram of the test statistic distribution. Defaults to 30.
Onghena, P. (2020). One by One: The design and analysis of replicated randomized single-case experiments.In R. van de Schoot & M. Mioecvic (Eds.), Small Sample Size Solutions: A Guide for Applied Researchers and Practitioners (1st ed., pp. 15). Routledge. doi:10.4324/9780429273872-8
result <- randomization_test(sleeping_pills, .out = "sever_compl",
.cond = "treatment", .time = "day",
num_permutations = 100,
cond_levels = c("C", "E"))
result$conf_int
Run the code above in your browser using DataLab