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 |
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.
data(Dissolved_Oxygen)
data(Dissolved_Oxygen)
A data frame with 236 rows and 6 variables:
unique water quality monitoring station identifier
sampling date in yyyy-mm-dd format
unique parameter code
parameter description with units
mean of dissolved oxygen measurement, in mg/L
minimum of dissolved oxygen measurement, in mg/L
https://www80.tceq.texas.gov/SwqmisPublic/public/default.htm
Produces a a rolling time-window based vector of binomial probability and confidence intervals.
tbr_binom(.tbl, x, tcolumn, unit = "years", n, alpha = 0.05)
tbr_binom(.tbl, x, tcolumn, unit = "years", n, alpha = 0.05)
.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 |
tibble with binomial point estimate and confidence intervals.
## 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)
## 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)
Produces a a rolling time-window based vector of geometric means and confidence intervals.
tbr_gmean(.tbl, x, tcolumn, unit = "years", n, ...)
tbr_gmean(.tbl, x, tcolumn, unit = "years", n, ...)
.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 |
tibble with columns for the rolling geometric mean and upper and lower confidence levels.
## 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)
## 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)
Produces a a rolling time-window based vector of means and confidence intervals.
tbr_mean(.tbl, x, tcolumn, unit = "years", n, ...)
tbr_mean(.tbl, x, tcolumn, unit = "years", n, ...)
.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 |
tibble with columns for the rolling mean and upper and lower confidence intervals.
## 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)
## 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)
Produces a a rolling time-window based vector of medians and confidence intervals.
tbr_median(.tbl, x, tcolumn, unit = "years", n, ...)
tbr_median(.tbl, x, tcolumn, unit = "years", n, ...)
.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 |
tibble with columns for the rolling median and upper and lower confidence intervals.
## 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)
## 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
tbr_misc(.tbl, x, tcolumn, unit = "years", n, func, ...)
tbr_misc(.tbl, x, tcolumn, unit = "years", n, func, ...)
.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 |
tibble
tbr_misc(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years", n = 5, func = mean)
tbr_misc(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years", n = 5, func = mean)
Time-Based Rolling Standard Deviation
tbr_sd(.tbl, x, tcolumn, unit = "years", n, na.rm = FALSE)
tbr_sd(.tbl, x, tcolumn, unit = "years", n, na.rm = FALSE)
.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? |
tibble with column for the rolling sd.
tbr_sd(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years", n = 5)
tbr_sd(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years", n = 5)
Time-Based Rolling Sum
tbr_sum(.tbl, x, tcolumn, unit = "years", n, na.rm = FALSE)
tbr_sum(.tbl, x, tcolumn, unit = "years", n, na.rm = FALSE)
.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? |
dataframe with column for the rolling sum.
tbr_sum(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years", n = 5)
tbr_sum(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years", n = 5)