if (requireNamespace("ggdmcModel", quietly = TRUE)) {
BuildModel <- getFromNamespace("BuildModel", "ggdmcModel")
model <- ggdmcModel::BuildModel(
p_map = list(
a = "1", v = "1", z = "1", d = "1", sz = "1", sv = "1",
t0 = "1", st0 = "1", s = "1", precision = "1"
),
match_map = list(M = list(s1 = "r1", s2 = "r2")),
factors = list(S = c("s1", "s2")),
constants = c(d = 0, s = 1, st0 = 0, sv = 0, precision = 3),
accumulators = c("r1", "r2"),
type = "fastdm"
)
# Simulate one subject ------------------
sub_model <- setDDM(model)
p_vector <- c(a = 1, sz = 0.25, t0 = 0.15, v = 2.5, z = .38)
dat <- simulate(sub_model,
nsim = 256, parameter_vector = p_vector,
n_subject = 1
)
# Simulate multiple subjects ------------------
# 1. First build a population distribution to sample many p_vector's
pop_mean <- c(a = 1, sz = 0.25, t0 = 0.15, v = 2.5, z = 0.38)
pop_scale <- c(a = 0.05, sz = 0.01, t0 = 0.02, v = .5, z = 0.01)
pop_dist <- ggdmcPrior::BuildPrior(
p0 = pop_mean,
p1 = pop_scale,
lower = c(0, 0, 0, -10, 0),
upper = rep(NA, model@npar),
dists = rep("tnorm", model@npar),
log_p = rep(FALSE, model@npar)
)
# 2. Enter the population distribution to a DDM model
pop_model <- setDDM(model, population_distribution = pop_dist)
# 3. simulate method will use the distribution to sample new p_vector's
# Note: You must enter sensible pop_mean, pop_scale and distribution.
hdat <- simulate(pop_model, nsim = 128, n_subject = 32)
}
Run the code above in your browser using DataLab