Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


DiscreteGapStatistic (version 1.1.2)

SimData: Simulate Data

Description

A function to simulate data based on a multinomial vector parameter vector or a list of parameter vectors.

Usage

SimData(N, nQ, pi)

Value

N x nQ matrix with simulated categories distributed according to vector pi

Arguments

N

Integer. Number of observations.

nQ

Integer. Number of questions.

pi

Numeric vector. Vector of probabilities adding up to 1; it is recommended that names of elements are character strings. Alternatively, pi can be list of vectors as previously described with length equal to `nQ`. Notice that the list elements need not have same vector names. The order of pi vectors in the list will be reflected in the resulting simulated matrix. This alternative ideally assumes that questions are independently distributed.

Examples

Run this code
Pix <- setNames(c(0.1, 0.2, 0.3, 0.4, 0), paste0('a', 1:5))
X <- SimData(N=10, nQ=5, Pix)
head(X)

Piy <- setNames(c(0.3, 0.2, 0.4, 0, 0.1), paste0('a', 1:5))
Y <- SimData(N=10, nQ=3, Piy)
head(Y)

PiZ <- list(x1 = Pix, x2 = Pix, y1 = Piy, y2 = Piy)
Z <- SimData(N=10, nQ=length(PiZ), PiZ)

Run the code above in your browser using DataLab