Learn R Programming

tbrf

tbrf is retired. I will maintain the package to ensure it remains on CRAN but do not expect additional functionality or improvements. I highly recommend runner for the same functionality but faster!

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. Although 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 variable with the result of the rolling statistical measure.

Installation

tbrf is available on CRAN:

install.packages("tbrf")

The development version is available on r-universe and can be installed as:

install.packages('tbrf', repos = c('https://mps9506.r-universe.dev', 'https://cloud.r-project.org'))

Available Functions

  • tbr_binom: Rolling binomial probability with confidence intervals.

  • tbr_gmean: Rolling geometric mean with confidence intervals.

  • tbr_mean: Rolling mean with confidence intervals.

  • tbr_median: Rolling median with confidence intervals.

  • tbr_misc: Accepts user specified function.

  • tbr_sd: Rolling standard deviation.

  • tbr_sum: Rolling sum.

Usage

See:

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

Example

Plot a rolling 1-hour mean:

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

y = 3 * sin(2 * seq(from = 0, to = 4*pi, length.out = 100)) + rnorm(100)
time = sample(seq(as.POSIXct(strptime("2017-01-01 00:01:00", "%Y-%m-%d %H:%M:%S")),
                  as.POSIXct(strptime("2017-01-01 23:00:00", "%Y-%m-%d %H:%M:%S")),
                  by = "min"), 100)

df <- tibble(y, time)

df %>%
  tbr_mean(y, time, "hours", n = 1) %>%
  ggplot() +
  geom_point(aes(time, y)) +
  geom_step(aes(time, mean))

Plot a rolling 3-hour mean:

df %>%
  tbr_mean(y, time, "hours", n = 3) %>%
  ggplot() +
  geom_point(aes(time, y)) +
  geom_step(aes(time, mean))

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.

stat_stepribbon() is an implementation of code licensed under MIT by Bob Rudis’s ggalt package.

If you can cite the use of this software, please use citation("tbrf") .

Test Results

library(tbrf)

date()
## [1] "Tue Aug 19 13:32:27 2025"

devtools::test()
## ✔ | F W  S  OK | Context
## 
## ⠏ |          0 | expectedClass                                                  
## ⠏ |          0 | core functions work in piped workflow                          
## ⠙ |          2 | core functions work in piped workflow                          
## ✔ |          6 | core functions work in piped workflow
## 
## ⠏ |          0 | expectedMessages                                               
## ⠏ |          0 | core functions return expected errors and messages             
## ⠹ |          3 | core functions return expected errors and messages             
## ⠴ |          6 | core functions return expected errors and messages             
## ✔ |          7 | core functions return expected errors and messages
## 
## ⠏ |          0 | expectedValues                                                 
## ⠏ |          0 | core functions return expected structures and values           
## ⠹ |          3 | core functions return expected structures and values           
## ⠼ |          5 | core functions return expected structures and values           
## ⠴ |          6 | core functions return expected structures and values           
## ✔ |          6 | core functions return expected structures and values
## 
## ⠏ |          0 | internalStatsFunctions                                         
## ⠏ |          0 | internal statistical functions return expected values          
## ⠼ |          5 | internal statistical functions return expected values          
## ✔ |         17 | internal statistical functions return expected values
## 
## ══ Results ═════════════════════════════════════════════════════════════════════
## Duration: 1.4 s
## 
## [ FAIL 0 | WARN 0 | SKIP 0 | PASS 36 ]

Copy Link

Version

Install

install.packages('tbrf')

Monthly Downloads

389

Version

0.1.7

License

GPL-3 | file LICENSE

Maintainer

Michael Schramm

Last Published

August 19th, 2025

Functions in tbrf (0.1.7)

tbr_sd_window

Standard Deviation Based on a Time-Window
tbrf

Time-Based Rolling Functions
tbr_sum

Time-Based Rolling Sum
tbrf-ggproto

tbrf extensions to ggplot2
tbr_sum_window

Sum Based on a Time-Window
mean_ci

Returns the mean and CI
gm_mean

Calculates the Geometric Mean
stat_stepribbon

Step ribbon statistic
Dissolved_Oxygen

Dissolved oxygen measurements from the Tres Palacios River
gm_mean_ci

Returns the Geomean and CI
open_window

Open Window
Entero

Enterococci bacteria measurements from the Tres Palacios River
binom_ci

Confidence Intervals for Binomial Probabilities
median_ci

Returns the median and CI
list_NA

List NA
tbr_gmean_window

Geometric mean based on a time-window
tbr_sd

Time-Based Rolling Standard Deviation
tbr_binom

Time-Based Rolling Binomial Probability
tbr_median

Time-Based Rolling Median
tbr_misc

Use Generic Functions with Time Windows
tbr_gmean

Time-Based Rolling Geometric Mean
tbr_median_window

Median Based on a Time-Window
tbr_binom_window

Binomial test based on time window
tbr_mean_window

Mean Based on a Time-Window
tbr_mean

Time-Based Rolling Mean