sim_trial: Simulate a single cross-sectional trial

View source: R/simulate.R

sim_trialR Documentation

Simulate a single cross-sectional trial

Description

Simulate a single cross-sectional trial

Usage

sim_trial(
  n_subjects = 40,
  sigma_u = 0.5,
  group_allocation = list(control = 0.5, treatment = 0.5),
  random_allocation = TRUE,
  n_goals = NULL,
  n_goals_range = c(3, 6),
  n_goals_prob = NULL,
  sigma_e = 0.5,
  delta = 0.3,
  mean_control_response = -0.3,
  weight_type = "unweighted",
  n_levels = 5,
  score_dist = "norm",
  centre = 0
)

Arguments

n_subjects

Number of subjects.

sigma_u

Standard deviation of the subject-level random effect.

group_allocation

A named list of groups and their probability of assignment. By default, will give equal probability to "control" and "treatment" groups. If NULL, will returns subjects without groups.

random_allocation

Logical. If TRUE (default), randomly assigns to groups based on probabilities in group_allocation. If FALSE, assigns with equal probability. Note that this option will return an error if the subjects cannot be neatly divided. For example, n_subjects = 21 with two groups of probabilities 0.5 and 0.5, will return an error if random_allocation = FALSE because 21 cannot be equally divided in two.

n_goals

The exact number of goals for each subject.

n_goals_range

A vector defining the minimum and maximum number of goals per subjects. Randomly samples the range of goals with uniform probability.

n_goals_prob

A named list with element n_goals defining the possible numbers of goals, and element prob defining the probabilities of getting each number. For example: n_goals_prob = list(n_goals = 1:3, probs = c(0.3, 0.3, 0.4).

sigma_e

Standard deviation of the goal-level random effect, i.e. the random error of each latent goal score.

delta

The size of the treatment effect.

mean_control_response

The mean response in the control group.

weight_type

The type of weights to apply. See 'Details'.

n_levels

The number of levels to use. Defaults to the traditional 5 levels.

score_dist

The distribution by which scores should be approximated. The default "norm" will return thresholds which approximate a standard normal distribution. Choosing "unif" will return thresholds which approximate a uniform distribution.

centre

The centre of the normal distribution from which the thresholds are taken.

Value

A data frame with a row per trial (numbered 1 to n_sim) with list column data containing the simulated data.


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