ggdmc
ggdmc provides tools to conduct Bayesian inference on a range of choice response time models.
Science Score: 39.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 10 DOI reference(s) in README -
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (14.7%) to scientific vocabulary
Repository
ggdmc provides tools to conduct Bayesian inference on a range of choice response time models.
Basic Info
- Host: GitHub
- Owner: yxlin
- Language: R
- Default Branch: main
- Homepage: https://yxlin.github.io
- Size: 7.02 MB
Statistics
- Stars: 18
- Watchers: 2
- Forks: 3
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
📦 ggdmc
ggdmc (v0.2.8.9) is an R package for Bayesian inference on cognitive choice response time models, including:
- Linear Ballistic Accumulator (LBA)
- Diffusion Decision Model (DDM)
It supports hierarchical Bayesian modelling, efficient MCMC sampling, and flexible model definitions.
🚀 Getting Started
Installation
From CRAN:
r
install.packages("ggdmc")
From GitHub (development version):
r
remotes::install_github("yxlin/ggdmc")
🔢 Overview
ggdmc helps researchers fit hierarchical Bayesian models of decision-making.
Key features include:
- Flexible model specification with condition-dependent parameters
- Efficient MCMC sampling with population-level migration
- Support for Truncated normal priors and bounded uniform priors
- Built-in tools for:
- Posterior summarisation
- Convergence diagnostics
- Model comparison
Currently supported models:
- LBA (Linear Ballistic Accumulator)
- DDM (Diffusion Decision Model)
- Regular statistical models (via hyper-only route)
- Extendable to user-defined models (e.g., pLBA, DDM with varying drift rates)
⚡ Quick Start — Fit a Simple DDM
Below is a step-by-step example of fitting a basic single-subject DDM. We’ll simulate some data, fit the model, and plot the posterior distributions.
```r
1. Load package
library(ggdmc)
2. Define a simple DDM model
model <- ggdmcModel::BuildModel( pmap = list(a="1", v="1", z="1", sz="1", t0="1"), # Free parameters matchmap = list(M = list(s1="r1", s2="r2")), # Mapping stimuli to responses factors = list(S = c("s1", "s2")), # Experimental factors constants = c(d=0, s=1, st0=0, sv=0, precision=3), # Fixed parameters accumulators = c("r1", "r2"), type = "fastdm" )
3. Simulate a small dataset for one subject
trueparams <- c(a=1.0, sz=0.25, t0=0.15, v=2.5, z=0.38) dat <- simulate(model, nsim=300, parametervector=trueparams, nsubject=1)
4. Prepare the data for fitting
dmi <- ggdmcModel::BuildDMI(dat, model)
5. Set flat (uninformative) priors
pri <- ggdmcPrior::setpriors( ggdmcPrior::BuildPrior( p0=rep(0, model@npar), p1=rep(10, model@npar), lower=rep(NA, model@npar), upper=rep(NA, model@npar), dist=rep("unif", model@npar), logp=rep(TRUE, model@npar) ) )
6. Fit the model (MCMC sampling)
fit <- ggdmc::StartSampling_subject(dmi[[1]], pri, thin=2, seed=123)
7. Rebuild and plot posterior distributions
post <- ggdmc::RebuildPosterior(fit) ggdmc::plot(post, pll=FALSE, den=TRUE) ```
💡 Tip: For faster tests, lower nsim and nmc in setThetaInput(). For real analyses, increase them for better convergence.
🔧 Dependencies
ggdmc requires:
- R (≥ 3.3.0)
- C++ integration:
Rcpp,RcppArmadillo - Data handling:
data.table,matrixStats - Plotting:
lattice - Core
ggdmccomponents:ggdmcHeaders,ggdmcModel,ggdmcPrior,ggdmcLikelihood - Model modules:
lbaModel,ddModel
Install all dependencies:
r
install.packages(c(
"Rcpp", "RcppArmadillo", "data.table",
"matrixStats", "lattice",
"ggdmcHeaders", "ggdmcModel",
"ggdmcPrior", "ggdmcLikelihood",
"lbaModel", "ddModel"
))
📄 Citation
If you use ggdmc, please cite:
Lin, Y.-S., & Strickland, L. (2020). Evidence accumulation models with R: A practical guide to hierarchical Bayesian methods. The Quantitative Methods for Psychology, 16(2), 133–153. doi.org/10.20982/tqmp.16.2.p133 | PDF
Heathcote, A., Lin, Y.-S., Reynolds, A., Strickland, L., Gretton, M., & Matzke, D. (2018). Dynamic models of choice. Behavior Research Methods. doi.org/10.3758/s13428-018-1067-y
👨💼 Contributors
The initial version of ggdmc was adapted from the Dynamic Model of Choice (Heathcote et al., 2018).
Bug reports and suggestions are welcome via: - 📧 Email - 🐛 GitHub Issues
📓 Acknowledgments
- DDM functions are based on Voss & Voss's
fast-dmand Gretton's contributions tortdists(Singmann et al.). These were rewritten in C++ to support MCMC-based inference. - Truncated normal sampling draws from:
- Jonathan Olmsted's RcppTN 0.1-8
- Christopher Jackson's
msm - Robert, C. P. (1995). Simulation of truncated normal variables. Statistics and Computing, 5(2), 121–125. https://doi.org/10.1007/BF00143942
Further Examples
⚡ Quick Start — Fit a Simple LBA
This example simulates a two-choice LBA for one participant, fits it, and plots the posterior. We keep drift variability fixed (sdv = 1) and let the core parameters vary: A, B, t0, meanv.true, mean_v.false.
```# 1. Load package library(ggdmc)
2. Define a simple LBA model (two accumulators)
model <- ggdmcModel::BuildModel( pmap = list(A="1", B="1", t0="1", meanv="M", st0="1"), # 'M' => match/mismatch (true/false) matchmap = list(M = list(s1="r1", s2="r2")), factors = list(S = c("s1","s2")), constants = c(st0=0, sdv=1), # fix drift SD accumulators = c("r1","r2"), type = "lba" )
3. Simulate data for one subject
trueparams <- c(A=0.5, B=1.2, t0=0.30, meanv.true=2.5, meanv.false=1.5) dat <- simulate(model, nsim=400, parametervector=trueparams, nsubject=1)
4. Prepare data & priors, then fit
dmi <- ggdmcModel::BuildDMI(dat, model) pri <- ggdmcPrior::setpriors( ggdmcPrior::BuildPrior( p0=rep(0, model@npar), p1=rep(10, model@npar), lower=rep(NA, model@npar), upper=rep(NA, model@npar), dist=rep("unif", model@npar), logp=rep(TRUE, model@npar) ) ) fit <- ggdmc::StartSampling_subject(dmi[[1]], pri, thin=2, seed=42)
5. Inspect posteriors
post <- ggdmc::RebuildPosterior(fit) ggdmc::plot(post, pll=FALSE, den=TRUE) ```
Tip: For a quick smoke test, reduce nsim (e.g., 200) or thin; for real analyses, increase them to improve convergence and stability.
Example 1: LBA Model with Population Recovery
This example shows how to:
- Define a condition-dependent LBA model
- Simulate data
- Recover parameters at both subject and population levels
See scripts under:
tests/testthat/Group1/data/– simulation datatests/testthat/Group1/0_5param_hyper.r– hyper-level only modeltests/testthat/Group1/1_6param_fit_subject.r– single participant fittingtests/testthat/Group1/2_v_model_multiple_level.r– hierarchical model with varying drift ratestests/testthat/Group1/3_B_model_中文.r– hierarchical model with varying thresholds (Chinese example)
Key functions:
simulate()– generate dataStartSampling()– find optimised parameterscompare()– analyse posterior recovery
Example 2: Minimal DDM Recovery
tests/testthat/Group6/data/– simulation datatests/testthat/Group6//– fitting the data to find optimised parameters
Owner
- Name: Yi-Shin Lin
- Login: yxlin
- Kind: user
- Repositories: 10
- Profile: https://github.com/yxlin
GitHub Events
Total
- Delete event: 2
- Push event: 9
- Create event: 1
Last Year
- Delete event: 2
- Push event: 9
- Create event: 1
Committers
Last synced: over 3 years ago
All Time
- Total Commits: 84
- Total Committers: 1
- Avg Commits per committer: 84.0
- Development Distribution Score (DDS): 0.0
Top Committers
| Name | Commits | |
|---|---|---|
| Yi-Shin Lin | y****1@g****m | 84 |
Issues and Pull Requests
Last synced: over 2 years ago
All Time
- Total issues: 6
- Total pull requests: 0
- Average time to close issues: 2 months
- Average time to close pull requests: N/A
- Total issue authors: 5
- Total pull request authors: 0
- Average comments per issue: 3.33
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 2
- Pull requests: 0
- Average time to close issues: 26 days
- Average time to close pull requests: N/A
- Issue authors: 2
- Pull request authors: 0
- Average comments per issue: 2.5
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- davidt0x (2)
- barracuda156 (1)
- ykunisato (1)
- ezrp (1)
- hcp4715 (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cran 298 last-month
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 9
- Total maintainers: 1
cran.r-project.org: ggdmc
Cognitive Models
- Homepage: https://github.com/yxlin/ggdmc
- Documentation: http://cran.r-project.org/web/packages/ggdmc/ggdmc.pdf
- License: GPL-2
-
Latest release: 0.2.6.2
published about 1 year ago
Rankings
Maintainers (1)
Dependencies
- R >= 3.3.0 depends
- Rcpp >= 0.12.10 imports
- data.table >= 1.10.4 imports
- ggplot2 * imports
- loo >= 2.1.0 imports
- matrixStats * imports
- stats * imports
- utils * imports
- testthat * suggests
- actions/checkout v3 composite
- r-lib/actions/check-r-package v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
- r-hub/actions/checkout v1 composite
- r-hub/actions/platform-info v1 composite
- r-hub/actions/run-check v1 composite
- r-hub/actions/setup v1 composite
- r-hub/actions/setup-deps v1 composite
- r-hub/actions/setup-r v1 composite