Learn R Programming

dRiftDM

The package dRiftDM was developed to assist psychology researchers in applying and fitting diffusion models to empirical data within the R environment. Its most important feature is the ability to handle non-stationary problems, specifically diffusion models with time-dependent parameters (such as a drift rate that changes over the course of a trial). The package includes essential tools for standard analyses, such as building models, estimating parameters for multiple participants, and creating/visualizing summary statistics. The pre-built models available in the package are:

  • The Standard Ratcliff Diffusion Model (Ratcliff, 1978, Psychological Review)
  • The Diffusion Model for Conflict Tasks (Ulrich et al., 2015, Cognitive Psychology)
  • The Shrinking Spotlight Model (White et al., 2011, Cognitive Psychology)

We can flexibly create custom models and utilize the dRiftDM machinery to estimate them. Variability in the starting point and non-decision time is generally supported. Variability in the drift rate is also supported, although it is limited to models with a time-independent/constant drift rate. Model components for a collapsing boundary are already pre-built. Demos for model customization are provided in one of our vignettes.

Model predictions (i.e., first-passage times) are derived by numerically solving the Kolmogorov-Forward equation (KFE) using a time-adaptive procedure (i.e., the time-step size is adjusted dynamically and this leads to substantial speed-up). This is the default, and we currently recommend keeping it that way.

For backward compatibility, it is also possible to derive the first-passage-time distribution via a coupled set of integral equations. However, this method does not yet support adaptive time stepping. Thus, finer discretization settings are necessary, and it will generally run slower than the approach based on the KFE.

Mathematical details of both approaches are provided in Richter et al. (2023, Journal of Mathematical Psychology).

Installation

You can install the development version of dRiftDM from GitHub with:

# install.packages("devtools")
devtools::install_github("bucky2177/dRiftDM")

The CRAN version can be installed with:

install.packages("dRiftDM")

Notes

Compared to the initial version 0.1.1, versions >=0.2.0 make greater use of the S3 object system. Additionally, beginning with version 0.2.0, models use flex_prms objects to handle parameters across conditions.

In versions >=0.3.0, we implemented a more efficient KFE-based solver, which led to a substantial speed-up. We also added several new features:

  • different optimization algorithms (including unbounded Nelder-Mead and BFGS)
  • different cost functions (with the root-mean-square error, RMSE, as an alternative to the log-likelihood)
  • default parameter ranges for pre-built models
  • visualizing the full distribution of a model and calculating basic summary statistics
  • calculating/visualizing uncertainty intervals via bootstrap-like procedures
  • fitting a model to aggregated data using the RMSE statistic
  • fitting a model via hierarchical and non-hierarchical Bayesian estimation (currently experimental and not fully connected to all of dRiftDM’s features)

To install one of the older versions (0.1.1, 0.2.1, 0.2.2), you can use:

devtools::install_github("bucky2177/dRiftDM", ref = "<insert version>")

How to use dRiftDM

If you are interested in getting started with dRiftDM, we recommend reading the OSF pre-print. More information on functions and model customization can be found in dRiftDM’s vignettes. These vignettes are also available from the “Getting started” and “Articles” tabs on our Github.io page.

If you have any questions, feel free to contact us!

Copy Link

Version

Install

install.packages('dRiftDM')

Monthly Downloads

196

Version

0.3.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Valentin Koob

Last Published

December 1st, 2025

Functions in dRiftDM (0.3.1)

calc_stats

Calculate Statistics
calc_stats_pred_obs

Calculate Statistics for Model Prediction and/or Observed Data
calc_pdfs

Calculate the PDFs
calc_fit_stats

Calculate Fit Statistics
calc_rmse_eval

RMSE Calculation and Helpers
calc_dens_obs

Calculate and Combine Density Estimates for Observed and Predicted Data
calc_quantiles_obs

Calculate Quantiles
calc_delta_funs

Calculate delta function(s)
calc_log_like

Calculate the Log-Likelihood
calc_quantiles

Calculate Quantiles
check_b_coding

Check a B_Coding
coef<-

Access Coefficients of a Model
check_reduce_raw_data

Check and Reduce the Observed Data
comp_funs<-

The Component Functions of A Model
check_internal_list

checks if all entries of internal_list are an expression or integer. Throws an error if not (internal docu)
check_digit_larger_0

Checks if a variable/vector of length 1 is a number > 0 or 0/expression
check_discretization

Check time/space discretization via reference comparison
call_log_posterior_m

Metropolis Acceptance Step for Vectorized MCMC Sampling
comp_vals

Evaluate all Component Functions
check_if_named_numeric_vector

