Package 'SSRTcalc'

Title: Stop-Signal Reaction Time Calculator with Monte Carlo and Bayesian Extensions
Description: Estimates stop-signal reaction time (SSRT) using integration and mean methods following Verbruggen et al. (2019) <doi:10.7554/eLife.46323>. Version 2.0 adds three major extensions: (1) Monte Carlo methods -- nonparametric bootstrap confidence intervals, parametric ex-Gaussian simulation, power/minimum-trial-count analysis, and robustness testing under horse-race assumption violations; (2) Bayesian estimation via Stan -- single-subject and hierarchical ex-Gaussian horse-race models with optional trigger-failure parameter, posterior inhibition functions, and posterior predictive checks; (3) convenience wrappers for comparing models and running full pipelines. Stan integration works with either cmdstanr or rstan as backend.
Authors: Anton Leontyev [aut, cre] (ORCID: <https://orcid.org/0000-0001-8880-6161>)
Maintainer: Anton Leontyev <[email protected]>
License: GPL-3
Version: 2.0.4
Built: 2026-07-04 23:18:28 UTC
Source: https://github.com/agleontyev/ssrtcalc

Help Index


Example adaptive stop-signal task data

Description

A long-format dataset from a stop-signal task using an adaptive (staircase-tracking) stop-signal delay, suitable for demonstrating every function in SSRTcalc.

Usage

adaptive

Format

A data frame with 4000 rows (20 subjects x 200 trials) and 6 columns:

SubjID

Integer subject identifier (1-20).

trial

Integer trial number within subject (1-200).

vol

Trial type: 0 = go trial, 1 = stop trial.

RT_exp

Observed reaction time in milliseconds. NA on successfully inhibited stop trials.

correct

Accuracy indicator (1 = correct response on go trials, or successful inhibition on stop trials; 0 otherwise).

soa

Stop-signal delay (SOA) in milliseconds for stop trials; NA on go trials. Adjusted trial-by-trial by a staircase algorithm to track ~50% inhibition.

Source

Simulated data distributed with the SSRTcalc package, generated to resemble a typical adaptive stop-signal task following Verbruggen et al. (2019) <doi:10.7554/eLife.46323>.

Examples

data(adaptive)
d <- adaptive[adaptive$SubjID == 1, ]
integration_adaptiveSSD(d)

Fixed-SSD dataset for stop-signal task

Description

Data from a mouse movement-based stop-signal experiment, using preset stop-signal delays, with random dot kinematogram as the "go" task, collected from 51 participants

Usage

data(fixed)

Format

A data frame with 29376 rows and 7 variables

new_id

Subject identifier

soa

stop-signal delay (ignore for "go" trials)

vol

stop (1) or go (0) trial

coh

Percent coherent dots in the kinematogram go task

RT_exp

Response time in seconds, NA if no response was made

response

Which button did the participant click?

acc

Did the participant respond in "go" trials/omit response in "stop" trials (1) or not(0)?

Source

OSF archive

References

Leontyev and Yamauchi (2019) PLoS One (doi:10.1371/journal.pone.0225437)

Examples

data(fixed)
head(fixed)

Estimate SSRT via the integration method (adaptive / staircase SSD design)

Description

Implements the recommended integration method from Verbruggen et al. (2019). For each dataset:

  1. Compute p(respond|signal) from all stop trials.

  2. Find the nth percentile of the go-RT distribution (n = p_respond).

  3. Subtract the mean SSD: SSRT = nth_percentile_RT - mean(SSD).

Usage

integration_adaptiveSSD(
  data,
  stop_col = "vol",
  rt_col = "RT_exp",
  acc_col = "correct",
  ssd_col = "soa",
  min_rt = 50
)

Arguments

data

A data.frame with one row per trial.

stop_col

Column name for the stop-trial indicator (1 = stop, 0 = go). Default "vol".

rt_col

Column name for reaction time in ms. Default "RT_exp".

acc_col

Column name for accuracy (1 = correct). Default "correct".

ssd_col

Column name for stop-signal delay in ms. Default "soa".

min_rt

Minimum valid RT in ms; shorter responses are excluded as anticipations. Default 50.

Value

A single numeric value: the estimated SSRT in milliseconds.

References

Verbruggen, F., et al. (2019). A consensus guide to capturing the ability to inhibit actions and impulses: the stop-signal task. eLife, 8, e46323. doi:10.7554/eLife.46323

Examples

data(adaptive)
d <- adaptive[adaptive$SubjID == 1, ]
integration_adaptiveSSD(d)

Estimate SSRT via the integration method (fixed SSD design)

Description

Identical to integration_adaptiveSSD in computation, but intended for experiments using a fixed (constant) stop-signal delay. When multiple fixed SSD values are used, SSRT is computed separately for each SSD and the results are averaged (Verbruggen et al., 2019, Appendix).

Usage

integration_fixedSSD(
  data,
  stop_col = "vol",
  rt_col = "RT_exp",
  acc_col = "correct",
  ssd_col = "soa",
  min_rt = 50
)

Arguments

data

A data.frame with one row per trial.

stop_col

Column name for the stop-trial indicator (1 = stop, 0 = go). Default "vol".

rt_col

Column name for reaction time in ms. Default "RT_exp".

acc_col

Column name for accuracy (1 = correct). Default "correct".

ssd_col

Column name for stop-signal delay in ms. Default "soa".

min_rt

Minimum valid RT in ms; shorter responses are excluded as anticipations. Default 50.

Value

A single numeric value: the estimated SSRT in milliseconds.

References

Verbruggen, F., et al. (2019). A consensus guide to capturing the ability to inhibit actions and impulses: the stop-signal task. eLife, 8, e46323. doi:10.7554/eLife.46323

Examples

data(adaptive)
d <- adaptive[adaptive$SubjID == 1, ]
integration_fixedSSD(d)

Estimate SSRT via the mean method (adaptive SSD design)

Description

Computes SSRT as the difference between mean go RT and mean SSD:

SSRT=RTˉgoSSDˉSSRT = \bar{RT}_{go} - \bar{SSD}

This method is less accurate than the integration method but is included for comparison and historical compatibility.

Usage

mean_adaptiveSSD(
  data,
  stop_col = "vol",
  rt_col = "RT_exp",
  acc_col = "correct",
  ssd_col = "soa",
  min_rt = 50
)

Arguments

data

A data.frame with one row per trial.

stop_col

Column name for the stop-trial indicator (1 = stop, 0 = go). Default "vol".

rt_col

Column name for reaction time in ms. Default "RT_exp".

acc_col

Column name for accuracy (1 = correct). Default "correct".

ssd_col

Column name for stop-signal delay in ms. Default "soa".

min_rt

Minimum valid RT in ms; shorter responses are excluded as anticipations. Default 50.

Value

A single numeric value: the estimated SSRT in milliseconds.

Examples

data(adaptive)
d <- adaptive[adaptive$SubjID == 1, ]
mean_adaptiveSSD(d)

Estimate SSRT via the mean method (fixed SSD design)

Description

Computes SSRT as RTˉgoSSDˉ\bar{RT}_{go} - \bar{SSD}. For multiple fixed SSD values the mean is taken across all stop trials.

Usage

mean_fixedSSD(
  data,
  stop_col = "vol",
  rt_col = "RT_exp",
  acc_col = "correct",
  ssd_col = "soa",
  min_rt = 50
)

Arguments

data

A data.frame with one row per trial.

stop_col

Column name for the stop-trial indicator (1 = stop, 0 = go). Default "vol".

rt_col

Column name for reaction time in ms. Default "RT_exp".

acc_col

Column name for accuracy (1 = correct). Default "correct".

ssd_col

Column name for stop-signal delay in ms. Default "soa".

min_rt

Minimum valid RT in ms; shorter responses are excluded as anticipations. Default 50.

Value

A single numeric value: the estimated SSRT in milliseconds.

Examples

data(adaptive)
d <- adaptive[adaptive$SubjID == 1, ]
mean_fixedSSD(d)

Plots and prints stop-signal delays and accuracies

Description

Plots and prints stop-signal delays and corresponding accuracies. For studies that use fixed (randomly chosen on each trial from a pre-determined set) stop-signal delays.

Usage

plotInhFunc(df, stop_col, ssd_col, acc_col)

Arguments

df

Dataframe with response time, accuracy, indication whether trial is stop or go, and delays for a given trial.

stop_col

Name of the column in the dataframe df that indicates whether a given trial is a "stop" or a "go" trial ( 0 = go, 1 = stop)

ssd_col

Name of the column in the dataframe df that contains stop-signal delays

acc_col

Name of the column in the dataframe df that contains accuracy of inhibition ( 0 = incorrect, 1 = correct)

Value

Line plot of the inhibition function.

Examples

data(fixed)
df <- subset(fixed, new_id == 3)
plotInhFunc(df = df, stop_col='vol', ssd_col='soa', acc_col='acc')

Extract per-group random-effect summaries

Description

A generic function for extracting per-group (e.g. per-subject) parameter summaries from a fitted model. SSRTcalc provides ranef.ssrt_stan for hierarchical Stan fits.

Usage

ranef(object, ...)

Arguments

object

A fitted model object.

...

Additional arguments passed to methods.

Value

A method-specific object (typically a data.frame of per-group summaries).

See Also

ranef.ssrt_stan


Extract per-subject random effects from a hierarchical fit

Description

Extract per-subject random effects from a hierarchical fit

Usage

## S3 method for class 'ssrt_stan'
ranef(object, ...)

Arguments

object

An ssrt_stan object from a hierarchical model.

...

Unused.

Value

data.frame with per-subject posterior summaries.


Run all four Monte Carlo analyses in one call

Description

Run all four Monte Carlo analyses in one call

Usage

run_all_mc(
  data,
  n_iter = 1000,
  seed = 42,
  stop_col = "vol",
  rt_col = "RT_exp",
  acc_col = "correct",
  ssd_col = "soa"
)

Arguments

data

data.frame in SSRTcalc long format.

n_iter

Iterations (shared). Default 1000.

seed

Random seed. Default 42.

stop_col, rt_col, acc_col, ssd_col

Column names.

Value

Named list: bootstrap, simulation, power, robustness.

Examples

## Not run: 
data(adaptive)
d <- adaptive[adaptive$SubjID == 1, ]
res <- run_all_mc(d, n_iter=500)

## End(Not run)

Bootstrap confidence intervals for SSRT

Description

Resamples trials with replacement n_iter times and applies the chosen SSRT estimation function to each resample.

Usage

ssrt_boot(
  data,
  ssrt_fn = "integration_adaptiveSSD",
  n_iter = 2000,
  conf = 0.95,
  stop_col = "vol",
  rt_col = "RT_exp",
  acc_col = "correct",
  ssd_col = "soa",
  seed = 42,
  parallel = FALSE,
  n_cores = 2
)

Arguments

data

data.frame in SSRTcalc long format.

ssrt_fn

SSRT function name. Default "integration_adaptiveSSD".

n_iter

Bootstrap resamples. Default 2000.

conf

Confidence level. Default 0.95.

stop_col, rt_col, acc_col, ssd_col

Column names.

seed

Random seed. Default 42.

parallel

Use parallel::mclapply? (Unix/macOS only). Default FALSE.

n_cores

Cores when parallel=TRUE. Default 2.

Value

Object of class ssrt_boot.

Examples

data(adaptive)
d <- adaptive[adaptive$SubjID == 1, ]
b <- ssrt_boot(d, n_iter = 500)
print(b)

Minimum trial count analysis via Monte Carlo

Description

Simulates datasets of increasing size and computes SSRT variance as a function of trial count (power curve).

Usage

ssrt_power(
  data,
  trial_counts = c(10, 20, 30, 50, 75, 100, 150, 200),
  n_iter = 500,
  target_se = 10,
  stop_col = "vol",
  rt_col = "RT_exp",
  acc_col = "correct",
  ssd_col = "soa",
  seed = 42
)

Arguments

data

data.frame for calibration.

trial_counts

Stop-trial counts to evaluate.

n_iter

MC iterations per count. Default 500.

target_se

Target SE in ms. Default 10.

stop_col, rt_col, acc_col, ssd_col

Column names.

seed

Random seed. Default 42.

Value

Object of class ssrt_power.

Examples

data(adaptive)
d <- adaptive[adaptive$SubjID == 1, ]
p <- ssrt_power(d, trial_counts=c(10,30,50), n_iter=200)
print(p)

Sensitivity of SSRT estimates to horse-race assumption violations

Description

Sweeps three violation types: go/stop process correlation, trigger failure rate, and go-RT shift on stop trials.

Usage

ssrt_robustness(
  data,
  violation = "all",
  n_iter = 500,
  corr_range = seq(0, 0.8, by = 0.1),
  trigger_range = seq(0, 0.4, by = 0.05),
  shift_range = seq(0, 100, by = 10),
  stop_col = "vol",
  rt_col = "RT_exp",
  acc_col = "correct",
  ssd_col = "soa",
  seed = 42
)

Arguments

data

data.frame for calibration.

violation

"all", "correlation", "trigger_failure", or "go_shift".

n_iter

MC iterations per condition. Default 500.

corr_range

Correlations to test.

trigger_range

Trigger failure rates to test.

shift_range

Go-RT shifts in ms to test.

stop_col, rt_col, acc_col, ssd_col

Column names.

seed

Random seed. Default 42.

Value

Object of class ssrt_robustness.

Examples

data(adaptive)
d <- adaptive[adaptive$SubjID == 1, ]
r <- ssrt_robustness(d, violation="trigger_failure", n_iter=100,
                     trigger_range=seq(0, 0.3, 0.1))
print(r)

Parametric Monte Carlo SSRT estimation via ex-Gaussian simulation

Description

Fits an ex-Gaussian to observed go-RT data, simulates synthetic datasets under the horse-race model, and estimates SSRT on each.

Usage

ssrt_simulate(
  data,
  n_iter = 2000,
  n_trials = NULL,
  p_stop = NULL,
  ssrt_true = NULL,
  conf = 0.95,
  stop_col = "vol",
  rt_col = "RT_exp",
  acc_col = "correct",
  ssd_col = "soa",
  seed = 42
)

Arguments

data

data.frame in SSRTcalc long format.

n_iter

MC iterations. Default 2000.

n_trials

Trials per simulated dataset. NULL uses nrow(data).

p_stop

Stop-trial proportion. NULL uses observed proportion.

ssrt_true

Known true SSRT for parameter recovery. Default NULL.

conf

Confidence level. Default 0.95.

stop_col, rt_col, acc_col, ssd_col

Column names.

seed

Random seed. Default 42.

Value

Object of class ssrt_simulate.

Examples

data(adaptive)
d <- adaptive[adaptive$SubjID == 1, ]
s <- ssrt_simulate(d, n_iter=500)
print(s)

Bayesian SSRT estimation via Stan

Description

Fits the independent horse-race model with ex-Gaussian go- and stop-process distributions using Hamiltonian Monte Carlo via Stan. Supports single-subject and multi-subject hierarchical designs, with an optional trigger-failure parameter following Matzke et al. (2013).

Usage

ssrt_stan(
  data,
  model = c("single", "hierarchical"),
  subject_col = NULL,
  trigger_failure = FALSE,
  n_quad = 100,
  chains = 4,
  iter = 2000,
  warmup = 1000,
  cores = 4,
  backend = "auto",
  adapt_delta = 0.95,
  stop_col = "vol",
  rt_col = "RT_exp",
  acc_col = "correct",
  ssd_col = "soa",
  seed = 42,
  ...
)

Arguments

data

data.frame in SSRTcalc long format.

model

"single" (default) or "hierarchical".

subject_col

Column with subject IDs (required for hierarchical).

trigger_failure

Logical: include trigger-failure parameter. Default FALSE.

n_quad

Quadrature resolution for P(inhibit) integral. Default 100.

chains

Number of MCMC chains. Default 4.

iter

Total iterations per chain including warmup. Default 2000.

warmup

Warmup iterations. Default 1000.

cores

Parallel cores. Default 4.

backend

"cmdstanr", "rstan", or "auto".

adapt_delta

HMC target acceptance rate. Increase to 0.99 if divergences appear. Default 0.95.

stop_col, rt_col, acc_col, ssd_col

Column names.

seed

Random seed. Default 42.

...

Additional arguments passed to the Stan sampler.

Value

An object of class ssrt_stan.

References

Matzke, D., et al. (2013). Bayesian parametric estimation of stop-signal reaction time distributions. Journal of Experimental Psychology: General, 142(4), 1047–1073.

Examples

## Not run: 
data(adaptive)
d <- adaptive[adaptive$SubjID == 1, ]
fit <- ssrt_stan(d, chains = 4, iter = 2000)
print(fit)
plot(fit)

# Hierarchical
fit_h <- ssrt_stan(adaptive, model = "hierarchical",
                   subject_col = "SubjID", chains = 4)
ranef(fit_h)

## End(Not run)

Compare base model vs. trigger-failure model

Description

Fits both models and returns side-by-side SSRT posterior summaries.

Usage

ssrt_stan_compare(data, ...)

Arguments

data

data.frame in SSRTcalc long format.

...

Arguments forwarded to ssrt_stan().

Value

Invisibly, a list with base, tf, and comparison.


Posterior inhibition function

Description

Computes P(inhibit | SSD) across a range of SSD values using posterior parameter samples, with a 90

Usage

ssrt_stan_inhibition_fn(
  fit,
  ssd_range = seq(0, 600, by = 10),
  n_draws = 400,
  plot = TRUE
)

Arguments

fit

An ssrt_stan object (single-subject only).

ssd_range

SSD values to evaluate in ms. Default seq(0, 600, 10).

n_draws

Posterior draws to use. Default 400.

plot

Produce the plot? Default TRUE.

Value

Invisibly, a data.frame with columns: ssd, mean, lo90, hi90.


Leave-one-out cross-validation for an ssrt_stan fit

Description

Requires the Stan model to include a log_lik vector in generated quantities. If absent, an informative error explains how to add it.

Usage

ssrt_stan_loo(fit)

Arguments

fit

An ssrt_stan object.

Value

A loo object.


Posterior predictive checks for an ssrt_stan fit

Description

Overlays posterior-predictive RT distributions over observed data.

Usage

ssrt_stan_pp_check(fit, n_samples = 200)

Arguments

fit

An ssrt_stan object (single-subject only).

n_samples

Posterior draws to use. Default 200.

Value

Invisibly, a list with pp_go_rt and pp_ssrt.

Examples

## Not run: 
data(adaptive)
fit <- ssrt_stan(adaptive[adaptive$SubjID == 1, ])
ssrt_stan_pp_check(fit)

## End(Not run)