cogmod cogmod logo

Models of Cognition for Subjective Scales and Decision Making Tasks in R

This R package is dedicated to facilitate the application of computational models of cognition in R under a Bayesian framework. These are useful in the field of cognitive science and computational neuropsycholology.

If you have suggestions for improvement, please get in touch!

Features

interactive visualization of evidence accumulation models of cogmod

Response formats covered by cogmod, and the main families available for each. Every family comes with a _stanvars() function supplying its Stan code, and with d*() and r*() functions for density evaluation and simulation.

What are Computational Cognitive Models?

Measures from cognitive tasks, such as decision-making paradigms involving fast responses or ratings, often produce noisy, specific, and complex patterns of results. Broadly speaking, there are three ways of analysing such data.

Illustration animation of Drift Diffusion Models

Installation

Install the released version from CRAN:

install.packages("cogmod")

Or the development version from GitHub:

if (!requireNamespace("remotes", quietly = TRUE)) install.packages("remotes")

# remotes::install_github("DominiqueMakowski/cogmod")
install.packages("cogmod", repos = c('https://dominiquemakowski.r-universe.dev', 'https://cloud.r-project.org'))

Fitting the models requires a working Stan installation through brms. The examples use the cmdstanr backend, which is not on CRAN: follow its installation guide to set up CmdStan.

Usage

Using a cogmod model requires two arguments beyond a standard brm() call: family and stanvars. Two further helpers, cogmod_priors() and cogmod_inits(), are strictly speaking optional but should be treated as part of the call: they provide adapted chain-initialization values and weakly informative priors on the sensitive parameters to limit convergence issues and other sampling pathologies.

library(cogmod)
library(brms)

# Specify the formula using brms' bf()
f <- bf(
  RT ~ Condition,
  sigma ~ Condition,
  ndt ~ Condition,
  sigmabias = 0,  # No start-point variability
  family = cogmod_lognormal()
)

# Fit the model
m <- brm(
  f,
  data = df,
  prior = cogmod_priors(f, df),
  init = cogmod_inits(f, df),
  stanvars = cogmod_stanvars(f),
  backend = "cmdstanr"
)

We can then analyze its results, and check its predictions like with any other models. See the Subjective Ratings, RT-only Models, and Decision Making Models vignettes for more detailed examples.

Roadmap