Learn R Programming

Cumulative History Analysis For Bistable Perception Time Series

A package to compute a cumulative history for time-series of perceptual dominance in bistable displays.

Estimates cumulative history, an estimate of accumulating adaptation/prediction error for the dominant percept, for time-series for continuously viewed bistable perceptual rivalry displays. Computes cumulative history via a homogeneous first order differential process. I.e., it assumes exponential growth/decay of the history as a function of time and perceptually dominant state. Supports Gamma, log normal, and normal distribution families.

If you use the toolbox in your work, please cite Pastukhov, A., (2022). bistablehistory: an R package for history-dependent analysis of perceptual time series. Journal of Open Source Software, 7(70), 3901, https://doi.org/10.21105/joss.03901

Installation

For current stable version use

install.packages("bistablehistory")

The master branch is the development version. To install it please use

library("devtools")
install_github("alexander-pastukhov/bistablehistory", dependencies = TRUE)

Note

This package uses Stan, a "state-of-the-art platform for statistical modeling and high-performance statistical computation". Therefore, it depends on the package rstantools, which in turn depends on the rstan package, which uses the V8 JavaScript library, through the V8 R package.

Therefore, you will need to install the V8 JavaScript library on your system, and it is recommended that you also install the V8 R package beforehand. For detailed instructions, please see https://github.com/jeroen/v8.

You will also need the R package curl, which depends on libcurl-* in various operating systems. Please see the documentation at https://cran.r-project.org/package=curl.

Usage

The main function is fit_cumhist that takes a data frame with time-series as the first argument. Minimally, you need to specify state --- string with the column name that encodes perceptually dominant state --- and either duration (column name with duration of individual dominance phases) or onset (column name with onset times of individual dominance phases). Thus, for a simplest case of a single subject and single run/block measurement with all defaults (gamma distribution, fitted cumulative history time constant but fixed mixed state value and history mixing proportion) the call would be

library(bistablehistory)
data(br_singleblock)
gamma_fit <- fit_cumhist(br_singleblock,
                         state = "State",
                         duration = "Duration")

or, equivalently

library(bistablehistory)
data(br_singleblock)
gamma_fit <- fit_cumhist(br_singleblock,
                         state = "State",
                         onset = "Time")

Now you can look at the fitted value for history time constant via

history_tau(gamma_fit)

and main effect of history for both parameters of gamma distribution

coef(gamma_fit)

For further details please see vignettes on package usage (Usage examples and Cumulative history) and on an example of writing Stan code directly (Writing Stan code).

Copy Link

Version

Install

install.packages('bistablehistory')

Monthly Downloads

225

Version

1.1.2

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Alexander (Sasha) Pastukhov

Last Published

September 13th, 2023

Functions in bistablehistory (1.1.2)

cumhist-class

Class cumhist.
evaluate_history_init

Evaluates validity of initial history values.
evaluate_history_option

Evaluates whether and how to fit a cumulative history parameter.
loo.cumhist

Computes an efficient approximate leave-one-out cross-validation via loo library. It can be used for a model comparison via loo::loo_compare() function.
nc

Necker cube data
extract_replicate_term_to_matrix

Extract a term and replicates it randomN times for each linear model
extract_history_parameter

Extracts a history parameter as a matrix
kde_two_observers

Multirun data for two participants, kinetic-depth effect display
kde

Kinetic-depth effect data
summary.cumhist

Summary for a cumhist object
history_parameter

Extract values of used or fitted history parameter
history_mixed_state

Extract values of used or fitted history parameter mixed_state
extract_history

Computes history for a fitted model
print.cumhist

Prints out cumhist object
predict.cumhist

Computes predicted dominance phase durations using posterior predictive distribution.
predict_history

Computes predicted cumulative history using posterior predictive distribution.
waic.cumhist

Computes widely applicable information criterion (WAIC).
historyef

Extract the history-effects estimates
history_tau

Extract values of used or fitted history parameter tau
fit_cumhist

Fits cumulative history for bistable perceptual rivalry displays.
fixef

Extract the fixed-effects estimates
predict_samples

Computes prediction for a each sample.
preprocess_data

Preprocesses time-series data for fitting
coef.cumhist

Extract Model Coefficients
br_single_subject

Single experimental session for binocular rivalry stimulus
bistablehistory-package

Cumulative History Analysis for Bistable Perception Time Series
compute_history

Computes cumulative history for the time-series
bayes_R2

Computes R-squared using Bayesian R-squared approach.
extract_term_to_matrix

Extracts a term with one column per fixed or random-level into a matrix
check_normal_prior

Checks for validity of values for use as normal distribution parameters.
check_fixed_history_parameter

Evaluates values for a fixed history parameter
br_contrast

Binocular rivalry, variable contrast
br

Binocular rivalry data
fast_history_compute

Computes cumulative history
br_singleblock

Single run for binocular rivalry stimulus