diff --git a/IntervalsModel/network-data/POLYMOD/AALfreqdist.csv b/IntervalsModel/network-data/POLYMOD/AALfreqdist.csv index 5cd9c2b0c2c9c9e28d1461804057d0bb94d1a49b..012df22ce2a8dfa6be17cab0943ad1ecd8cbc175 100644 --- a/IntervalsModel/network-data/POLYMOD/AALfreqdist.csv +++ b/IntervalsModel/network-data/POLYMOD/AALfreqdist.csv @@ -1,13 +1,19 @@ ,Age_in,Age_out,location,0,1,2 0,Y,Y,workschool,0.77870480731029,0.19355052310952192,0.027744669580188053 1,Y,Y,rest,0.37273777435502503,0.33153638814016173,0.29572583750481324 -2,Y,M,workschool,0.4929277756915759,0.3358367755664038,0.1712354487420203 -3,Y,M,rest,0.24455087479229792,0.26116704134493207,0.49428208386277 -4,Y,O,workschool,0.5075757575757576,0.21212121212121213,0.2803030303030303 -5,Y,O,rest,0.20387453874538744,0.3274907749077491,0.46863468634686345 -6,M,M,workschool,0.4924376199616123,0.2583493282149712,0.24921305182341652 -7,M,M,rest,0.1579316799251287,0.25869599126501325,0.583372328809858 -8,M,O,workschool,0.3647859922178988,0.24610894941634243,0.3891050583657587 -9,M,O,rest,0.1687344913151365,0.2924937965260546,0.5387717121588089 -10,O,O,workschool,0.2,0.2545454545454545,0.5454545454545455 -11,O,O,rest,0.1589895988112927,0.35066864784546803,0.4903417533432392 +2,Y,M,workschool,0.4884488448844885,0.3536067892503536,0.15794436586515795 +3,Y,M,rest,0.2386593470095348,0.25874024848309735,0.5026004045073678 +4,Y,O,workschool,0.35185185185185186,0.2037037037037037,0.4444444444444444 +5,Y,O,rest,0.1974025974025974,0.34545454545454546,0.45714285714285713 +6,M,Y,workschool,0.49799839871897517,0.31571924206031493,0.1862823592207099 +7,M,Y,rest,0.25687518887881533,0.26624357812027805,0.4768812330009066 +8,M,M,workschool,0.4924376199616123,0.2583493282149712,0.24921305182341652 +9,M,M,rest,0.1579316799251287,0.25869599126501325,0.583372328809858 +10,M,O,workschool,0.40144927536231884,0.2246376811594203,0.3739130434782608 +11,M,O,rest,0.19285274183610598,0.30560690080098585,0.5015403573629083 +12,O,Y,workschool,0.6153846153846154,0.21794871794871795,0.16666666666666669 +13,O,Y,rest,0.2197452229299363,0.28343949044585987,0.4968152866242038 +14,O,M,workschool,0.28994082840236685,0.28994082840236685,0.42011834319526625 +15,O,M,rest,0.14428482198625858,0.27920049968769517,0.5765146783260462 +16,O,O,workschool,0.2,0.2545454545454545,0.5454545454545455 +17,O,O,rest,0.1589895988112927,0.35066864784546803,0.4903417533432392 diff --git a/IntervalsModel/network-data/POLYMOD/Duration-priors.py b/IntervalsModel/network-data/POLYMOD/Duration-priors.py index 01d25f9500433cc6d535f309de2c3e1656f9d895..be0ecd3033e7f231e7e35f502c66f2f06540463d 100644 --- a/IntervalsModel/network-data/POLYMOD/Duration-priors.py +++ b/IntervalsModel/network-data/POLYMOD/Duration-priors.py @@ -16,7 +16,6 @@ import numpy as np import pandas as pd import math from itertools import product -import matplotlib.pyplot as plt # Read the cleaned survey as a dataframe Contact = pd.read_csv("AALContact_data.csv") @@ -36,7 +35,6 @@ def symage_row(row): if symage == (agesrc, agetar) or symage == (agetar, agesrc): return symage Contact['symage'] = Contact.apply(symage_row, axis=1) -#print(Contact[Contact['symage']==('M', 'M')].head(10)) # Dictionary separating contact data by symage-location ContAAL = {} @@ -46,10 +44,7 @@ for symage, loc in list(product(SymAge,Locales)): x,y,z = symage[0], symage[1], loc C = Contact[Contact['cnt_'+z] == True][Contact['symage']==symage] ContAAL[(x,y,z)] = C[columns].copy(deep=True) -test1 = ('Y', 'Y', 'home') -test2 = ('Y', 'M', 'home') -print(ContAAL[test1].head(15)) -print(ContAAL[test2].head(25)) + # Duration distributions stratified by SymAge-location DurFreqAAL = {} @@ -97,26 +92,4 @@ dfkeys = pd.DataFrame([pd.Series(x) for x in df.col1]) dfkeys.columns = ["Age_in", "Age_out", "location"] dfvals = pd.DataFrame([pd.Series(x) for x in df.col2]) dfout = dfkeys.join(dfvals) -dfout.to_csv("AALPoisPriors.csv") - -# Determine frequency distributions accord to to symage-locales, excluding hh -freqdistAAL={} -locales_nohh = ['workschool', 'rest'] -for symage, loc in list(product(SymAge, locales_nohh)): - x, y, z = symage[0],symage[1],loc - C = ContAAL[(x,y,z)] - tot = len(C) - freqfull = np.full(5,0.) - for i in range(1,6): - count = len(C[C['frequency_multi']==i]) - freqfull[i-1] = (count)/tot - freqdistAAL[(x,y,z)] = [freqfull[0], freqfull[1], np.sum(freqfull[2:])] - - -# Save them to csv -df = pd.DataFrame(list(freqdistAAL.items()), columns=['col1','col2']) -dfkeys = pd.DataFrame([pd.Series(x) for x in df.col1]) -dfkeys.columns = ["Age_in", "Age_out", "location"] -dfvals = pd.DataFrame([pd.Series(x) for x in df.col2]) -dfout = dfkeys.join(dfvals) -dfout.to_csv("AALfreqdist.csv") +dfout.to_csv("AALPoisPriors.csv") \ No newline at end of file diff --git a/IntervalsModel/network-data/POLYMOD/Frequency-distribution.py b/IntervalsModel/network-data/POLYMOD/Frequency-distribution.py new file mode 100644 index 0000000000000000000000000000000000000000..065beeded43597477a33413c628ea2e96b3ce934 --- /dev/null +++ b/IntervalsModel/network-data/POLYMOD/Frequency-distribution.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on 2021-03-24 + +Determines the fraction of interactions which are daily, 3x/week or singular + in the ABM. Daily are those with frequency_mult =1, 3x/week are 2 and + singular are 3-5. + + + +@author: mark +""" +import numpy as np +import pandas as pd +from itertools import product + +# Read the cleaned survey as a dataframe +Contact = pd.read_csv("AALContact_data.csv") + + +# Specify AAL categories +Ages = ['Y', 'M', 'O'] +Locales = ['home', 'workschool', 'rest'] + +# Dictionary separating contact data by symage-location +ContAAL = {} +columns = ['part_id', 'cont_id', 'age_source', 'age_target', + 'duration_multi', 'frequency_multi'] +for x,y,z in list(product(Ages,Ages,Locales)): + #x,y,z = symage[0], symage[1], loc + C = Contact[Contact['cnt_'+z] == True][Contact['age_source']==x][Contact['age_target']==y] + ContAAL[(x,y,z)] = C[columns].copy(deep=True) + +# Determine frequency distributions accord to AAL, excluding hh +freqdistAAL={} +locales_nohh = ['workschool', 'rest'] +for x,y, z in list(product(Ages, Ages, locales_nohh)): + #x, y, z = symage[0],symage[1],loc + C = ContAAL[(x,y,z)] + tot = len(C) + freqfull = np.full(5,0.) + for i in range(1,6): + count = len(C[C['frequency_multi']==i]) + freqfull[i-1] = (count)/tot + freqdistAAL[(x,y,z)] = [freqfull[0], freqfull[1], np.sum(freqfull[2:])] + + +# Save them to csv +df = pd.DataFrame(list(freqdistAAL.items()), columns=['col1','col2']) +dfkeys = pd.DataFrame([pd.Series(x) for x in df.col1]) +dfkeys.columns = ["Age_in", "Age_out", "location"] +dfvals = pd.DataFrame([pd.Series(x) for x in df.col2]) +dfout = dfkeys.join(dfvals) +dfout.to_csv("AALfreqdist.csv") \ No newline at end of file