camr_shuffle_groups: Shuffle Grouping Variable Levels

View source: R/R04-Data_wrangling.R

camr_shuffle_groupsR Documentation

Shuffle Grouping Variable Levels

Description

Function that shuffles the levels of a grouping variable (e.g., treatment or intervention assignments) over participants (and optionally a within-participant variable like study visit or time point). This is useful, for example, to create a data set for an analyst-blind design.

Usage

camr_shuffle_groups(
  dtf,
  id,
  group,
  within = NULL,
  include = NULL,
  group_levels = NULL,
  prob_levels = NULL,
  save_unshuffled = TRUE,
  rng_seed = NULL
)

Arguments

dtf

A data frame.

id

A character string, the column with participant identifiers.

group

A character string, the column for the grouping variable.

within

An optional character string, the column with the levels for a within-participant variable (e.g., time points or visits).

include

An optional logical vector matching in length to the number of rows in dtf, indicating the subset of cases to shuffle. If NULL all rows are used.

group_levels

An optional character vector, the subset of levels of group to consider.

save_unshuffled

Logical; if TRUE adds a new column with the original unshuffled group levels.

rng_seed

An integer, the RNG seed to use to ensure reproducibility.

original_freq

Logical; if TRUE shuffles data in a way that preserves the original frequencies for group levels - otherwise, assigns new levels in equal frequencies.

Value

A data frame with shuffled group levels for the group variable.

Author(s)

Kevin Potter


rettopnivek/camrprojects documentation built on Dec. 20, 2024, 10:17 p.m.