Learn R Programming

⚠️There's a newer version (0.2.6.2) of this package.Take me there.

DMC with Parallel Computation and C++ Capabilities

ggdmc implements hierarchical Bayesian, evidence accumulation model (HB-EAM). This release includes drift-diffusion model (Ratcliff, 1978). Based on Voss, Rothermund, and Voss's (2004) fast-dm 30.2 density.c, the DDM in ggdmc implements the equations in their paper as C++ routines plus a new parallel integration function to handle high precision requirement.

ggdmc is derived from Andrew Heathcote's Dynamic Model of Choice (DMC), which has also implemented other numerous EAMs. Identical to DMC, ggdmc uses differential evolution Markov Chain Monte Carlo sampler to search optimal theta and phi that maximise posterior likelihood.

Getting Started

Here is a simple example extracted from Andrew Heathcote's DMC workshop materials. For further details, please see R help pages in this package.

require(ggdmc) 

## Use a 6-parameter drift-diffusion model  
## The only experimental factor is Stimulus type
m1 <- model.dmc(
  p.map     = list(a="1", v="1", z="1", d="1", sz="1", sv="1", t0="1",st0="1"),
  constants = c(st0=0, d=0),          ## Fixed st0 and d at 0
  match.map = list(M = list(s1 = "r1", s2 = "r2")),
  factors   = list(S=c("s1", "s2")),  ## Two stimulus types  
  responses = c("r1","r2"),           ## Two response types
  type      = "rd")                   ## rd stands for Ratcliff's diffusion

## Set up a prior probability distribution setting
p.prior <- prior.p.dmc(
  dists = rep("tnorm", 6),
  p1    = c(a=2,  v=2.5, z=.5, sz=.3, sv=1,  t0=.3),
  p2    = c(a=.5, v=.5,  z=.1, sz=.1, sv=.3, t0=.05),
  lower = c(0,-5, 0, 0, 0, 0),
  upper = c(5, 7, 2, 2, 2, 2))

## Assume a true DDM parameter vector
p.vector <- c(a=1, v=1, z=.5, sz=.25, sv=0.2,t0=.15)

## Use simulate function to simulate choice-RT data 
## One usually would like to fit his/her own empirical data.
dat1 <- simulate(m1, nsim=1e2, p.vector=p.vector)

## Set up a data model instance. This binds the empirical/simulated data with 
## the model set-up
mdi1 <- data.model.dmc(dat1, m1)

## Initialise a small sample 
## (1) iteration number == 250 
## (2) thinning length == 1
## (3) prior distributions are listed in p.prior 
## (4) data == mdi1, an assumed model and a simulated/empirical data frame
samples0 <- samples.dmc(nmc=250, p.prior=p.prior, data=mdi1, thin=1)

## Fit the Bayesian model 
samples0 <- run.dmc(samples0)


## Check if model converged, etc.
gelman.diag.dmc(samples0)
## Potential scale reduction factors:
## 
##    Point est. Upper C.I.
## a        1.16       1.29
## v        1.20       1.36
## z        1.18       1.33
## sz       1.12       1.21
## sv       1.24       1.48
## t0       1.16       1.34

plot(samples0)  ## Check traceplot to see if chains converged

## Further details and more arguments, please see
?gelman.diag.dmc
?samples.dmc
?run.dmc
?plot.dmc

## For hierarchical Bayesian model 
?h.run.dmc
?h.samples.dmc
?plot.dmc.list
?plot.hyper

Prerequisites

  • R (>= 3.0.0)
  • Rcpp (>= 0.12.10), RcppArmadillo (>= 0.7.700.0.0), ggplot2 (>= 2.1.0), rtdists (>= 0.6-6), gridExtra (>= 2.2-1), ggmcmc (>= 0.7.3), ggthemes (>= 3.0.1), stats (>= 3.2.2), loo (>= 0.1.6), coda (>= 0.16-1)
  • Windows users need Rtools (>= 3.3.0.1959), and Microsoft Visual Studio Community (>= 2015) (for Open MPI library and M_PI macro support)
  • OS X users need to install Open MPI library
  • Linux/Unix users may need to install Open MPI library, if it has not been installed.
  • Armadillo requires a recent compiler; for the g++ family at least version 4.6.* is required.

Successful cases for Windows OS:

  • Microsoft Visual Studio Community 2015 (Version 14.0.25421.03 Update 3) on
    Windows 10 64 bits.
  • Microsoft Visual Studio Community 2015 (Version 14.0.24720.1 Update 1), with Rtools 3.4 on Windows 10 64 bits.

Unsuccseeful cases for Windows OS:

  • Microsoft Blend for Visual Studio Express 2015

Installing

From CRAN: install.packages("ggdmc")
From source: install.packages("ggdmc_0.1.3.9.tar.gz", repos = NULL, type="source")

### Other supporting packages for DMC (not necessary for ggdmc)
install.packages("coda_0.18-1.3.tar.gz", repos = NULL, type="source")
install.packages("tnorm_0.1.0.0.tar.gz", repos = NULL, type="source")

