Produces a a rolling time-window based vector of binomial probability and confidence intervals.
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
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-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-04-29 0 0.5 0.182 0.818
#> 5 2001-05-16 1 0.6 0.272 0.857
#> 6 2001-08-11 0 0.5 0.221 0.779
#> 7 2001-10-04 1 0.571 0.289 0.814
#> 8 2002-01-15 0 0.5 0.249 0.751
#> 9 2002-01-21 1 0.556 0.303 0.782
#> 10 2002-01-22 0 0.5 0.269 0.731
#> # ℹ 90 more rows