Durations¶
This section shows how to use the duration functionality of Episuite. The
main class of this module is the Durations
, that
represents any kind of duration between events. One example is representing
the length of stay (also known as LoS) for patients in ICU units.
Note
In the example below, we will use a sample dataset that comes embedded
in Episuite with real data from the SARS-CoV-2 outbreak in south of Brazil.
This dataset can be accessed using the admissions_sample()
function from the data
module.
See also
- Module
episuite.durations
Documentation of the
episuite.durations
module.- Module
episuite.data
Documentation of the
episuite.data
module.
[1]:
import episuite
from matplotlib import pyplot as plt
from episuite.durations import Durations
from episuite import data
Load the sample data¶
First we need to load a sample dataset.
[2]:
sample_data = data.admissions_sample()
[3]:
sample_data.head()
[3]:
DATE_START | DATE_END | OUTCOME | |
---|---|---|---|
0 | 2020-06-17 | 2020-08-03 | RECOVERY |
1 | 2020-06-11 | 2020-06-21 | DEATH |
2 | 2020-07-12 | 2020-08-02 | DEATH |
3 | 2020-06-25 | 2020-07-31 | DEATH |
4 | 2020-07-24 | 2020-08-16 | DEATH |
[4]:
sample_data.shape
[4]:
(4538, 3)
[5]:
# Here we are filtering only outcomes that were RECOVERY or DEATH.
sample_data = sample_data[sample_data["OUTCOME"].isin(["RECOVERY", "DEATH"])]
Build the durations object¶
Here we are going to build the durations object. Please note that this class requires you to specify the start and end date column names. By default, it will assume that the columns are named DATE_START and DATE_END.
[6]:
adm = Durations(sample_data)
Data visualization¶
The durations have a plot
object that you can use to make visualizations of the duration distribution.
[7]:
fig = plt.figure(figsize=(7, 4))
adm.plot.histogram()
plt.xlim(0, 80)
plt.show()
[8]:
fig = plt.figure(figsize=(7, 3))
adm.plot.histogram(hue="OUTCOME")
plt.xlim(0, 80)
plt.show()
[9]:
fig = plt.figure(figsize=(7, 4))
adm.plot.density(hue="OUTCOME")
plt.xlim(0, 80)
plt.show()
<Figure size 504x288 with 0 Axes>
This plot shows the average distribution per day. In this case we are computing 100 bootstrap samples to compute the default confidence interval (CI 95%).
[10]:
fig = plt.figure(figsize=(10, 5))
adm.plot.timeplot(n_boot=100)
plt.show()
[11]:
fig = plt.figure(figsize=(10, 5))
adm.plot.timeplot(n_boot=100, hue="OUTCOME")
plt.show()