tbrf

Travis build status AppVeyor build status Coverage status

License: GPL v3

The goal of tbrf is to provide time-window based rolling statistical functions. The package differs from other rolling statistic packages because the intended use is for irregular measured data. Althogh tbrf can be used to apply statistical functions to regularly sampled data, zoo, RcppRoll, and other packages provide fast, efficient, and rich implementations of rolling/windowed functions.

An appropriate example case is water quality data that is measured at irregular time intervals. Regulatory compliance is often based on a statistical average measure or exceedance probability applied to all samples collected in the previous 7-years. tbrf can be used to display regulatory status at any sample point.

tbrf identifies the previous n measurements within the specified time window, applies the function, and outputs a varaible with the result of the rolling statistical measure.

Installation

tbrf is still under active development (do not expect stable behavior) and can be installed from github with:

devtools::install.github("mps9506/tbrf")

Available Functions

Usage

See:

https://mps9506.github.io/tbrf/

Example

Plot a rolling 6-hour geometric mean

library(tbrf)
library(dplyr)
library(ggplot2)
library(ggalt)

y <- -100*log(runif(50))
time = sample(seq(as.POSIXct(strptime("2017-01-01 00:01:00", "%Y-%m-%d %H:%M:%S")),
                  as.POSIXct(strptime("2017-01-03 23:00:00", "%Y-%m-%d %H:%M:%S")),
                  by = "min"), 50)

df <- data_frame(time, y)

df %>% 
  tbr_gmean(y, time, unit = "hours", n = 6, conf = 0.95) %>%
  ggplot() +
  geom_point(aes(time, y)) +
  geom_step(aes(time, mean)) +
  geom_ribbon(aes(time, ymin = lwr_ci, ymax = upr_ci), alpha = 0.5, stat = "stepribbon")

Contributing

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

License

tbrf code is released under GPL-3 | LICENSE.md

binom_ci() is an implementation of code licensed under GPL (>=2) by Frank Harrell’s Hmisc package.

Test Results

library(tbrf)

date()
## [1] "Thu Aug 30 18:24:59 2018"

devtools::test()
## v | OK F W S | Context
## 
/ |  0       | core functions work in piped workflow
- |  1       | core functions work in piped workflow
\ |  2       | core functions work in piped workflow
| |  3       | core functions work in piped workflow
/ |  4       | core functions work in piped workflow
- |  5       | core functions work in piped workflow
\ |  6       | core functions work in piped workflow
v |  6       | core functions work in piped workflow [0.4 s]
## 
/ |  0       | core functions return expected errors and messages
- |  1       | core functions return expected errors and messages
\ |  2       | core functions return expected errors and messages
| |  3       | core functions return expected errors and messages
/ |  4       | core functions return expected errors and messages
- |  5       | core functions return expected errors and messages
\ |  6       | core functions return expected errors and messages
| |  7       | core functions return expected errors and messages
v |  7       | core functions return expected errors and messages
## 
/ |  0       | core functions return expected structures and values
- |  1       | core functions return expected structures and values
\ |  2       | core functions return expected structures and values
| |  3       | core functions return expected structures and values
/ |  4       | core functions return expected structures and values
- |  5       | core functions return expected structures and values
\ |  6       | core functions return expected structures and values
| |  7       | core functions return expected structures and values
/ |  8       | core functions return expected structures and values
v |  8       | core functions return expected structures and values [1.1 s]
## 
/ |  0       | internal statistical functions return expected values
- |  1       | internal statistical functions return expected values
\ |  2       | internal statistical functions return expected values
| |  3       | internal statistical functions return expected values
/ |  4       | internal statistical functions return expected values
- |  5       | internal statistical functions return expected values
\ |  6       | internal statistical functions return expected values
| |  7       | internal statistical functions return expected values
/ |  8       | internal statistical functions return expected values
- |  9       | internal statistical functions return expected values
\ | 10       | internal statistical functions return expected values
| | 11       | internal statistical functions return expected values
v | 11       | internal statistical functions return expected values [0.5 s]
## 
## == Results =================================================================================================
## Duration: 2.1 s
## 
## OK:       32
## Failed:   0
## Warnings: 0
## Skipped:  0