Check if Object is a Named Numeric Vector
create_matrix_smart

Create a matrix for lower and upper
create_temperatures

Create "Temperatures" for TIDE
count_unique_prms_one_internal_entry

Count the number of digits > 0
copy_class_attributes

Copy Class Attributes from One Object to Another
d_default_prior_hyper

Default Prior for Group-Level (Hyper) Parameters
component_shelf

Diffusion Model Components
cost_function<-

Access/Replace the Cost Function Label and Access the Cost Function Value
conds<-

The Conditions of an Object
dRiftDM-package

dRiftDM: Estimating (Time-Dependent) Drift Diffusion Models
crossover

Perform Crossover Between Chains
drift_dm_stats_types

Available types of statistics
dmc_dm

Create the Diffusion Model for Conflict Tasks
drift_dm_cost_functions

Available Cost Functions for Model Estimation
drift_dm_pre_built_models

Pre-built Drift Diffusion Models
ddm_opts<-

Optional Arguments for the Component Functions
drift_dm

Create a drift_dm object
do_resampling

Temporarily suppress new stats generation during resampling
dmc_synth_data

A synthetic data set with two conditions
defaults

Default Values for the dRiftDM Package
draw_from_pdf

Draw Samples Using Inverse Transform Sampling
dtnorm

Truncated Normal Density Function
estimate_model

Estimate the Parameters of a drift_dm Model
estimate_classical

Estimate Parameters of a drift_dm Model via Classical Optimization
estimate_bayesian

(Hierarchical) Bayesian Estimation
estimate_classical_wrapper

Internal wrapper for classical estimation of individuals
estimate_model_ids

Fit Multiple Individuals and Save Results
estimate_dm

Fit a DDM to Observed Data
estimate_bayes_h

(Hierarchical) Bayesian Estimation with Differential Evolution
dt_b_constant

Derivative of a Constant Boundary
drop_levels_ID_column

Maybe droplevels of ID column
flex_vary_prms

Allow parameters to vary
flex_prms<-

Flex_Prms
flex_specific_value

Set a specific value to the parameter matrix (internal docu)
get_avg_trials

Compute average trials per condition across individuals
flex_fix_prms

Exclude parameters from being modified (i.e., fix it; internal docu)
full_crossover

Perform a Full Crossover Step Using Differential Evolution
flex_cust_prm

Specify custom parameters
get_default_functions

Get default/fall back component functions
flex_special_dependency

Set special dependencies (internal docu)
flex_restrain_prms

Set parameters as equal across conditions
get_example_fits

Auxiliary Function to load a fits_ids_dm, fits_agg_dm, or mcmc_dm object
get_lower_upper

Get Default Parameter Ranges for a Model
hist.coefs_dm

Plot Parameter Distribution(s)
internal_aggregate

Aggregate Data Frame Columns by Group
get_starting_values

TITLE
get_subset_chains

Extract a Subset of MCMC Chains
get_ez_diffusion

Compute EZ Diffusion parameters
get_default_prior_settings

Generate Prior Functions for Model Parameters
get_parameters_smart

Turn default/special parameter specifications to vectors
internal_list_to_matrix

Turn an internal list to a matrix
mcmc_dm_to_coda_mcmc

Convert MCMC Chain Array to a coda::mcmc.list Object
logLik.drift_dm

Extract Log-Likelihood for a drift_dm Object
log_posterior_hyper

Conditional Log-Posterior Distributions for MCMC Sampling
load_fits_ids

Load Estimates of a Fit Procedure
logLik.fits_ids_dm

Extract Model Statistics for fits_ids_dm Object
linearize_internal_list

Relabel the internal list
max_number_one_internal_entry

Get the maximum number from an internal entry or flex_prms_obj (internal docu)
is_empty

Check if an object of length <= 1 is either empty or contains entry with ""
migration_crossover

Perform a Migration Step Between Chains
is_numeric

Check if an object is a valid numeric vector
nobs.drift_dm

Get the Number of Observations for a drift_dm Object
modify_flex_prms

Set Instructions to a flex_prms object
mu_int_dmc

Integral of DMC's Drift Rate
nt_constant

Constant Non-Decision time
new_stats_dm

Create a New stats_dm Object
new_drift_dm

Create a DDM model --- internal
mu_constant

Constant Drift Rate
mu_int_constant

Integral of Constant Drift Rate
mu_dmc

Drift Rate for DMC
mu_ssp

Drift Rate for SSP
plot.delta_funs

Plot Delta Functions
plot.mcmc_dm

Plot MCMC Results and Diagnostics for mcmc_dm Objects
pdfs

