Learn R Programming

YEAB (version 1.0.6)

bp_opt: Find the best fit for individual trials using optim

Description

Find the best fit for individual trials by minimizing the negative sum of areas between the response rate and the target rate.

Usage

bp_opt(r_times, trial_duration, optim_method = "Brent")

Value

A data frame with the following columns:

  • bp: The breakpoint

  • r1: The response rate before the breakpoint

  • r2: The response rate after the breakpoint

  • d1: The duration of the first state

  • d2: The duration of the second state

Arguments

r_times

Vector of response times

trial_duration

Duration of the trial

optim_method

character, the optimization method to use

Examples

Run this code
data("r_times")
r_times <- r_times[r_times < 60]
bp_from_opt <- bp_opt(r_times, 60)
plot(r_times, seq_along(r_times),
  xlim = c(0, max(r_times)),
  main = "Cummulative Record",
  xlab = "Time (s)",
  ylab = "Cum Resp",
  col = 2, type = "s"
)
abline(v = bp_from_opt$bp)

Run the code above in your browser using DataLab