calc_rolling_stats: Calculate rolling window statistics

Description Usage Arguments Value Examples

View source: R/rolling_window.R

Description

Calculate rolling window statistics for multiple combinations of statistics, variables, rolling window widths, and detrending options.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
calc_rolling_stats(
  data,
  var_cols,
  id_cols = c("Lake", "Year"),
  time_col = "DOY",
  statistics = c("Mean", "SD", "SD_sd", "Ar1", "Ar1_sd"),
  vars_to_log = NULL,
  log_offset = 0.1,
  widths = c(21),
  detrend = FALSE,
  min_prop = 0.99
)

Arguments

data

data frame containing time series to calculate rolling window stats on

var_cols

character vector, variable names that are columns of *data* containing time series to calculate rolling window stats on

id_cols

character vector, two columns specifying "groups" to separate data into before calculating stats independently on, defaults are "Lake" and "Year"

time_col

character, column name that defines time step of data within the *id_cols* groupings

statistics

character vector, rolling window statistics to calculate, defaults to all available: c("Mean", "SD", "SD_sd", "Ar1", "Ar1_sd")

vars_to_log

character vector, optional variables names to log10 transform and create new columns before calculating rolling window stats

log_offset

positive numeric value, if any variables are being log transformed that contain negative values, all values will be shifted so that the minimum (before transformation) equals this value

widths

numeric vector, rolling window width(s) to be used, default is c(21)

detrend

TRUE or FALSE, should data within rolling windows be linearly detrended before calculating *statistics*

min_prop

numeric value between 0 and 1, proportion of data within a rolling window to calculate rolling window statistic, default 0.99

Value

a data frame with the results for the specified stats, widths, variables, etc.

Examples

1
rw_stats <- calc_rolling_stats(data = ts_data, var_cols = c("DO_Sat"))

cbuelo/tvsews documentation built on Jan. 21, 2022, 1:31 a.m.