downsample_digital_timeseries: This function downsamples a vector of integers by keeping the...

View source: R/RcppExports.R

downsample_digital_timeseriesR Documentation

This function downsamples a vector of integers by keeping the mode within each resampled chunk.

Description

When downsampling integers, it is difficult to decide on what value should be retained since simpler subsampling approaches may retain a digital value that is not representative of the local neighborhood of the vector. This is less of a problem for downsampling of analog channels where we assume relative continuity across values.

Here, we have adopted the approach of downsampling integers by retaining the most common intger value within each subset of the vector. For example, if the vector is of length 100 and we are downsampling 10x, then the function will look within each set of 10 integers and retain the most common value in each.

Arguments

x

A vector of integer values to be downsampled by retaining the mode in each chunk

downsamp

The factor by which data are downsampled (e.g., 3 will reduce the resulting vector 3x)

demote_zeros

Logical indicating whether to prefer non-zero modes, even if they are no more likely in a chunk

Details

Note that this function does not allow for multiple modes. If there are multiple modes, it always retains the mode with the lowest integer value in each chunk. The exception is if demote_zeros is TRUE. In this case, even if there is one non-zero value in a chunk, it will trump any number of zeros. This is helpful for TTL codes where a code may be on for part of the higher-frequency time series and we don't want it to become zero in the downsampled data.

Value

A vector of length ceiling(length(x)/downsamp) with downsampled integers

Author(s)

Michael Hallquist


PennStateDEPENdLab/experiment_pipeline documentation built on Nov. 27, 2024, 4:56 a.m.