Skip to contents

This test data is based around a known time varying exponential growth rate with an initial epidemic seed size of 100. The data is simulated with weekly periodicity.

Locfit models

Simple incidence test with a poisson model

An incidence mode based on absolute counts:

data = .test_data()
data %>% dplyr::glimpse()
#> Rows: 105
#> Columns: 5
#> $ time  <time_prd> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1…
#> $ r     <dbl> 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,…
#> $ rate  <dbl> 110.5171, 122.1403, 134.9859, 149.1825, 164.8721, 182.2119, 201.…
#> $ count <int> 105, 104, 145, 150, 168, 174, 207, 217, 247, 273, 296, 353, 355,…
#> $ denom <dbl> 2402, 2402, 2402, 2402, 2402, 2402, 2402, 2402, 2402, 2402, 2402…
tmp = data %>% poisson_locfit_model(window=7, deg = 2)

plot_incidence(tmp, data)+ggplot2::geom_line(
  mapping=ggplot2::aes(x=as.Date(time),y=rate), data=data, colour="red",inherit.aes = FALSE)

Estimted absolute growth rate versus simulation (red)


plot_growth_rate(tmp)+
  ggplot2::geom_line(mapping=ggplot2::aes(x=as.Date(time),y=r), data=data, colour="red",inherit.aes = FALSE)


plot_growth_phase(tmp)
#> Warning in .time_labels(x, ..., dfmt = dfmt, ifmt = ifmt, na.value = na.value):
#> labelling applied to non-integer times.

Multinomial data

Multiple classes are simulated as 3 independent epdiemics (‘variant1’, ‘variant2’ and ‘variant3’) with known growth rates and initial sample size resulting in 3 parallel time series. These are combined to give an overall epidemic and a proportional distribution of each ‘variant’ as a fraction of the whole. A relative growth rate is calculated based on set parameters.

data2 = .test_multinomial() %>% dplyr::group_by(class) %>% dplyr::glimpse()
#> Rows: 315
#> Columns: 9
#> Groups: class [3]
#> $ time           <time_prd> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, …
#> $ r              <dbl> 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, …
#> $ rate           <dbl> 110.5171, 122.1403, 134.9859, 149.1825, 164.8721, 182.2…
#> $ count          <int> 105, 104, 145, 150, 168, 174, 207, 217, 247, 273, 296, …
#> $ denom          <dbl> 2402, 2402, 2402, 2402, 2402, 2402, 2402, 2402, 2402, 2…
#> $ class          <chr> "variant1", "variant1", "variant1", "variant1", "varian…
#> $ proportion     <dbl> 0.3382826, 0.3420088, 0.3445125, 0.3458146, 0.3459542, …
#> $ proportion.obs <dbl> 0.3398058, 0.3421053, 0.3452381, 0.3456221, 0.3449692, …
#> $ relative.r     <dbl> 0.019385523, 0.013833622, 0.008404115, 0.003151554, -0.…

Poisson model

Firstly fitting the same incidence model in a groupwise fashion:

tmp2 = data2 %>% poisson_locfit_model(window=7, deg = 1)

plot_incidence(tmp2, data2)+scale_y_log1p()

And the absolute growth rates:

plot_growth_rate(modelled = tmp2)+
   ggplot2::geom_line(mapping=ggplot2::aes(x=as.Date(time),y=r, colour=class), data=data2, inherit.aes = FALSE)+
   ggplot2::facet_wrap(dplyr::vars(class), ncol=1)

One versus others Binomial model

This looks at the proportions of the three variants and their growth rate relative to each other:

# This will reinterpret total to be the total of positives across all variants
data3 = data2 %>% 
  dplyr::group_by(time) %>% 
  dplyr::mutate(denom = sum(count)) %>%
  dplyr::group_by(class) %>%
  dplyr::glimpse()
#> Rows: 315
#> Columns: 9
#> Groups: class [3]
#> $ time           <time_prd> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, …
#> $ r              <dbl> 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, …
#> $ rate           <dbl> 110.5171, 122.1403, 134.9859, 149.1825, 164.8721, 182.2…
#> $ count          <int> 105, 104, 145, 150, 168, 174, 207, 217, 247, 273, 296, …
#> $ denom          <int> 309, 304, 420, 434, 487, 504, 604, 638, 734, 823, 909, …
#> $ class          <chr> "variant1", "variant1", "variant1", "variant1", "varian…
#> $ proportion     <dbl> 0.3382826, 0.3420088, 0.3445125, 0.3458146, 0.3459542, …
#> $ proportion.obs <dbl> 0.3398058, 0.3421053, 0.3452381, 0.3456221, 0.3449692, …
#> $ relative.r     <dbl> 0.019385523, 0.013833622, 0.008404115, 0.003151554, -0.…

Firstly proportions:


tmp3 = data3 %>% proportion_locfit_model(window=14, deg = 2)

plot_proportion(modelled = tmp3,raw = data3)+
  ggplot2::facet_wrap(dplyr::vars(class), ncol=1)

And secondly relative growth rate:



plot_growth_rate(modelled = tmp3)+
   ggplot2::geom_line(mapping=ggplot2::aes(x=as.Date(time),y=relative.r, colour=class), data=data2, inherit.aes = FALSE)+
   ggplot2::facet_wrap(dplyr::vars(class), ncol=1)


plot_growth_phase(tmp3)
#> Warning in .time_labels(x, ..., dfmt = dfmt, ifmt = ifmt, na.value = na.value):
#> labelling applied to non-integer times.

Multinomial model

The mulitnomial model gives us absolute proportions only (and no growth rates)

# we don't need to calculate the denominator as it is done automatically by the 
# mulitnomial model

tmp4 = data2 %>% multinomial_nnet_model()
#> # weights:  30 (18 variable)
#> initial  value 361707.109921 
#> iter  10 value 182309.592690
#> iter  20 value 178948.204365
#> final  value 176994.905787 
#> converged
plot_multinomial(tmp4)


# plot_multinomial(tmp3, events = event_test,normalise = TRUE)

GLM models

Poisson model

  • Spline currently only good for incidence

tmp5 = data %>% poisson_glm_model(window=7)
plot_incidence(tmp5,data)

Binomial model

Absolute proportions only


tmp6 = data3 %>% proportion_glm_model(window=14, deg = 2)
plot_proportion(tmp6,data3)