Package 'tbrf'

Title: Time-Based Rolling Functions
Description: Provides rolling statistical functions based on date and time windows instead of n-lagged observations.
Authors: Michael Schramm [aut, cre] , Frank Harrell [ctb]
Maintainer: Michael Schramm <[email protected]>
License: GPL-3 | file LICENSE
Version: 0.1.5.9000
Built: 2024-10-29 04:17:57 UTC
Source: https://github.com/mps9506/tbrf

Help Index


Dissolved oxygen measurements from the Tres Palacios rivers

Description

Data from the Texas Commission on Environmental Quality Surface Water Quality Monitoring Information System. The 'AverageDO“ field is the mean of dissolved oxygen concentrations (mg/L) measured at a field site at that day. The MinDO is the minimum dissolved oxygen concentration measured at that site on that day.

Usage

data(Dissolved_Oxygen)

Format

A data frame with 236 rows and 6 variables:

Station_ID

unique water quality monitoring station identifier

Date

sampling date in yyyy-mm-dd format

Param_Code

unique parameter code

Param_Desc

parameter description with units

Average_DO

mean of dissolved oxygen measurement, in mg/L

Min_DO

minimum of dissolved oxygen measurement, in mg/L

Source

https://www80.tceq.texas.gov/SwqmisPublic/public/default.htm


Time-Based Rolling Binomial Probability

Description

Produces a a rolling time-window based vector of binomial probability and confidence intervals.

Usage

tbr_binom(.tbl, x, tcolumn, unit = "years", n, alpha = 0.05)

Arguments

.tbl

dataframe with two variables.

x

indicates the variable column containing "success" and "failure" observations coded as 1 or 0.

tcolumn

indicates the variable column containing Date or Date-Time values.

unit

character, one of "years", "months", "weeks", "days", "hours", "minutes", "seconds"

n

numeric, describing the length of the time window in the selected units.

alpha

numeric, probability of a type 1 error, so confidence coefficient = 1-alpha

Value

tibble with binomial point estimate and confidence intervals.

See Also

binom_ci

Examples

## Generate Sample Data
df <- tibble::tibble(
date = sample(seq(as.Date('2000-01-01'), as.Date('2015/12/30'), by = "day"), 100),
value = rbinom(100, 1, 0.25)
)

## Run Function
tbr_binom(df, x = value,
tcolumn = date, unit = "years", n = 5,
alpha = 0.1)

Time-Based Rolling Geometric Mean

Description

Produces a a rolling time-window based vector of geometric means and confidence intervals.

Usage

tbr_gmean(.tbl, x, tcolumn, unit = "years", n, ...)

Arguments

.tbl

a data frame with at least two variables; time column formatted as date, date/time and value column.

x

column containing the values to calculate the geometric mean.

tcolumn

formatted time column.

unit

character, one of "years", "months", "weeks", "days", "hours", "minutes", "seconds"

n

numeric, describing the length of the time window.

...

additional arguments passed to gm_mean_ci

Value

tibble with columns for the rolling geometric mean and upper and lower confidence levels.

See Also

gm_mean_ci

Examples

## Return a tibble with new rolling geometric mean column
tbr_gmean(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years", n = 5)

## Not run: 
## Return a tibble with rolling geometric mean and 95% CI
tbr_gmean(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years", n = 5, conf = .95)
## End(Not run)

Time-Based Rolling Mean

Description

Produces a a rolling time-window based vector of means and confidence intervals.

Usage

tbr_mean(.tbl, x, tcolumn, unit = "years", n, ...)

Arguments

.tbl

a data frame with at least two variables; time column formatted as date, date/time and value column.

x

column containing the numeric values to calculate the mean.

tcolumn

formatted time column.

unit

character, one of "years", "months", "weeks", "days", "hours", "minutes", "seconds"

n

numeric, describing the length of the time window.

...

additional arguments passed to mean_ci.

Value

tibble with columns for the rolling mean and upper and lower confidence intervals.

See Also

mean_ci

Examples

## Return a tibble with new rolling mean column
tbr_mean(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years", n = 5)

## Not run: 
## Return a tibble with rolling mean and 95% CI
tbr_mean(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years", n = 5, conf = .95)
## End(Not run)

Time-Based Rolling Median

Description

Produces a a rolling time-window based vector of medians and confidence intervals.

Usage

tbr_median(.tbl, x, tcolumn, unit = "years", n, ...)

Arguments

.tbl

a data frame with at least two variables; time column formatted as date, date/time and value column.

x

column containing the numeric values to calculate the mean.

tcolumn

formatted time column.

unit

character, one of "years", "months", "weeks", "days", "hours", "minutes", "seconds"

n

numeric, describing the length of the time window.

...

additional arguments passed to median_ci

Value

tibble with columns for the rolling median and upper and lower confidence intervals.

See Also

median_ci

Examples

## Return a tibble with new rolling median column
tbr_median(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years",
n = 5)

## Not run: 
## Return a tibble with rolling median and 95% CI 
tbr_median(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years", n = 5, conf = .95)
## End(Not run)

Use Generic Functions with Time Windows

Description

Use Generic Functions with Time Windows

Usage

tbr_misc(.tbl, x, tcolumn, unit = "years", n, func, ...)

Arguments

.tbl

a data frame with at least two variables; time column formatted as date, date/time and value column.

x

column containing the values the function is applied to.

tcolumn

formatted time column.

unit

character, one of "years", "months", "weeks", "days", "hours", "minutes", "seconds"

n

numeric, describing the length of the time window.

func

specified function

...

optional additional arguments passed to function func

Value

tibble

Examples

tbr_misc(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years", n = 5, func = mean)

Time-Based Rolling Standard Deviation

Description

Time-Based Rolling Standard Deviation

Usage

tbr_sd(.tbl, x, tcolumn, unit = "years", n, na.rm = FALSE)

Arguments

.tbl

a data frame with at least two variables; time column formatted as date, date/time and value column.

x

column containing the values to calculate the standard deviation.

tcolumn

formatted time column.

unit

character, one of "years", "months", "weeks", "days", "hours", "minutes", "seconds"

n

numeric, describing the length of the time window.

na.rm

logical. Should missing values be removed?

Value

tibble with column for the rolling sd.

See Also

sd

Examples

tbr_sd(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years", n = 5)

Time-Based Rolling Sum

Description

Time-Based Rolling Sum

Usage

tbr_sum(.tbl, x, tcolumn, unit = "years", n, na.rm = FALSE)

Arguments

.tbl

a data frame with at least two variables; time column formatted as date, date/time and value column.

x

column containing the values to calculate the sum.

tcolumn

formatted time column.

unit

character, one of "years", "months", "weeks", "days", "hours", "minutes", "seconds"

n

numeric, describing the length of the time window.

na.rm

logical. Should missing values be removed?

Value

dataframe with column for the rolling sum.

See Also

sum

Examples

tbr_sum(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years", n =
5)