Learn R Programming

DstarM (version 0.1.0)

simData: Simulate data from a given densitiy function via multinomial sampling

Description

Simulate data from a given densitiy function via multinomial sampling

Usage

simData(n, pars, tt, pdfND, fun.density = Voss.density, args.density = list(prec = 3), npars = 5, return.pdf = FALSE)

Arguments

n
Number of observations to be sampled
pars
Parameter values for the density function to be evaluated with. length(pars) must be a multiple of npars.
tt
time grid on which the density function will be evaluated. Responses not in this time grid cannot appear.
pdfND
either a vector of length tt specifying the nondecision density for all condition-response pairs, or a matrix where columns corresponds to the nondecision densities of condition-response pairs.
fun.density
Density function to use.
args.density
Additional arguments to be passed to fun.density, aside from tt, pars, and a boundary argument ('upper' or 'lower')
npars
Number of parameters fun.density must be evaluated with. If length(pars) > npars each npars values in pars will be seen as the parameter values of a condition.
return.pdf
Logical, if TRUE genData returns a list containing the probability density function used and the data, if FALSE genData returns a dataframe with simulated data.

Value

A sorted dataframe where rows represent trials. It contains: a column named rt containing reaction times in seconds, a column named response containing either reponse option lower or upper, and a column named condition indicating which condition a trials belongs to. If return.pdf is TRUE it returns a list where the first element is the sorted dataframe, the second through the fifth elements are lists that contain densities used for simulating data.

Details

Simulate data via multinomial sampling. The response options to sample from should be provided in tt. The number of conditions is defined as length(pars) / npars.

Examples

Run this code
tt = seq(0, 5, .01)
pdfND = dbeta(tt, 10, 30)
n = 100
pars = c(1, 2, .5, .5, .5)
dat = simData(n, pars, tt, pdfND)
head(dat)

Run the code above in your browser using DataLab