stratEst.simulate: Simulation function for strategy estimation.

View source: R/stratEst_simulate.R

stratEst.simulateR Documentation

Simulation function for strategy estimation.

Description

The simulation function of the package.

Usage

stratEst.simulate(
  data = NULL,
  strategies,
  shares = NULL,
  coefficients = NULL,
  covariate.mat = NULL,
  num.ids = 100,
  num.games = 5,
  num.periods = NULL,
  fixed.assignment = TRUE,
  input.na = FALSE,
  sample.id = NULL
)

Arguments

data

a stratEst.data object. Alternatively, the arguments num.ids, num.games, and num.periods can be used if no data is available.

strategies

a list of strategies. Each element if the list must be an object of class stratEst.strategy.

shares

a numeric vector of strategy shares. The order of the elements corresponds to the order in strategies. NA values are not allowed. Use a list of numeric vectors if data has more than one sample and shares are sample specific.

coefficients

a matrix of regression coefficients. Column names correspond to the names of the strategies, row names to the names of the covariates.

covariate.mat

a matrix with the covariates in columns. The column names of the matrix indicate the names of the covariates. The matrix must have as many rows as there are individuals.

num.ids

an integer. The number of individuals. Default is 100.

num.games

an integer. The number of games. Default is 5.

num.periods

a vector of integers with as many elements num.games. The elements specify the number of periods in each game. Default (NULL) means 5 periods in each game.

fixed.assignment

a logical value. If FALSE individuals use potentially different strategies in each each game. If TRUE, individuals use the same strategy in each game. Default is FALSE.

input.na

a logical value. If FALSE an input value is randomly selected for the first period. Default is FALSE.

sample.id

a character string indicating the name of the variable which identifies the samples in data. Individual observations must be nested in samples. Default is NULL.

Value

A stratEst.data object. A data frame in the long format with the following variables:

id

the variable that identifies observations of the same individual.

game

the variable that identifies observations of the same game.

period

the period of the game.

choice

the discrete choices.

input

the inputs.

sample

the sample of the individual.

strategy

the strategy of the individual.

Examples

## Simulate data of two strategies for choices "left" and "right".
lr <- c("left","right")
pi <- runif(1)
pr <- c(1,0,0,1)
tr <- c(1,2,1,2)
mixed <- stratEst.strategy(choices = lr, inputs = lr, prob.choices = c(pi, 1 - pi))
pure <- stratEst.strategy(choices = lr, inputs = lr, prob.choices = pr, tr.inputs = tr)
gamma <- runif(1)/4
pure$tremble <- gamma
beta <- rnorm(1)
p <- 1/sum(1 + exp(beta))
sim.shares <- c(p, 1-p)
sim.strategies <- list("mixed" = mixed, "pure" = pure)
sim.data <- stratEst.simulate(strategies = sim.strategies, shares = sim.shares)


stratEst documentation built on Dec. 1, 2022, 1:13 a.m.