Skip to content

Instantly share code, notes, and snippets.

@leuchtetgruen
Created February 18, 2021 11:39
Show Gist options
  • Save leuchtetgruen/17f61f6bacd3ceeb6e32265c1df858df to your computer and use it in GitHub Desktop.
Save leuchtetgruen/17f61f6bacd3ceeb6e32265c1df858df to your computer and use it in GitHub Desktop.
import pandas as pd
import numpy as np
import scipy.stats as st
CT_CUTOFF = str(28)
# CSV from https://raw.githubusercontent.com/skissler/CtTrajectories_B117/main/data/ct_dat_refined.csv
f = pd.read_csv("ct_dat_refined.csv")
b117Lt30 = f.query("B117Status == 'Yes' and CtT1 < " + CT_CUTOFF)
noB117Lt30 = f.query("B117Status == 'No' and CtT1 < " + CT_CUTOFF)
ids117 = b117Lt30.PersonIDClean.unique()
idsNo117 = noB117Lt30.PersonIDClean.unique()
durations117 = []
durationsNo117 = []
for nr in ids117:
nrValues = b117Lt30.query("PersonIDClean == " + str(nr))
days = nrValues.TestDateIndex.unique()
minDay = min(days)
maxDay = max(days)
duration = maxDay - minDay
durations117.append(duration)
for nr in idsNo117:
nrValues = noB117Lt30.query("PersonIDClean == " + str(nr))
days = nrValues.TestDateIndex.unique()
minDay = min(days)
maxDay = max(days)
duration = maxDay - minDay
durationsNo117.append(duration)
print("Nr of days B1.1.7 Cases are infectious (CT < " + CT_CUTOFF + "):")
ci95117 = st.t.interval(0.95, len(durations117)-1, loc=np.mean(durations117), scale=st.sem(durations117))
mean117 = np.mean(durations117)
print(str(mean117) + " CI95 " + str(ci95117))
print("Nr of days Non-B1.1.7 Cases are infectious (CT < " + CT_CUTOFF + "):")
ciNon95117 = st.t.interval(0.95, len(durationsNo117)-1, loc=np.mean(durationsNo117), scale=st.sem(durationsNo117))
meanNon117 = np.mean(durationsNo117)
print(str(meanNon117) + " CI95 " + str(ciNon95117))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment