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)

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

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)
#> # A tibble: 100 × 5
#>    date       value PointEst  Lower Upper
#>    <date>     <int>    <dbl>  <dbl> <dbl>
#>  1 2000-03-08     0    0     0      0.895
#>  2 2000-07-24     0    0     0      0.575
#>  3 2000-09-03     0    0     0      0.474
#>  4 2000-10-29     1    0.25  0.0263 0.644
#>  5 2000-12-02     0    0.2   0.0211 0.565
#>  6 2001-01-16     0    0.167 0.0176 0.502
#>  7 2001-04-28     0    0.143 0.0151 0.452
#>  8 2001-05-10     0    0.125 0.0132 0.411
#>  9 2001-08-21     1    0.222 0.0765 0.496
#> 10 2001-11-06     0    0.2   0.0686 0.459
#> # … with 90 more rows