| Title: | Paired Randomization Functions |
|---|---|
| Description: | Provides tools for generating simulated study data, creating matched participant pairs using optimal nonbipartite matching, randomizing participants within pairs into study groups, and assessing post-randomization balance using descriptive summary statistics and standardized mean differences. The matching methodology is based on Lu et al. (2011) <doi:10.1198/tast.2011.08294>. |
| Authors: | Milan Bimali [aut, cre], Kamal Joshi [aut], Miaolei Bao [aut] |
| Maintainer: | Milan Bimali <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-10-08 22:20:55 UTC |
| Source: | https://github.com/cran/PairedRand |
The following function creates matched pair. With the matched pair, randomization is performed. SMD helps assess balance, but caution is required when interpreting results in small samples
create_matched_randomization( dat_in, group_label = c("SelfHelp", "Group"), seed = 177 )create_matched_randomization( dat_in, group_label = c("SelfHelp", "Group"), seed = 177 )
dat_in |
Input dataset |
group_label |
The label for the two randomization group |
seed |
Seed for reproducibility |
A list containing:
A data frame containing participants organized into matched pairs based on similarity across baseline variables. The variable Pair identifies each matched pair.
A data frame containing matched participants and their randomized study group assignments. This dataset is used for study implementation and assessment of balance between study groups.
An object of class distancematrix from the nbpMatching package.
The distance matrix quantifies similarity between participants and is
used by the optimal nonbipartite matching algorithm to identify matched
pairs. Smaller distances indicate greater similarity between participants.
dat_in <- data.frame( id = 1:4, age = c(25, 30, 35, 40), trait = c("A", "B", "A", "B") ) results <- create_matched_randomization(dat_in, group_label = c("Treated", "Control")) print(results$dat_in_matched_rand)dat_in <- data.frame( id = 1:4, age = c(25, 30, 35, 40), trait = c("A", "B", "A", "B") ) results <- create_matched_randomization(dat_in, group_label = c("Treated", "Control")) print(results$dat_in_matched_rand)
The following code generates a simulated dataset that will be used in running functions in the package
dat_sim(n_rows = 100, num_vars = 5, cat_vars = 3, cat_lev = 3, seed = 100)dat_sim(n_rows = 100, num_vars = 5, cat_vars = 3, cat_lev = 3, seed = 100)
n_rows |
Number of rows in the simulated dataset |
num_vars |
Number of numeric variables |
cat_vars |
Number of categorical variables |
cat_lev |
Number of levels for each categorical variable |
seed |
Seed for reproducibility |
A data frame containing simulated study data. The first column is a unique participant identifier (ID), followed by numeric variables (N_1, N_2, ...) and categorical variables (C_1, C_2, ...).
n_rows <- 100 num_vars <- 5 cat_vars <- 3 cat_lev <- 3 seed <- 100 dat_out <- dat_sim(n_rows, num_vars, cat_vars, cat_lev, seed)n_rows <- 100 num_vars <- 5 cat_vars <- 3 cat_lev <- 3 seed <- 100 dat_out <- dat_sim(n_rows, num_vars, cat_vars, cat_lev, seed)
The following code generates summary statistics to describe balance across two arms Note: To save the output from summ_stats as an Excel file, refer to the as_hux_xlsx() function from the gtsummary package
summ_stats(dat_in, lab_list, arm = "randomization_group")summ_stats(dat_in, lab_list, arm = "randomization_group")
dat_in |
Dataset generated after randomization within pairs |
lab_list |
Variable labels for the dataset (can be set to NULL if not needed) |
arm |
Variable indicating the randomization group |
A gtsummary object of class tbl_strata containing
descriptive statistics by study group, overall summary statistics,
standardized mean differences (SMDs), and confidence intervals for
assessing balance between randomized groups.
dat_in <- data.frame( id = 1:4, age = c(25, 30, 35, 40), trait = c("A", "B", "A", "B") ) results <- create_matched_randomization(dat_in, group_label = c("Treated", "Control")) results_matched_rand <- results$dat_in_matched_rand dat_in <- results_matched_rand %>% dplyr::select(-c(Pair,ID)) results_matched__summary <- summ_stats(dat_in, lab_list = NULL, arm = "Group")dat_in <- data.frame( id = 1:4, age = c(25, 30, 35, 40), trait = c("A", "B", "A", "B") ) results <- create_matched_randomization(dat_in, group_label = c("Treated", "Control")) results_matched_rand <- results$dat_in_matched_rand dat_in <- results_matched_rand %>% dplyr::select(-c(Pair,ID)) results_matched__summary <- summ_stats(dat_in, lab_list = NULL, arm = "Group")