shuffle_two_groups: Randomization for Two-Group Comparisons

View source: R/shuffle_two_groups.R

shuffle_two_groupsR Documentation

Randomization for Two-Group Comparisons

Description

Shuffles data for use in two-group simulations.

Usage

shuffle_two_groups(d, groups)

Arguments

d

A data frame that contains the

groups

The name of the variable (in quotes!) that identifies which group each observation belongs to

Value

The original data frame with the group labels randomly shuffled among observations

Examples

# Make a data frame to shuffle
og_data <- data.frame(
  "group" = c(rep("Group A", 600), rep("Group B", 200)),
  "result" = c(rep("Failure", 402), rep("Success", 198),
               rep("Failure", 120), rep("Success", 80)),
  stringsAsFactors = TRUE)

# Tabulate successes & failures in each group in original data
table(og_data$result, og_data$group)

# Shuffle data with shuffle_two_groups
shuffle_data <- shuffle_two_groups(og_data, "group")

# Tabulate successes & failures in each group in shuffled data
table(shuffle_data$result, shuffle_data$group)


STATS250SBI/stats250sbi documentation built on March 18, 2022, 1:14 p.m.