InstituteforDiseaseModeling / covasim

COVID-19 Agent-based Simulator (Covasim): a model for exploring coronavirus dynamics and interventions
https://covasim.org
MIT License
247 stars 222 forks source link

Not all agents are present in household layer in a hybrid population #393

Closed AndrewC19 closed 1 year ago

AndrewC19 commented 1 year ago

Describe the bug

When I create a simulation with a hybrid population type and examine the number of individuals in each contact layer, I find that some individuals are not assigned to a household. Is this intentional?

My understanding is that all individuals should be members of the household and community layer, while only some individuals should be members of the school or workplace, depending on age.

To reproduce

import covasim as cv
uk_sim = cv.Sim(pars={'location': 'UK', 'pop_type': 'hybrid', 'rand_seed': 0})
print(uk_sim.pars['pop_size'])  # 20,000
print(len(uk_sim.people.contacts['h'].members))  # 17,215
print(len(uk_sim.people.contacts['c'].members))  # 20,000
print(len(uk_sim.people.contacts['s'].members))  # 3,757
print(len(uk_sim.people.contacts['w'].members))  # 11,049

assert(len(uk_sim.people.contacts['h'].members) == uk_sim.pars['pop_size'])  # AssertionError
assert(len(uk_sim.people.contacts['c'].members) == uk_sim.pars['pop_size'])  # Pass

Expected behavior

As with the contact layer, the household layer should contain all individuals (20,000 in this case).

Platform:

AndrewC19 commented 1 year ago

On further inspection, I guess the discrepancy could be explained by single person households. If this is the case, is there an alternative way I can measure the number of individuals in each contact layer?

cliffckerr commented 1 year ago

@AndrewC19 That's correct, the discrepancy is due to single-person households. I think the calculations you have above are correct -- a person is considered "in" a layer if and only if they have one or more contacts in that layer. As an extreme example, if every single household consisted of a single person (e.g., some kind of dorm situation), we wouldn't include that layer in the network, since there wouldn't be any contacts.

AndrewC19 commented 1 year ago

Thanks for clearing that up @cliffckerr.

Just to confirm then, there is no way to see how many agents belong to each layer (home, school, workplace, community), irrespective of their contacts?

cliffckerr commented 1 year ago

I guess I'd phrase it a little differently...it's correct that there's no way to see how many agents were eligible to be in a particular layer, but the numbers you quoted above are the number of agents per layer. Depending on the way the network was generated (e.g. hybrid vs SynthPops), school enrollment can be <100%, and employment can be <100%. A 14-year-old who doesn't go to school is not in the schools layer with no contacts -- they're not in the schools layer. Likewise, a person living alone is not in the household layer with no contacts -- they're not in the household network.

AndrewC19 commented 1 year ago

Thanks for the explanation, that makes sense.