time_weights {FAVA} | R Documentation |
Compute a normalized weighting vector based on a vector of sampling times.
Description
This function takes a vector of sampling times, t = (t_1, t_2, \ldots, t_I)
and computes a normalized vector which can be used to weight each sample based on
the time between the subsequent and the preceding samples. The weighting vector w
is defined such that each entry, w_i = d_i / 2T
, where T=t_I - t_1
and
d_i = t_{i+1} - t_{i-1}
for i
not equal to 1 or I. d_1 = t_2-t_1
and d_I = t_I-t_{I-1}
.
Usage
time_weights(times, group = NULL)
Arguments
times |
A numeric vector of sampling times. Each entry must be greater than the previous entry. |
group |
Optional; a character vector specifying the group identity of each sampling time. Use if there are samples from multiple replicates or subjects in one dataset. |
Value
A numeric vector. Each entry provides a weight for each entry in the
provided times
vector. If group
is not specified, the vector sums to 1. If
group
is specified, the vector sums to the number of distinct groups.
Examples
time_vector = c(1, 8, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 44, 50, 57, 64)
time_weights(times = time_vector)