lbaModel
provides fast and flexible
tools for working with the Linear Ballistic Accumulator
(LBA) model, a widely used framework in cognitive psychology
and neuroscience for simulating and analysing choice and response time
(RT) data.
Key features:
While designed to be part of the ggdmc
ecosystem, lbaModel
is also fully functional as a
standalone package.
Hereβs a schematic of the LBA model showing accumulators racing to threshold (similar to diffusion models, but with linear deterministic growth.)
Figure: The LBA model assumes evidence accumulates linearly and independently across choices, with start points, drawing from a uniform distribution and drift rates. The first accumulator to hit its threshold determines the response and response time.
library(ggdmcModel)
library(ggdmcPrior)
<- BuildModel(
model p_map = list(A = "1", B = "1", t0 = "1", mean_v = "M", sd_v = "1", st0 = "1"),
match_map = list(M = list(s1 = "r1", s2 = "r2")),
factors = list(S = c("s1", "s2")),
constants = c(st0 = 0, sd_v = 1),
accumulators = c("r1", "r2"),
type = "lba"
)
# Set population-level prior
<- c(A = 0.4, B = 0.5, mean_v.false = 0.15, mean_v.true = 2.5, t0 = 0.3)
pop_mean <- c(A = 0.1, B = 0.1, mean_v.false = 0.2, mean_v.true = 0.2, t0 = 0.05)
pop_scale
<- BuildPrior(
pop_dist p0 = pop_mean,
p1 = pop_scale,
lower = c(0, 0, 0, 0, 0),
upper = rep(NA, length(pop_mean)),
dists = rep("tnorm", length(pop_mean)),
log_p = rep(FALSE, length(pop_mean))
)
plot_prior(pop_dist)
<- setLBA(model)
sub_model <- setLBA(model, population_distribution = pop_dist)
pop_model
# One subject
<- c(A = 0.75, B = 1.25, mean_v.false = 1.5, mean_v.true = 2.5, t0 = 0.15)
p_vector <- simulate(sub_model, nsim = 256, parameter_vector = p_vector, n_subject = 1)
dat
# Multiple subjects
<- simulate(pop_model, nsim = 128, n_subject = 32) hdat
# Parameters
<- list(
params_tmp A = c(0.5, 0.5),
b = c(1.0, 1.0),
mean_v = c(2.0, 1.0),
sd_v = c(1.0, 1.0),
st0 = c(0.0, 0.0),
t0 = c(0.2, 0.2)
)
# Convert to matrix
<- function(param_list) {
param_list2mat <- length(param_list[[1]])
n_row <- length(param_list)
n_col <- matrix(NA, nrow = n_row, ncol = n_col)
out for (i in seq_len(n_col)) out[, i] <- param_list[[i]]
t(out)
}
<- param_list2mat(params_tmp)
params <- c(0, 5, 0.01)
time_params <- ncol(params)
nv <- rep(TRUE, nv)
is_pos
<- theoretical_dlba(params, is_pos, time_params)
pdfs <- theoretical_plba(params, is_pos, time_params) cdfs
install.packages("lbaModel")
β οΈ Requires development tools and extra dependencies.
# install.packages("devtools")
::install_github("yxlin/lbaModel") devtools
If you use lbaModel
, please cite:
glba
:
Generalised LBA model fitting via MLErtdists
:
Density/distribution for LBA and diffusion models.lbaModel
?ggdmc
for hierarchical Bayesian
inferenceggdmcLikelihood
, pPDA
) for high-performance
parallelised LBAContributions are welcome! Please feel free to submit issues, fork the repo, or open pull requests.