A binomial proportion estimate and associated exponential growth rate
Source:R/estimator-locfit.R
proportion_locfit_model.Rd
takes a list of times, counts and a denominator and fits a quasi-binomial model
using a logit link function to proportion data using local regression
using the package locfit
.
Usage
proportion_locfit_model(
d = i_proportion_input,
...,
window = 14,
deg = 1,
frequency = "1 day",
predict = TRUE
)
Arguments
- d
the input
A dataframe containing the following columns:
denom (positive_integer) - Total test counts associated with the specified timeframe
count (positive_integer) - Positive case counts associated with the specified timeframe
time (as.time_period + group_unique) - A (usually complete) set of singular observations per unit time as a `time_period`
Ungrouped.
No default value.
- ...
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. - (defaults to
14
)- deg
polynomial degree (min 1) - higher degree results in less smoothing, lower values result in more smoothing. A degree of 1 is fitting a linear model piece wise. - (defaults to
1
)- frequency
the density of the output estimates as a time period such as
7 days
or2 weeks
. - (defaults to"1 day"
)- predict
result is a prediction dataframe. If false we return the
locfit
models (advanced). - (defaults toTRUE
)
Value
A dataframe containing the following columns:
time (as.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 (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)
relative.growth.fit (double) - an estimate of the relative growth rate
relative.growth.se.fit (double) - the standard error the relative growth rate
relative.growth.0.025 (double) - lower confidence limit of the relative growth rate
relative.growth.0.5 (double) - median estimate of the relative growth rate
relative.growth.0.975 (double) - upper confidence limit of the relative growth rate
No mandatory groupings.
No default value.
Details
This expects d to contain one combination of:
time
andcount
anddenom
columns - e.g. all tests conducted.
This results is a one versus others comparison binomial proportion estimate plus a relative growth rate estimate specifying how much quicker this is growing compared to the growth of the denominator.
The denominator maybe the sum of all subgroups denom = sum(count)
, e.g. in the situation where
there are multiple variants of a disease circulating. In which case the
relative growth is that of the subgroup compared to the overall. You can
make this a one-versus-others comparison by making the denominator exclude the
current item (e.g. denom = sum(count)-count
).
The denominator can also be used to express the size of the population tested. This gives us a relative growth rate that is different in essence to the previous and may be a better estimate of the true growth rate in the situation where testing effort is variable, or capacity saturated.
Examples
growthrates::england_covid %>%
growthrates::proportion_locfit_model(window=21) %>%
dplyr::glimpse()
#> Rows: 26,790
#> Columns: 12
#> Groups: class [19]
#> $ class <fct> 00_04, 00_04, 00_04, 00_04, 00_04, 00_04, 00_04…
#> $ time <time_prd> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, …
#> $ proportion.fit <dbl> -13.433629, -13.178345, -12.898497, -12.600007,…
#> $ proportion.se.fit <dbl> 51.598289, 49.954079, 48.024633, 45.878749, 43.…
#> $ proportion.0.025 <dbl> 1.759164e-50, 5.698079e-49, 3.308357e-47, 2.991…
#> $ proportion.0.5 <dbl> 1.465037e-06, 1.891110e-06, 2.501801e-06, 3.371…
#> $ proportion.0.975 <dbl> 1.0000000, 1.0000000, 1.0000000, 1.0000000, 1.0…
#> $ relative.growth.fit <dbl> 0.24102860, 0.24048966, 0.23901181, 0.23680352,…
#> $ relative.growth.se.fit <dbl> 1.2309119, 1.2257057, 1.2114298, 1.1900979, 1.1…
#> $ relative.growth.0.025 <dbl> -2.1715143, -2.1618494, -2.1353470, -2.0957455,…
#> $ relative.growth.0.5 <dbl> 0.24102860, 0.24048966, 0.23901181, 0.23680352,…
#> $ relative.growth.0.975 <dbl> 2.6535715, 2.6428288, 2.6133706, 2.5693525, 2.5…