sim_treatment_effect: Simulate a treatment effect

View source: R/simulate.R

sim_treatment_effectR Documentation

Simulate a treatment effect

Description

Currently only simulates a uniform distribution of treatment effects, regardless of group allocation.

Usage

sim_treatment_effect(goals, delta = 0.3)

Arguments

goals

A data frame with a row for each goal.

delta

The size of the treatment effect.

Value

The same goals data frame with the added treatment_fe column.

Examples

library(dplyr)
library(tidyr)
library(purrr)

# Generate some subjects and goals
d <- sim_subjects(n_subjects = 40) %>%
  sim_goals(n_goals_range = c(1, 3))

# Apply treatment effects in one of two ways
# Using purrr::map()
d %>%
  mutate(
    goals = map(
      goals,
      ~sim_treatment_effect(., delta = 0.4)
    )
  )

# Or using tidyr::unnest() on the goals column
d %>%
  unnest(goals) %>%
  group_by(subject_id) %>%
  sim_treatment_effect(delta = 0.4)


taylordunn/gasr documentation built on April 5, 2022, 1:37 a.m.