Skip to content

Commit 34215e6

Browse files
amanda-minteravallecam
authored andcommitted
add step 4
1 parent d99c601 commit 34215e6

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

episodes/disease-burden.Rmd

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ hosp <- new_cases$new_infections * ihr
223223
We convolve the expected number of hospitalisations (hosp) with the distribution of onset to admission times to obtain the estimated number of new hospitalisations
224224

225225

226+
226227
```{r}
227228
# define tail of the delay distribution
228229
tail_value_admission <- quantile(onset_to_admission, 0.999)
@@ -244,17 +245,23 @@ tail_value_discharge <- quantile(admission_to_discharge, 0.999)
244245
discharges <- convolve(hospitalisations, rev(density(admission_to_discharge,
245246
0:tail_value_discharge)),
246247
type = "open")[seq_along(hospitalisations)]
247-
# calculate the current number in hospital
248-
in_hospital <- cumsum(hospitalisations) - cumsum(discharges)
249248
```
250249

250+
#### 4. Calculate the number in hospital as the difference between the cumulative sumo of hospitalisation and the cumulative sum of discharges
251+
252+
We can use the R function `cumsum()` to calculate the cumulative number of hospitalisations and discharges. The difference between these two quantities gives is the current number of people in hospital.
251253

254+
```{r}
255+
# calculate the current number in hospital
256+
in_hospital <- cumsum(hospitalisations) - cumsum(discharges)
257+
```
252258

259+
We create a data frame to plot our outcomes using `pivot_longer()`:
253260
```{r}
254261
# create data frame
255262
hosp_df <- cbind(new_cases, in_hospital = in_hospital,
256263
hospitalisations = hospitalisations)
257-
# pivot longer for plotting
264+
# pivot longer for plotting
258265
hosp_df_long <- pivot_longer(hosp_df, cols = new_infections:hospitalisations,
259266
names_to = "outcome", values_to = "value")
260267

0 commit comments

Comments
 (0)