sim_goals: Simulate goals

View source: R/simulate.R

sim_goalsR Documentation

Simulate goals

Description

For each subject, simulate a specified number of goals. There are three options for defining the number of goals: n_goals sets the same number for each subject, n_goals_range sets the minimum and maximum number, and n_goals_prob sets specific probabilities for each number.

Usage

sim_goals(
  subjects,
  n_goals = NULL,
  n_goals_range = NULL,
  n_goals_prob = NULL,
  sigma_e = 0.5
)

Arguments

subjects

A data frame with a row per subject.

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.

Value

The same subjects data frame with a n_goals column, and goals list column. The goals list column contains tibbles with two variables: a subject-specific goal index goal_num, and a normally distributed random effect goal_re.

Examples

sim_subjects() %>%
  sim_goals(n_goals = 3, sigma_e = 0.8)

sim_subjects() %>%
  sim_goals(n_goals_range = c(2, 7))

sim_subjects() %>%
  sim_goals(n_goals_prob = list(n_goals = c(6, 3, 4),
                                prob = c(0.3, 0.5, 0.2)))


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