Package {PairedRand}


Title: Paired Randomization Functions
Version: 0.1.0
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>.
License: MIT + file LICENSE
Encoding: UTF-8
Imports: dplyr, gtsummary, magrittr, nbpMatching, tidyr, tidyselect
Suggests: testthat (≥ 3.0.0)
Config/testthat/edition: 3
Config/roxygen2/version: 8.1.0
RoxygenNote: 7.3.3
NeedsCompilation: no
Packaged: 2026-09-29 21:33:36 UTC; BimaliMilan
Author: Milan Bimali [aut, cre], Kamal Joshi [aut], Miaolei Bao [aut]
Maintainer: Milan Bimali <mbimali@uams.edu>
Repository: CRAN
Date/Publication: 2026-10-08 18:10:02 UTC

Pipe operator

Description

See magrittr::%>% for details.

Usage

lhs %>% rhs

Value

No value is returned.


Create Matched Randomization

Description

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

Usage

create_matched_randomization(
  dat_in,
  group_label = c("SelfHelp", "Group"),
  seed = 177
)

Arguments

dat_in

Input dataset

group_label

The label for the two randomization group

seed

Seed for reproducibility

Value

A list containing:

dat_in_matched

A data frame containing participants organized into matched pairs based on similarity across baseline variables. The variable Pair identifies each matched pair.

dat_in_matched_rand

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.

dist_matrix

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.

Examples

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)

Data Simulation

Description

The following code generates a simulated dataset that will be used in running functions in the package

Usage

dat_sim(n_rows = 100, num_vars = 5, cat_vars = 3, cat_lev = 3, seed = 100)

Arguments

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

Value

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, ...).

Examples

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)

Summary Statistics

Description

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

Usage

summ_stats(dat_in, lab_list, arm = "randomization_group")

Arguments

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

Value

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.

Examples

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")

mirror server hosted at Truenetwork, Russian Federation.