Skip to contents

Create an approximate confidence band for the Rt or incidence estimate. Note that the variance computation is approximate.

Usage

confband(object, lambda, level = 0.95, type = c("Rt", "Yt"), ...)

Arguments

object

a poisson_rt or cv_poisson_rt object.

lambda

the selected lambda. May be a scalar value, or in the case of cv_poisson_rt objects, "lambda.min" or "lambda.max".

level

the desired confidence level(s). These will be sorted if necessary.

type

the type Rt or Yt for confidence intervals of fitted Rt or fitted incident cases

...

additional arguments for methods. Unused.

Value

A data.frame containing the estimates Rt or Yt at the chosen lambda, and confidence limits corresponding to level

Examples

y <- c(1, rpois(100, dnorm(1:100, 50, 15) * 500 + 1))
out <- estimate_rt(y, nsol = 10)
head(confband(out, out$lambda[2]))
#> An `rt_confidence_band` object.
#> 
#> * type = Rt 
#> * lambda = 110.771 
#> * degrees of freedom = 4 
#> 
#> # A tibble: 6 × 3
#>     fit  `2.5%` `97.5%`
#>   <dbl>   <dbl>   <dbl>
#> 1 0.783 NaN      NaN   
#> 2 0.833   0.215    1.45
#> 3 0.884   0        1.92
#> 4 0.934   0        1.98
#> 5 0.984   0.145    1.82
#> 6 1.03    0.204    1.86
head(confband(out, out$lambda[2], level = c(0.95, 0.8, 0.5)))
#> An `rt_confidence_band` object.
#> 
#> * type = Rt 
#> * lambda = 110.771 
#> * degrees of freedom = 4 
#> 
#> # A tibble: 6 × 7
#>     fit  `2.5%` `10.0%` `25.0%` `75.0%` `90.0%` `97.5%`
#>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
#> 1 0.783 NaN     NaN     NaN      NaN     NaN     NaN   
#> 2 0.833   0.215   0.431   0.622    1.04    1.24    1.45
#> 3 0.884   0       0.213   0.532    1.24    1.55    1.92
#> 4 0.934   0       0.256   0.579    1.29    1.61    1.98
#> 5 0.984   0.145   0.439   0.698    1.27    1.53    1.82
#> 6 1.03    0.204   0.494   0.750    1.32    1.57    1.86

cv <- cv_estimate_rt(y, nfold = 3, nsol = 30)
head(confband(cv, "lambda.min", c(0.5, 0.9)))
#> An `rt_confidence_band` object.
#> 
#> * type = Rt 
#> * lambda = 163.308 
#> * degrees of freedom = 4 
#> 
#> # A tibble: 6 × 5
#>     fit     `5%`   `25%`  `75%`  `95%`
#>   <dbl>    <dbl>   <dbl>  <dbl>  <dbl>
#> 1 0.777 NaN      NaN     NaN    NaN   
#> 2 0.830   0.338    0.629   1.03   1.32
#> 3 0.884   0.0402   0.540   1.23   1.73
#> 4 0.938   0.0697   0.584   1.29   1.81
#> 5 0.991   0.294    0.707   1.28   1.69
#> 6 1.04    0.362    0.766   1.32   1.73