# curv_indexes()

## Introduction

In fixed interval schedules (FI), subjects receive reinforcement only for the first response that occurs after a specific amount of time has elapsed (the fixed interval). Responses happening before the interval ends are recorded but have no consequence. Fixed-interval schedules are known to produce characteristic response patterns. These patterns typically involve an initial pause at the beginning of each interval, followed by a period of increasing responding that reaches a high and steady rate until reinforcement is delivered.

Curvature analysis provides a quantitative measure to characterize how responding deviates from an ideal increasingly steady rate. This information is valuable for understanding how different factors, such as drugs or manipulations of the reinforcement schedule itself, can influence response patterning. The curvature index can reveal deviations from a steady responding rate and help identify how different factors influence response patterning.

Here we introduce two functions for calculating the curvature index, one based on numerical integration and another using Fry’s derivation. The first, named `curv_index_int` takes the following parameters:

- `cr` a numeric vector representing the cumulative response data.
- `t` a numeric vector representing time points corresponding to the x-axis in a cumulative response distribution.

The second, named `curv_index_fry` takes the following parameters:

- `cr` a numeric vector of cumulative response.
- `time_in` a numeric vector of the response times.
- `if_val` a numeric value for the base of the triangle (e.g., FI value or the last time value).
- `n` the number of sub-intervals to divide the area under the curve by (4 by default).

Both functions return a numeric value for the curvature index.

## Example

First let’s load an example data set from an experimental trial and create the data points for the cumulative response vector:

    data("r_times")
    r_times <- r_times[r_times < 60] # This example is a Peak Procedure trial, so we keep only the responses up to the FI value of 60s.

    head(r_times, n = 30)

    ##  [1] 28.1 40.7 44.2 44.4 44.7 45.0 45.4 47.9 48.1 48.3 48.6 48.8 49.8 50.2 50.7
    ## [16] 51.2 51.4 51.7 51.9 52.7 53.0 53.5 53.7 53.9 54.1 54.3 54.9 55.3 55.5 55.7

    cr <- seq_along(r_times) # The Cumulative Response from 1 to n data points.

    cr

    ##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
    ## [26] 26 27 28 29 30 31 32 33 34 35 36 37

Now let’s calculate the curvature index using both methods for comparison purposes:

    int_index <- curv_index_int(cr, r_times)
    fry_index <- curv_index_fry(cr, r_times, 60)

Note that for the `curv_index_fry` function we omitted the `n` parameter, using the default subdivision value of 4.

    ## [1] "Numerical integration index:  0.501803743737452"

    ## [1] "Fry's integration index:  0.655405405405405"