Skip to contents

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)
#>  [1] 0.05555556 0.16666667 0.11904762 0.01587302 0.01587302 0.01587302
#>  [7] 0.01587302 0.01587302 0.01587302 0.01587302 0.01587302 0.01587302
#> [13] 0.01587302 0.01587302 0.01587302 0.01587302 0.01587302 0.01587302
#> [19] 0.01587302 0.04761905 0.08730159 0.10317460 0.11111111 0.05555556