From 70f7af043c20ebd7e6a95fb343966bbc659bdf07 Mon Sep 17 00:00:00 2001 From: Scott Olesen Date: Thu, 19 Dec 2024 16:29:29 -0500 Subject: [PATCH] add R0 slider --- ringvax/app.py | 61 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/ringvax/app.py b/ringvax/app.py index cf9282e..5af8d35 100644 --- a/ringvax/app.py +++ b/ringvax/app.py @@ -76,6 +76,7 @@ def app(): st.title("Ring vaccination") with st.sidebar: + st.subheader("Disease history times") latent_duration = st.slider( "Latent duration", min_value=0.0, @@ -84,17 +85,67 @@ def app(): step=0.1, format="%.1f days", ) + + max_infectious_duration = 10.0 + min_infectious_duration = 0.1 + default_infectious_duration = 3.0 + max_r0 = 10.0 + default_r0 = 1.5 + infectious_duration = st.slider( "Infectious duration", - min_value=0.0, - max_value=10.0, - value=3.0, + min_value=min_infectious_duration, + max_value=max_infectious_duration, + value=default_infectious_duration, step=0.1, format="%.1f days", ) - infection_rate = st.slider( - "Infection rate", min_value=0.0, max_value=10.0, value=0.5, step=0.1 + + st.subheader("Infectiousness") + r0_control = st.segmented_control( + "Variable infectiousness parameter", + options=["R0", "infection rate"], + selection_mode="single", + default="R0", + help="R0 = infectious duration * infection rate. Only two of the " + "three parameters can be varied.", ) + + if r0_control == "R0": + r0 = st.slider( + "R0", min_value=0.0, max_value=max_r0, value=default_r0, step=0.1 + ) + + infection_rate = st.slider( + "Infection rate (mean infections per day)", + min_value=0.0, + max_value=max_r0 / min_infectious_duration, + value=r0 / infectious_duration, + step=0.1, + disabled=True, + ) + + elif r0_control == "infection rate": + infection_rate = st.slider( + "Infection rate (mean infections per day)", + min_value=0.0, + max_value=max_r0 / max_infectious_duration, + value=default_r0 / default_infectious_duration, + step=0.1, + ) + + r0 = st.slider( + "R0", + min_value=0.0, + max_value=max_r0, + value=infectious_duration * infection_rate, + step=0.1, + disabled=True, + ) + else: + raise RuntimeError(f"Unexpected control value: {r0_control=}") + + st.subheader("Detection") p_passive_detect = ( st.slider( "Passive detection probability",