ddModel
provides fast and flexible computational tools
for the Decision Diffusion Model (DDM) - a widely used
cognitive model for analysing choice and response time
(RT) in speeded decision-making tasks.
This package supports: - End-to-end DDM support:
density, distribution, and random sampling functions - Flexible
parameterisation: - Fix parameters globally - Constrain by
experimental conditions - Vary subject-by-subject (hierarchical
modelling ready) - Efficient likelihood evaluation:
fully vectorised for large-scale datasets - Seamless
integration: designed to work smoothly with the
ggdmc
Figure: Illustration of the DDM. Evidence accumulates over time with
drift rate v until it reaches one of the decision
boundaries (a or 0). The starting
point z and non-decision time tβ are
also shown; variability parameters, sv, sz, and stβ were set to
0.
a
(boundary
separation), v
(drift rate), tβ
(non-decision
time), z
(starting point), plus optional variability
parameters sv
, sz
, stβ
ggdmcModel
,
ggdmcPrior
, ggdmcHeaders
)# Install from CRAN
install.packages("ddModel")
# Or development version
# install.packages("devtools")
::install_github("yxlin/ddModel")
devtools
library(ddModel)
library(ggdmcModel)
library(ggdmcPrior)
# Load packages
library(ggdmcModel)
library(ggdmcPrior)
library(ddModel)
# Set up a stimulus drift rate model
<- BuildModel(
model 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, precision = 3),
accumulators = c("r1", "r2"),
type = "fastdm"
)
# Set up a population-level prior distribution
<- c(a = 1, sv = 0.1, sz = 0.25, t0 = 0.15, v = 2.5, z = 0.38)
pop_mean <- c(a = 0.05, sv = 0.01, sz = 0.01, t0 = 0.02, v = 0.5, z = 0.01)
pop_scale <- BuildPrior(
pop_dist p0 = pop_mean,
p1 = pop_scale,
lower = c(0, 0, 0, 0, -10, 0),
upper = rep(NA, length(pop_mean)),
dists = rep("tnorm", length(pop_mean)),
log_p = rep(FALSE, length(pop_mean))
)
# Visualise the prior
plot_prior(pop_dist)
# Subject-level and population-level model setup
<- setDDM(model)
sub_model <- setDDM(model, population_distribution = pop_dist)
pop_model
# Simulate subject-level data
<- c(a = 1, sv = 0.1, sz = 0.25, t0 = 0.15, v = 2.5, z = 0.38)
p_vector <- simulate(sub_model, nsim = 256, parameter_vector = p_vector, n_subject = 1)
dat
# Simulate hierarchical data (32 subjects)
<- simulate(pop_model, nsim = 128, n_subject = 32) hdat
pfastdm
<- seq(0.1, 1.2, 0.01)
RT <- c(
params a = 1, v = 1.5, zr = 0.5, d = 0,
sz = 0.05, sv = 0.01, t0 = 0.15, st0 = 0.001,
s = 1, precision = 3
)# Ensure parameter names are ordered
<- params[sort(names(params))]
params
# Compute lower-bound response density
<- pfastdm(RT, params, is_lower = TRUE, debug = TRUE) result
Rcpp
(β₯ 1.0.7)RcppArmadillo
(β₯ 0.10.7.5.0)ggdmcModel
, ggdmcPrior
,
ggdmcHeaders
ddModel
Compare to HDDM
and
fastdm
?If youβve worked with other diffusion model toolkits, you might
wonder how ddModel
fits in. Hereβs a quick comparison:
HDDM
: Python-based Bayesian modelling using PyMC;
powerful but requires a Python workflow.fastdm
: Stand-alone C++ executable; very fast, but
limited R integration and less flexible parameter mapping.ddModel
: Native R + C++ (via RcppArmadillo), integrates
seamlessly with R packages like ggdmc
for hierarchical
inference and DE-MCMC sampling.ddModel
supports global, condition-wise, and
subject-wise parameter specifications.fastdm
speed but
remains fully open and modifiable within R.HDDM
βs full
Bayesian machinery.A comparison table at a glance:
Tool | Language | Speed | Bayesian Support | Integration Style |
---|---|---|---|---|
HDDM |
Python | Medium | Yes (PyMC3/PyMC) | Python workflow only |
fastdm |
C++ binary | High | No | CLI / external program |
ddModel | R + C++ | High | Via ggdmc (DE-MCMC) |
Native R, modular & open |
Why choose
ddModel
?If you work primarily in R or use the
ggdmc
ecosystem,ddModel
provides fast, flexible, and fully integrated DDM tools out of the box.
Contributions welcome! Please open an issue or pull request on GitHub.