Skip to contents

This function calculates the slopes (rate of change) between consecutive data points in a melatonin profile based on melatonin concentrations and their corresponding time points.

Usage

calculate_slopes(profile, decimal_time)

Arguments

profile

Numeric vector representing melatonin concentrations at each time point.

decimal_time

Numeric vector representing the time points in decimal format (e.g., fractional hours or days).

Value

A numeric vector of slopes calculated as the change in melatonin concentration divided by the change in time between consecutive points.

Details

The function sorts the input data by time to ensure proper calculation of slopes. The slopes are computed as: $$slope = (profile[i+1] - profile[i]) / (decimal_time[i+1] - decimal_time[i])$$.

Examples

profile <- c(1.2, 1.4, 1.5, 1.7, 2.0)
decimal_time <- c(0, 0.25, 0.5, 0.75, 1)  # Time in fractional hours
slopes <- calculate_slopes(profile, decimal_time)
print(slopes)
#> [1] 0.8 0.4 0.8 1.2