Skip to contents

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, na.pad = TRUE)

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

na.pad

logical. If `na.pad = TRUE` incomplete windows (duration of the window < `n`) return `NA`. Defatuls to `TRUE`

Value

tibble with binomial point estimate and confidence intervals.

See also

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, na.pad = FALSE)
#> # A tibble: 100 × 5
#>    date       value PointEst  Lower Upper
#>    <date>     <int>    <dbl>  <dbl> <dbl>
#>  1 2000-01-13     0    0     0      0.895
#>  2 2000-05-09     1    0.5   0.0527 0.947
#>  3 2000-07-15     1    0.667 0.254  0.965
#>  4 2001-05-16     1    0.75  0.356  0.974
#>  5 2001-08-11     1    0.8   0.435  0.979
#>  6 2001-10-04     0    0.667 0.347  0.883
#>  7 2002-01-15     0    0.571 0.289  0.814
#>  8 2002-01-21     1    0.625 0.348  0.839
#>  9 2002-01-22     0    0.556 0.303  0.782
#> 10 2002-02-11     1    0.6   0.352  0.806
#> # ℹ 90 more rows