Learn R Programming

EMC2: Extended Models of Choice 2:

The R package EMC2 provides tools to perform Bayesian hierarchical analyses of the following cognitive models: Diffusion Decision Model (DDM), Linear Ballistic Accumulator Model (LBA), Racing Diffusion Model (RDM), and Lognormal Racing Model (LNR). Specifically, the package provides functionality for specifying individual model designs, estimating the models, examining convergence as well as model fit through posterior prediction methods. It also includes various plotting functions and relative model comparison methods such as Bayes factors. In addition, users can specify their own likelihood function and perform non-hierarchical estimation. The package uses particle metropolis Markov chain Monte Carlo sampling. For hierarchical models, it uses efficient Gibbs sampling at the population level and supports a variety of covariance structures, extending the work of Gunawan and colleagues (2020).

Installation

To install the R package, and its dependencies you can use

install.packages("EMC2")

Or for the development version:

remotes::install_github("ampl-psych/EMC2",dependencies=TRUE)

Workflow Overview

Pictured below are the four phases of an EMC2cognitive model analysis with associated functions:.

Simple DDM Example

library(EMC2)

# Keep only 2 subjects for illustrative purposes
dat <- subset(forstmann, subjects %in% unique(forstmann$subjects)[1:5])
dat$subjects <- droplevels(dat$subjects)

# Drift varies by stimulus (S), boundary by emphasis (E), and t0, Z and sv are consistent.
# SZ, st0, sv and s (for scaling constraints) are assumed constant, since they are not specified here.
# EMC2 will assume that the levels of the `R` factor construct the lower and
# upper boundary in order. By varying the drift rate by `S` we allow the drift 
# rate to be informed by stimulus information.
ddm_design <- design(
  data = dat,
  model = DDM,
  formula = list(v ~ S, a ~ E, t0 ~ 1, Z~1),
)

emc <- make_emc(dat, ddm_design)

# Tiny run for demonstration
fit_ddm <- fit(emc, cores_per_chain = 2, fileName = "DDM.RData", iter = 500)

# See parameter estimates
summary(fit_ddm)

For more details please see the vignettes on the website. Or the original paper: Stevenson, N., Donzallaz, M. C., Innes, R. J., Forstmann, B., Matzke, D., & Heathcote, A. EMC2: An R Package for cognitive models of choice. https://doi.org/10.3758/s13428-025-02869-y

Bug Reports, Contributing, and Feature Requests

If you come across any bugs, or have ideas for extensions of EMC2, you can add them as an issue here. If you would like to contribute to the package's code, please submit a pull request.

References

Stevenson, N., Donzallaz, M. C., Innes, R. J., Forstmann, B., Matzke, D., & Heathcote, A. (2024, January 30). EMC2: An R Package for cognitive models of choice. https://doi.org/10.3758/s13428-025-02869-y

Gunawan, D., Hawkins, G. E., Tran, M. N., Kohn, R., & Brown, S. D. (2020). New estimation approaches for the hierarchical Linear Ballistic Accumulator model. Journal of Mathematical Psychology, 96, 102368. https://doi.org/10.1016/j.jmp.2020.102368

Copy Link

Version

Install

install.packages('EMC2')

Monthly Downloads

621

Version

3.5.0

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Niek Stevenson

Last Published

July 14th, 2026

Functions in EMC2 (3.5.0)

design

Specify a Design and Model
credint.emc.prior

Posterior Quantiles
emc2_build_info

Print EMC2 build configuration
contr.bayes

Contrast Enforcing Equal Prior Variance on each Level
fit.emc

Model Estimation in EMC2
factor_diagram

Factor diagram plot #Makes a factor diagram plot. Heavily based on the fa.diagram function of the psych package.
get_design.emc.prior

Get Design
contr.anova

Anova Style Contrast Matrix
get_group_design.emc.prior

Get Group Design
get_custom_kernel_pointers

Extract pointers of custom C++ trend kernels from trend list or emc object
cut_factors

Cut Factors Based on Credible Loadings
get_data.emc

Get Data
get_prior.emc

Get Prior
high_pass_filter

Apply High-Pass Filtering to fMRI Data
convolve_design_matrix

Convolve Events with HRF to Construct Design Matrices
hypothesis.emc

Within-Model Hypothesis Testing
get_trend_pnames

Get parameter types from trend object
credible.emc

Posterior Credible Interval Tests
get_power_spectra

Compute Power Spectra With Optional Subject-Level Aggregation
get_pars

