This uses a generalised linear model to fit a quasi-binomial model with a time
varying rate as a natural cubic spline with approx one degree of freedom per
window
units of the time series.
Usage
proportion_glm_model(
d = i_proportion_input,
...,
window = 14,
frequency = "1 day",
.progress = interactive()
)
Arguments
- d
Proportion model input - a dataframe with columns:
denom (positive_integer) - Total test counts associated with the specified time frame
count (positive_integer) - Positive case counts associated with the specified time frame
time (ggoutbreak::time_period + group_unique) - A (usually complete) set of singular observations per unit time as a `time_period`
Ungrouped.
- ...
not used and present to allow proportion model to be used in a
group_modify
- window
a number of data points defining the bandwidth of the estimate, smaller values result in less smoothing, large value in more. The default value of 14 is calibrated for data provided on a daily frequency, with weekly data a lower value may be preferred. - default
14
- frequency
the density of the output estimates as a time period such as
7 days
or2 weeks
. - default1 day
- .progress
show a CLI progress bar
Value
A dataframe containing the following columns:
time (ggoutbreak::time_period + group_unique) - A (usually complete) set of singular observations per unit time as a
time_period
proportion.fit (double) - an estimate of the proportion on a logit scale
proportion.se.fit (positive_double) - the standard error of proportion estimate on a logit scale
proportion.0.025 (proportion) - lower confidence limit of proportion (true scale)
proportion.0.5 (proportion) - median estimate of proportion (true scale)
proportion.0.975 (proportion) - upper confidence limit of proportion (true scale)
Any grouping allowed.
Examples
ggoutbreak::england_covid_proportion %>%
dplyr::filter(date < "2021-01-01") %>%
time_aggregate() %>%
ggoutbreak::proportion_glm_model(window=5) %>%
dplyr::glimpse()
#> Rows: 209
#> Columns: 10
#> $ time <time_prd> 22.57143, 22.71429, 22.85714, 23.00000, 23.1428…
#> $ proportion.fit <dbl> -4.145353, -4.168497, -4.191602, -4.214647, -4.23761…
#> $ proportion.se.fit <dbl> 0.4084512, 0.3869179, 0.3665636, 0.3475906, 0.330209…
#> $ proportion.0.025 <dbl> 0.007062264, 0.007197185, 0.007318146, 0.007421591, …
#> $ proportion.0.05 <dbl> 0.008024531, 0.008122834, 0.008206851, 0.008273554, …
#> $ proportion.0.25 <dbl> 0.011881163, 0.011780385, 0.011671731, 0.011554098, …
#> $ proportion.0.5 <dbl> 0.015590924, 0.015239662, 0.014896774, 0.014562335, …
#> $ proportion.0.75 <dbl> 0.02043506, 0.01969450, 0.01899581, 0.01833927, 0.01…
#> $ proportion.0.95 <dbl> 0.03007542, 0.02841329, 0.02689221, 0.02550831, 0.02…
#> $ proportion.0.975 <dbl> 0.03406576, 0.03197970, 0.03008592, 0.02837718, 0.02…
# TODO: deal with error conditions
# "observations with zero weight not used for calculating dispersion