mrc-ide / squire

SEIR transmission model of COVID-19. Documentation at:
https://mrc-ide.github.io/squire/
Other
50 stars 28 forks source link

Inconsistent Occupancy Figures #111

Open lrossouw opened 4 years ago

lrossouw commented 4 years ago

Getting inconsistent occupancy figures when using format_output with and without reduce_age:

r <- run_explicit_SEEIR_model(country = "United Kingdom", replicates = 10)

# check deaths
death_data_1 <-
  format_output(
    r,
    var_select = c("deaths"),
    reduce_age = FALSE
  )
death_data_2 <-
  format_output(
    r,
    var_select = c("deaths"),
    reduce_age = TRUE
  )

deaths_1 <-
  death_data_1 %>% filter(replicate == 5) %>% group_by(t, compartment) %>% summarise(y =
                                                                                       sum(y)) %>% ungroup()
deaths_2 <-
  death_data_2 %>% filter(replicate == 5) %>% group_by(t, compartment) %>% summarise(y =
                                                                                       sum(y)) %>% ungroup()
stopifnot(deaths_1 == deaths_2) #this is fine!

# check occupancy
capacity_data_1 <-
  format_output(
    r,
    var_select = c("ICU_occupancy"),
    reduce_age = FALSE
  )
capacity_data_2 <-
  format_output(
    r,
    var_select = c("ICU_occupancy"),
    reduce_age = TRUE
  )

occupancy_1 <-
  capacity_data_1 %>% filter(replicate == 5) %>% group_by(t, compartment) %>% summarise(y =
                                                                                          sum(y)) %>% ungroup()
occupancy_2 <-
  capacity_data_2 %>% filter(replicate == 5) %>% group_by(t, compartment) %>% summarise(y =
                                                                                          sum(y)) %>% ungroup()
stopifnot(occupancy_1 == occupancy_2) #these are not equal

occupancy_1 %>% filter(t==68) #>12 000
occupancy_2 %>% filter(t==68) #10 353 (matches capacity)

The occupancies at the bottom should both be 10 353.

lrossouw commented 4 years ago

Same applies to the demand figures.

OJWatson commented 4 years ago

Hey @lrossouw - thanks for picking this up. That is indeed a bug.

I have checked that when reduce_age = TRUE you do get the correct totals (i.e. it matches the sum from the correct columns in r$output).

Will get working on a patch.

P.S. Thank you for the really clear reproducible example.

OJWatson commented 4 years ago

Have found where this is. Need to call it a night but note to self that odin_sv will work through each column with reduce_age = FALSE. For multi compartment summaries like this we need to go through each age column at a time first in order for the data.frame creation on line 214 to work.

lrossouw commented 4 years ago

I was looking to see how squire priortises beds by age group? I.e. if 100 people of various ages need a bed and I have 10 beds free who gets them?

lrossouw commented 4 years ago

Any feedback on this?