Citation

If you use this package, please cite the software, for example:

Lin, Y.-S., & Heathcote, A (in preparation). ggdmc: An R package for hierarchical Bayesian evidence accumulation models, using differential evolution Markov Chain Monte Carlo Sampler. Retrieved from https://github.com/TasCL/ggdmc

Contributors

The ggdmc C++ codes are developed by Yi-Shin Lin.

The R codes mainly are incorporated from DMC developed by Andrew Heathcote].

If there is any bug been introduced inadvertently into DMC R codes, they are probably errors brought in by the first author. Please report any bugs you may find to the first author.

License

GPL-2. Please see License.md/LICENSE for details.

Acknowledgments

  • density.cpp is based on Voss & Voss's (2012) density.c in fast-dm 30.2. Any

identical parts in density.cpp belong to their copyright.

  • The tnorm_wrapper.cpp and tnorm.R are based on Jonathan Olmsted's

jpolmsted@gmail.com RcppTN 0.1-8 (https://github.com/olmjo/RcppTN) and Christopher Jackson's chris.jackson@mrc-bsu.cam.ac.uk R codes in msm. Any identical parts in tnorm_wrapper.cpp and tnrom.R belong to their copyright.

  • C++ codes in this package depend largely on Dirk Eddelbuettel, Romain

Francois and Doug Bates's Rcpp, and RcppArmadillo.

  • Armadillo is a collection of C++ library for performing linear

algebra http://arma.sourceforge.net/, authored by Conrad Sanderson.

  • Crossover (DEMCMC) sampler is based on the following papers,

Turner & Sederberg (2012), Turner et al (2013) and Ter Braak (2006).

  • Thanks to Matthew Gretton's consulation about rtdists's internal.

Copy Link

Version

Install

install.packages('ggdmc')

Monthly Downloads

418

Version

0.1.3.9

License

GPL-2

Issues

Pull Requests

Stars

Forks

Maintainer

Yi-Shin Lin

Last Published

March 31st, 2017

Functions in ggdmc (0.1.3.9)

dprior

Calculate Prior Probability Density for an EAM
ddmc

Compute Probability Density of Drift-Diffusion Model
density.dmc

Calculate Probability Density for an Experimental Condition
dtnorm

Truncated Normal Distribution
effectiveSize.dmc

Effective Sample Size for Estimating the Mean
acf.dmc

Plot an Autocorrelation Matrix
Dstats.ddm

Calculate Dstats of DDM Density
censor

Censor missing values and RT outliers
fac2df

Convert factor levels to a data frame
data.model.dmc

Bind Data and Models
g_minus

Calculate Drift-diffusion Probability Density
ggdmc

Supersonic DMC
getAccumulatorMatrix

Map a parameter vector to an accumulator matrix
h.samples.dmc

Set up a DMC Sample with Multiple Participants
get_os

get_os Function
initialise_data

Set up a DMC Sample for a Participant
initialise_hyper

Set up a DMC Sample for Multiple Participants
gelman.diag.dmc

Gelman and Rubin Convergence Diagnostic
h.run.dmc

Fit an EAM with Multiple Participants
h.simulate.dmc

Simulate Choice-RT Data for Multiple Participants
pick.stuck.dmc

Find Stuck Chains
plot.dmc

Plot DMC Samples
model.dmc

Creating a Model Object
pairs.dmc

Create a Plot Matrix of Posterior Simulations
p.df.dmc

Gets Parameter Data Frame
plot.dmc.list

Plot a DMC Sample with Multiple Participants
plot.hyper

Plot DMC Samples at the Hyper level
likelihood

Calculate Log-Likelihood
phi.as.mcmc.list

Convert Phi to a Theta Vector
mcmc.list.dmc

Create a mcmc.list in DMC format
profile.dmc

Profile a DMC Object
post.predict.ggdmc

Simulate Post-predictive Sample
plot_cell_density

Plot Distributions for Each Cell
plot_dist

Plot Cell Density
plot_prior

Plot Prior Probability Density
plot.pp.ggdmc

Posterior Predictive Plot
print_cell_p

Print accumulator x internal parameter type matrix for each cell
prior.p.dmc

Makes a list of prior distribution parameters.
rprior

Generate Random Numbers from Prior Probability Distribution
plot_priors

Plot Prior Probability Density
summary.hyper

Summarise a DMC Sample with Multiple Participant at the Hyper-level
run_data

Run a Bayesian EAM Model for Fixed-effect or Random-effect
summary.dmc

Summarise a DMC Sample with One Participant
run.dmc

run function
theta.as.mcmc.list

Convert Theta to a mcmc List
summed_log_likelihood

Sum and Log Probability Density of a EAM model
summed_log_prior

Sum and Log Prior Density of a EAM model
summary.dmc.list

Summarise a DMC Sample with Multiple Participants
samples.dmc

Initialising a DMC samples
simulate.dmc

Simulate Responses from an EAM
transform

Transform Parameter Data Frame
view

Inspect Prior Distribution Settings