<jupyter_start><jupyter_text>DurationsThis section shows how to use the duration functionality of Episuite. Themain class of this module is the :class:`~episuite.durations.Durations`, thatrepresents any kind of duration between events. One example is representingthe 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 :meth:`~episuite.data.admissions_sample`          function from the :mod:`~episuite.data` module... seealso::   Module :mod:`episuite.durations`      Documentation of the :py:mod:`episuite.durations` module.         Module :mod:`episuite.data`      Documentation of the :py:mod:`episuite.data` module.<jupyter_code>import episuite
from matplotlib import pyplot as plt

from episuite.durations import Durations
from episuite import data<jupyter_output><empty_output><jupyter_text>Load the sample dataFirst we need to load a sample dataset.<jupyter_code>sample_data = data.admissions_sample()
sample_data.head()
sample_data.shape
# Here we are filtering only outcomes that were RECOVERY or DEATH.
sample_data = sample_data[sample_data["OUTCOME"].isin(["RECOVERY", "DEATH"])]<jupyter_output><empty_output><jupyter_text>Build the durations objectHere we are going to build the durations object. Please note that this classrequires you to specify the start and end date column names. By default, it willassume that the columns are named **DATE_START** and **DATE_END**.<jupyter_code>adm = Durations(sample_data)<jupyter_output><empty_output><jupyter_text>Data visualizationThe durations have a `plot` object that you can use to make visualizations of the duration distribution.<jupyter_code>fig = plt.figure(figsize=(7, 4))
adm.plot.histogram()
plt.xlim(0, 80)
plt.show()
fig = plt.figure(figsize=(7, 3))
adm.plot.histogram(hue="OUTCOME")
plt.xlim(0, 80)
plt.show()
fig = plt.figure(figsize=(7, 4))
adm.plot.density(hue="OUTCOME")
plt.xlim(0, 80)
plt.show()<jupyter_output><empty_output><jupyter_text>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%).<jupyter_code>fig = plt.figure(figsize=(10, 5))
adm.plot.timeplot(n_boot=100)
plt.show()
fig = plt.figure(figsize=(10, 5))
adm.plot.timeplot(n_boot=100, hue="OUTCOME")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1024, 'fraction_numerical': 0.0132, 'mean_word_length': 5.8708791208791204, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '629333', 'license': 'MIT', 'n_tokens_mistral': 835, 'n_tokens_neox': 776, 'n_words': 249, 'path': 'docs/source/durations_notebook.ipynb', 'repo_name': 'perone/episuite', 'size': '2500'}