#| include: false knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 4)
cogmod provides cognitive models for two broad families of behavioural data: subjective ratings collected on Likert or analog scales, and decision making tasks that yield reaction times and choices.
Each model comes in two halves. The first is a set of plain R functions -
r*() to simulate, d*() for the density, useful on their own for simulation, predictions, visualization, and teaching.
library(cogmod) set.seed(3) x <- rcogmod_betagate(5000, mu = 0.6, phi = 4, pex = 0.15, bex = 0.4) hist(x, breaks = 50, col = "#2196F3", border = NA, main = "Beta-Gate ratings", xlab = "Rating")
The second half is the machinery needed to fit the model as a custom response
distribution in brms: a family
constructor, the Stan code implementing its log-density, and the
log_lik/posterior_predict/posterior_epred methods that make loo,
pp_check() and the easystats post-processing functions work as they
normally would. Fitting requires a Stan backend
(cmdstanr is recommended).
#| eval: false library(brms) f <- bf(rating ~ condition + (1 | participant), phi ~ 1, pex ~ 1, bex ~ 1, family = cogmod_betagate()) m <- brm( f, data = df, stanvars = cogmod_stanvars(f), backend = "cmdstanr" )
The pattern is the same for every model: name the family in bf(), then let
cogmod_stanvars() supply the Stan code that goes with it. Two companions
follow the same shape - cogmod_priors(f, df) for the priors brms would
otherwise leave flat, and cogmod_inits(f, df) for starting values on the
families whose default start is a bad one.
The function reference lists every model with its parameterisation. Worked, end-to-end analyses live on the package website, where they can be built with fitted models that would be too slow to include here:
cogmod relates to brms's native families and to bmm, and when each is the better choice.citation("cogmod")
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.