---
# System prepended metadata

title: Debugging infectiousness
tags: [debugging infectiousness]

---

---
tags: debugging infectiousness
---

# Debugging infectiousness
[Pull request code](https://github.com/mila-iqia/covi-simulator/pull/37)

| Before | After |
|--------|--------|
| ![](https://i.imgur.com/pjBPkon.png) |![](https://i.imgur.com/Dgd61s3.png) |
|![](https://i.imgur.com/5rwZd8q.png) | ![](https://i.imgur.com/ELG1UYf.png)| 
| ![](https://i.imgur.com/SCVRUuo.png) |  ![](https://i.imgur.com/TVbq1jp.png) |


### Analysis
A long time ago, @nasimrahaman identified that there was a problem with the number of days it takes to become infectious. We can see this clearly in the bottom left plot, there is a large peak at 1 day, so many people were beginning to be infectious starting 1 day after they were exposed. Now, it took additional time for their infectiousness to peak, but still, the time when they began to be infectious was too early. To remedy this, we made a couple changes. 


#### Incubation Days
Incubation days are the number of days before symptom onset (for symptomatic folks). Incubation days are Gamma distributed, but cannot be less than 2 days. Previously, we had implemented this cutoff as a max of 2 and the result of sampling a Gamma, but this slightly overweighted 2 day incubation periods. We fixed this by instead resampling if the sampled number is less than 2. 


#### Infectiousness onset days wrt incubation
The middle row of charts is somewhat subtle, so bear with me. We define the time until infectiousness onset in relation to symptom onset. In our model, people become symptomatic _after_ they become infectious. The plots in the middle row hsow the number of days it takes for infected people to become infectious _before_ symptom onset. 

The smaller these values are, the shorter the duration between infectiousness onset and symptom onset. In the left middle chart you can see that for most people, there's at least 1 day, and more often 2 days between infectiousness onset and symptom onset. 

On the left (the "before times"), we sampled these values from a truncated gaussian with mean 2.3, a minimum clip around 0.5 and a max clip around 3.5. On the right, we modify this distribution by multiplying each sampled value of this gaussian with a scale factor depending on the incubation days.

The scale factor we chose was the sampled incubation_days value divided by the INCUBATION_DAYS_GAMMA_SHAPE parameter (~6 in this case). Therefore, for small sampled values of incubation_days (lets say 3) we scale down the infectiousness onset days offset by 2 (3/6). Basically, we're just scaling down the relative offset when incubation days is small, and scaling it up when it's big.


#### Infectiousness onset days
Bottom right is the money plot.

By subtracting the scaled version of the offset from the incubation days, we get a nice new infectiousness onset days that looks much more like a gamma. You can see that we've managed to shift the distribution to the right, making the amount of time it takes for people to become infectious after being exposed more realistic. :leopard: 

## Parameters
#### &incubation period: Refer to Table 2 (in Appendix) of [ACP paper](https://www.acpjournals.org/doi/10.7326/M20-0504) for parameters
INCUBATION_DAYS_GAMMA_SHAPE: 5.807
INCUBATION_DAYS_GAMMA_SCALE: 0.948

#### &infectiousness-onset: [He 2020](https://www.nature.com/articles/s41591-020-0869-5#ref-CR1) infectiousness peaked at 0.7 days (95% CI, −0.2–2.0 days) before symptom onset (Fig. 1c).
INFECTIOUSNESS_PEAK_AVG: 0.7 # DAYS
INFECTIOUSNESS_PEAK_STD: 0.5
INFECTIOUSNESS_PEAK_CLIP_LOW: 0.01
INFECTIOUSNESS_PEAK_CLIP_HIGH: 2.2

#### &infectiousness-onset [He 2020 https://www.nature.com/articles/s41591-020-0869-5#ref-CR1] infectiousness started from 2.3 days (95% CI, 0.8–3.0 days) before symptom onset and peaked at 0.7 days (95% CI, −0.2–2.0 days) before symptom onset (Fig. 1c).
INFECTIOUSNESS_ONSET_DAYS_WRT_SYMPTOM_ONSET_AVG: 2.3
INFECTIOUSNESS_ONSET_DAYS_WRT_SYMPTOM_ONSET_STD: 0.5
#### we set these to be even more conservative than the 95% CI, more like 98% CI
INFECTIOUSNESS_ONSET_DAYS_WRT_SYMPTOM_ONSET_CLIP_LOW: 0.5
INFECTIOUSNESS_ONSET_DAYS_WRT_SYMPTOM_ONSET_CLIP_HIGH: 3.3
