| Title: | Compare Ordinal Endpoints Using Simulations |
|---|---|
| Description: | Simultaneously evaluate multiple ordinal outcome measures. Applied data analysts in particular are faced with uncertainty in choosing appropriate statistical tests for ordinal data. The included 'shiny' application allows users to simulate outcomes given different ordinal data distributions. |
| Authors: | Pat Callahan [aut, cre, cph] (ORCID: <https://orcid.org/0000-0003-1769-7580>) |
| Maintainer: | Pat Callahan <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.4 |
| Built: | 2026-05-27 06:48:54 UTC |
| Source: | https://github.com/NeuroShepherd/ordinalsimr |
(Brief description of the function here.)
assign_groups( sample_size, sample_prob, prob0, prob1, seed, .rng_kind = NULL, .rng_normal_kind = NULL, .rng_sample_kind = NULL )assign_groups( sample_size, sample_prob, prob0, prob1, seed, .rng_kind = NULL, .rng_normal_kind = NULL, .rng_sample_kind = NULL )
sample_size |
total number of people under observation. |
sample_prob |
a vector of probability weights for obtaining the elements of the vector being sampled. |
prob0 |
vector probability of each possible outcome for the null group |
prob1 |
vector probability of each possible outcome for the intervention group |
seed |
integer specifying the seed number |
.rng_kind |
seeding info passed to withr::with_seed |
.rng_normal_kind |
seeding info passed to withr::with_seed |
.rng_sample_kind |
seeding info passed to withr::with_seed |
list of group assignments
This function calculates the power, Type II error, and Type I error of tests given p-values. Power, Type II error, and confidence intervals calculated using 'stats::binom.test()' which implements the Newcombe method.
calculate_power_t2error( df, alpha = 0.05, power_confidence_int = 95, n = NA_real_ )calculate_power_t2error( df, alpha = 0.05, power_confidence_int = 95, n = NA_real_ )
df |
Data frame where each column is a vector of p-values from a statistical test |
alpha |
Numeric significance level; defaults to 0.05 |
power_confidence_int |
confidence interval |
n |
Numeric value of sample size; repeated for convenience |
A data frame with columns for Type 1 error, Type 2 error, and power as well as rows for each test
Calculate Type 1 error for a distribution, and the confidence interval around this estimate. Type I error and confidence intervals calculated using 'stats::binom.test()' which implements the Newcombe method.
calculate_t1_error( df, alpha = 0.05, t1_error_confidence_int = 95, n = NA_real_ )calculate_t1_error( df, alpha = 0.05, t1_error_confidence_int = 95, n = NA_real_ )
df |
data frame |
alpha |
significance level |
t1_error_confidence_int |
confidence interval |
n |
optional numeric input of |
data frame
Returns all of the ordinalsimr options to the console.
get_ordinalsimr_options()get_ordinalsimr_options()
list of ordinalsimr options
get_ordinalsimr_options()get_ordinalsimr_options()
A metafunction that runs the statistical tests listed below, and returns the p-values as a named vector.
ordinal_tests(x, y, included = "all", ...)ordinal_tests(x, y, included = "all", ...)
x |
Group one |
y |
Group two |
included |
a character vector of the tests to be included. Default is "all" |
... |
Placeholder for additional arguments to functions |
stats::wilcox.test()
stats::fisher.test(simulate.p.value = TRUE)
stats::chisq.test(correct = FALSE)
stats::chisq.test(correct = TRUE)
rms::lrm()
coin::independence_test(ytrafo = coin::rank_trafo)
A named matrix of probabilities for each test
The function is designed to run all 6 tests by default. If you want to run only a subset of the tests, you can specify them in the 'included' argument. The following values are possible:
"Wilcoxon"
"Fisher"
"Chi Squared (No Correction)"
"Chi Squared (Correction)"
"Prop. Odds"
"Coin Indep. Test"
This option is primarily for use in the Shiny application.
This function parses text from ratios which are written in the format of 1-2 digit numbers separated by a colon and trailing with another 1-2 digit number. The text is processed into a numeric vector of length 2 containing the two numbers.
parse_ratio_text(text)parse_ratio_text(text)
text |
A string of in the form of e.g. 5:95 or 70:30 |
Numeric vector of length 2
parse_ratio_text("70:30")parse_ratio_text("70:30")
This function takes a wide table of p-values (i.e. one column for each statistical test), converts it to long format, and creates a density plot of the p-values by each test.
plot_distribution_results(df, alpha = 0.05, outlier_removal = 0.1)plot_distribution_results(df, alpha = 0.05, outlier_removal = 0.1)
df |
data frame where each column is a set of p-values for a different statistical test |
alpha |
numeric. significance level |
outlier_removal |
numeric. set x-axis scale maximum by proportion |
ggplot object
Plot Test Power
plot_power(df, power_threshold = 0.8, ci_band = TRUE)plot_power(df, power_threshold = 0.8, ci_band = TRUE)
df |
a dataframe with p-values and a sample_size column |
power_threshold |
numeric. desired power threshold |
ci_band |
logical. whether to include a confidence interval band around the power estimate |
ggplot object
Run the Shiny Application
run_app( onStart = NULL, options = list(), enableBookmarking = NULL, uiPattern = "/", ... )run_app( onStart = NULL, options = list(), enableBookmarking = NULL, uiPattern = "/", ... )
onStart |
A function that will be called before the app is actually run.
This is only needed for |
options |
Named options that should be passed to the |
enableBookmarking |
Can be one of |
uiPattern |
A regular expression that will be applied to each |
... |
arguments to pass to golem_opts. See '?golem::get_golem_options' for more details. |
NULL, the function is called for its side effects
Run Simulations
run_simulations( sample_size, sample_prob, prob0, prob1, niter, included = "all", .rng_kind = NULL, .rng_normal_kind = NULL, .rng_sample_kind = NULL )run_simulations( sample_size, sample_prob, prob0, prob1, niter, included = "all", .rng_kind = NULL, .rng_normal_kind = NULL, .rng_sample_kind = NULL )
sample_size |
Total number of trial participants |
sample_prob |
a vector of probability weights for obtaining the elements of the vector being sampled. |
prob0 |
Vector of probabilities for control group |
prob1 |
Vector of probabilities for intervention group |
niter |
Number of simulation iterations to complete#' |
included |
a character vector of the tests to be included. Default is "all" |
.rng_kind |
seeding info passed to withr::with_seed |
.rng_normal_kind |
seeding info passed to withr::with_seed |
.rng_sample_kind |
seeding info passed to withr::with_seed |
a list of lists; sub-list elements include 'p_values' which is a matrix of p values for tests at each iteration, and 'initial_groups' which is the group assignment information for each iteration
run_simulations( sample_size = c(40, 50, 60), sample_prob = c(0.5, 0.5), prob0 = c(0.1, 0.2, 0.3, 0.4), prob1 = c(0.6, 0.2, 0.1, 0.1), niter = 40 )run_simulations( sample_size = c(40, 50, 60), sample_prob = c(0.5, 0.5), prob0 = c(0.1, 0.2, 0.3, 0.4), prob1 = c(0.6, 0.2, 0.1, 0.1), niter = 40 )
Set ordinalsimr Shiny App Default Values
set_ordinalsimr_options( default_iterations, default_size_min, default_size_max, default_ratio, default_distributions, default_entry_rows )set_ordinalsimr_options( default_iterations, default_size_min, default_size_max, default_ratio, default_distributions, default_entry_rows )
default_iterations |
number of iterations to run |
default_size_min |
number for the small end of the sample size range |
default_size_max |
number for the large end of the sample size range |
default_ratio |
text ratio of the number of levels in the two groups, format of "50:50" |
default_distributions |
data frame of the distributions of the levels in the two groups |
default_entry_rows |
number of rows to initialize the (empty) data frame with |
invisible
# Set the default values for the ordinalsimr Shiny app set_ordinalsimr_options( default_iterations = 1000, default_size_min = 10, default_size_max = 100, default_ratio = "50:50", default_distributions = data.frame(c(0.4, 0.3, 0.3), c(0.8, 0.1, 0.1)) ) # Values can be either overwritten or unset by setting them to NULL. The Shiny # app still has backup values if these options are not set. Not all arguments # need to be provided set_ordinalsimr_options( default_iterations = 500, # Ex: update argument default_size_min = NULL, # Ex: unset argument default_size_max = NULL, # Ex: unset argument # default_ratio = NULL, # Ex: arg not provided (by commenting out) default_distributions = NULL )# Set the default values for the ordinalsimr Shiny app set_ordinalsimr_options( default_iterations = 1000, default_size_min = 10, default_size_max = 100, default_ratio = "50:50", default_distributions = data.frame(c(0.4, 0.3, 0.3), c(0.8, 0.1, 0.1)) ) # Values can be either overwritten or unset by setting them to NULL. The Shiny # app still has backup values if these options are not set. Not all arguments # need to be provided set_ordinalsimr_options( default_iterations = 500, # Ex: update argument default_size_min = NULL, # Ex: unset argument default_size_max = NULL, # Ex: unset argument # default_ratio = NULL, # Ex: arg not provided (by commenting out) default_distributions = NULL )
Simulated p-values and metadata for a two group comparison. Useful for Type I error calculations.
simulation_data_one_groupsimulation_data_one_group
## 'simulation_data_one_group' A list
A data frame of p-values from each run of each test
A nested list with information for each simulation run
Simulated p-values and metadata for a two group comparison. Useful for Type II error and power calculations.
simulation_data_two_groupssimulation_data_two_groups
## 'simulation_data_two_groups' A list
A data frame of p-values from each run of each test
A nested list with information for each simulation run