Access the Probability Density Functions of a Model
plot.drift_dm

Plot Components of a Drift Diffusion Model
plot.densities

Plot Distributions of Predicted and Observed Data
plot.cafs

Plot Conditional Accuracy Functions (CAFs)
nt_uniform

Uniform Non-Decision Time
obs_data<-

The Observed Data
obs_data_to_rt_lists

Disassemble an Observed Data set
nt_truncated_normal

Truncated Normally-Distributed Non-Decision Time
plot.stats_dm_list

Plot Multiple Statistics
print.cafs

Print Functions for Stats Objects
plot_mcmc_trace

Plot MCMC Chains for Drift Diffusion Model Parameters
plot.quantiles

Plot Response Time Quantiles
plot.traces_dm_list

Plot Traces of a Drift Diffusion Model
prms_solve<-

The Parameters for Deriving Model Predictions
prms_cond_combo

Unique Conditions-Parameter Combinations
prms_to_str

Format Parameters as String
prms_conds_to_modify

Extract the conditions and parameters from an instruction string
prm_cond_combo_2_labels

Generate Parameter-Condition Labels
ratcliff_dm

Create a Basic Diffusion Model
re_evaluate_model

Re-evaluate the model
set_one_solver_setting

Set one specific aspect of the solver settings
set_agg_data

Set aggregated data to a model object
remove_estimate_info

Remove flags added when calling estimate_classical
simulate_data

Simulate Synthetic Responses
set_default_arguments

Set default graphical parameters for plotting in dRiftDM
set_default_colors

Set Default Colors
ratcliff_synth_data

A synthetic data set with one condition
resample_helpers

Internal Helpers for Resampling of Summary Statistics
ssp_dm

Create the Shrinking Spotlight Model
solver<-

The Solver for Deriving Model Predictions
stats.options

Helper to get, set, or reset package-global options for statistics
simulate_traces_one_cond

Simulate Traces for One Conditions
simulate_values

Simulate Values
sort_one_internal_entry

Sorts the numbers in ascending order
stats_from_pdfs_agg_info

Get Quantiles/CAFs from PDFs and stats_agg_info
ssp_synth_data

A synthetic data set with two conditions
simulate_traces

Simulate Trajectories/Traces of a Model
simulate_one_data_set

Simulate one data set
stats_resample_dm

Resample Observed and Predicted Statistics for Interval Estimation
summary.stats_dm

Summary for stats_dm Objects
summary.flex_prms

Summarizing Flex Parameters
print.summary.fits_agg_dm

Summary and Printing for fits_agg_dm Objects
summary.mcmc_dm

Summary for mcmc_dm Objects
print.summary.fits_ids_dm

Summary and Printing for fits_ids_dm Objects
summarize_drift_dm_info

Reads Info file
summary.traces_dm

Summary for traces_dm and traces_dm_list Objects
summary.drift_dm

Summary for drift_dm objects
summary.coefs_dm

Summary for coefs_dm Objects
unpack_traces

Unpack/Destroy Traces Objects
internal_trapz

Numerical integration using the trapezoidal rule
unpack_obj

Unpack/Destroy dRiftDM Objects
try_cast_integer

Convert Character Digits to Numeric Digits
validate_fits_ids

Validate a an Object of Type fits_ids_dm
ulrich_flanker_data

Exemplary Flanker Data
validate_drift_dm

Validate a DDM object
update_special_values

Update all prms
update_stats_agg

Update aggregated statistics in a drift_dm object
ulrich_simon_data

Exemplary Simon Data
validate_flex_prms

checks if a flex_prms_object is parameterized in a reasonable way
x2prms_vals

Update the parameter matrix for vector inputs (internal docu)
x_dirac_0

Constant Starting Point at Zero
x_uniform

Uniform Starting Point Distribution Centered Around Zero
x_beta

Beta-Shaped Starting Point Distribution Centered Around Zero
validate_stats_dm

Validate a stats_dm Object
calc_basic_stats

Calculate Basic Statistics for Response Times or Probability Densities
b_coding<-

The Coding of the Boundaries
b_weibull

Collapsing Boundary - Weibull Function
calc_cafs_obs

Calculate CAFs
aggregate_stats

Aggregate Statistics Across ID
add_residual

Convolute the First Passage Times with the Non-Decision Time Distribution
b_constant

Constant Boundary
calc_cafs

Calculate CAFs
b_hyperbol

Collapsing Boundary - Hyperbolic Ratio Function
calc_basic_stats_obs

Calculate Basic Mean, Standard Deviations, and Percentages for Observed and Predicted Data