Skip to contents

Categorizes events by relationship to a given stimulus, creating a stimulus index.

Usage

add_stimulus_index(
  df,
  time_of_stim,
  isi,
  sweep_count,
  recovery_stim = NULL,
  add_missing = TRUE
)

Arguments

df

Data Frame or Tibble with the following columns:

  • sweep

  • time_ms

time_of_stim

List, with event times in milliseconds.

isi

Numeric, interstimulus interval in milliseconds.

sweep_count

Numeric, total number of experiment sweeps/trials.

recovery_stim

Numeric, default is NULL. Time of the recovery stimulus in milliseconds, useful in paired-pulse ratio experiments when a recovery stimulus is given to measure the rate of recovery.

add_missing

Logical, default is TRUE. Rows for missing events will be inserted with corresponding sweep and stimulus number.

Value

Data Frame or Tibble with the following columns:

  • stimulus, Factor column with the stimulus index.

  • stim_time, Numeric column with stimulus times.

Details

Determines which events fall within a stimulus window, defined by the interstimulus interval (isi), and adds rows with NA for missing events. The stimulus column can take on several values:

  • Character int, e.g. 1, representing an event occurring within a stimulus window.

  • NA, representing events that do not correspond to a stimulus.

  • Character, r, representing the recovery stimulus. If recovery_stim is not NULL.

Note

Run insert_rows_for_missing_sweeps before this function, as it will only insert NA for missing events on sweep numbers already present the data frame. A check occurs in this function and notifies the user.

Examples

simple_df <- data.frame(
  sweep = as.ordered(rep(1:2, c(1, 2))),
  time_ms = c(405, 405, 415)
)

# add rows for missing events
add_stimulus_index(
  df = simple_df,
  time_of_stim = c(400, 410),
  isi = 10,
  sweep_count = 2,
  recovery_stim = NULL,
  add_missing = TRUE
)
#>   sweep time_ms stimulus stim_times
#> 1     1     405        1        400
#> 2     1      NA        2        410
#> 3     2     405        1        400
#> 4     2     415        2        410