Filter/Manipulate Parameters from emc Object
ess_summary.emc

Effective Sample Size
fix_custom_kernel_pointers

Reset pointers of custom C++ trend kernels to an emc object
init_chains

Initialize Chains
design_fmri

Create fMRI Design for EMC2 Sampling
make_data

Simulate Data
get_BayesFactor

Bayes Factors
forstmann

Forstmann et al.'s Data
gd_summary.emc

Gelman-Rubin Statistic
ordered_probit

Ordered Probit Response Model
ordered_logit

Ordered Logit Response Model
graphical_model

Graphical Model
multinomial_logit

Multinomial Logit Response Model
merge_chains

Merge Samples
plot.emc.prior

Plot a prior
plot_stat

Plot Statistics on Data
plot_trend

Plots trends over time
plot.emc.design

Plot method for emc.design objects
plot.emc

Plot Function for emc Objects
plot_cdf

Plot Defective Cumulative Distribution Functions
predict.emc.prior

Generate Posterior/Prior Predictives
plot_design_fmri

Plot fMRI Design Matrix
make_SEM_diagram

Make SEM Diagram
prior

Specify Priors for the Chosen Model
plot_delta

Plot Difference of Cumulative Distribution Functions
multinomial_probit

Multinomial Probit Response Model
plot_fit_choice

Plot Choice Model Fit
prior_help

Prior Specification Information
recovery.emc

Recovery Plots
plot_caf

Plot conditional accuracy functions
plot_fmri

Plot fMRI peri-stimulus time courses
plot_pars

Plots Density for Parameters
register_trend

Register a custom C++ trend kernel
profile_plot

Likelihood Profile Plots
group_design

Create Group-Level Design Matrices
sampled_pars

Get Model Parameters from a Design
make_emc

Make an emc Object
subset.emc

Shorten an emc Object
summary.emc

Summary Statistics for emc Objects
plot_sbc_hist

Plot the Histogram of the Observed Rank Statistics of SBC
plot_spectrum

Plot Empirical and Posterior Predictive Power Spectra
model_averaging

Model Averaging
samples_LNR

LNR Model of Forstmann Data (First 3 Subjects)
plot_density

Plot Defective Densities
plot_sbc_ecdf

Plot the ECDF Difference in SBC Ranks
plot_design.emc.design

Plot Design
make_trend

Create a trend specification for model parameters
run_bridge_sampling

Estimating Marginal Likelihoods Using WARP-III Bridge Sampling
mapped_pars

Parameter Mapping Back to the Design Factors
parameters.emc.prior

Return Data Frame of Parameters
set_custom_kernel_pointers

(Re-)Set pointers of custom C++ trend kernels to an emc object
run_emc

Fine-Tuned Model Estimation
split_timeseries

Split fMRI Timeseries Data by ROI Columns
plot_relations

Plot Group-Level Relations
update2version

Update EMC Objects to the Current Version
make_random_effects

Generate Subject-Level Parameters
make_sem_structure

Define Structural Equation Model (SEM) Matrices
pairs_posterior

Plot Within-Chain Correlations
run_sbc

Simulation-Based Calibration
rotate_loadings

Rotate loadings based on posterior median
reshape_events

Reshape events data for fMRI analysis
run_hyper

Run a Group-level Model.
summary.emc.design

Summary method for emc.design objects
summary.emc.prior

Summary method for emc.prior objects
trend_help

Get help information for trend kernels and bases
summary.emc.group_design

Summary method for emc.group_design objects
EMC2-package

EMC2: Bayesian Hierarchical Analysis of Cognitive Models of Choice
add_ICs_MLL

Add information criteria to emc object
RDM

The Racing Diffusion Model
align_loadings

Reorder MCMC Samples of Factor Loadings
DDM

The Diffusion Decision Model
chain_n

MCMC Chain Iterations
LNR

The Log-Normal Race Model
check.emc

Convergence Checks for an emc Object
MRI_AR1

Create an AR(1) GLM model for fMRI data
DDMGNG

The GNG (go/nogo) Diffusion Decision Model
apply_kernel

Apply a kernel implied in an emc object
MRI

GLM model for fMRI data
compare

Information Criteria and Log Marginal Likelihood
contr.decreasing

Contrast Enforcing Decreasing Estimates
LBA

The Linear Ballistic Accumulator model
compare_subject

Information Criteria For Each Participant
contr.increasing

Contrast Enforcing Increasing Estimates
auto_thin.emc

Automatically Thin an emc Object