UseR! Ottar N. Bjørnstad Epidemics Models and Data using R Use R! SeriesEditors RobertGentleman KurtHornik GiovanniParmigiani Moreinformationaboutthisseriesathttp://www.springer.com/series/6991 Ottar N. Bjørnstad Epidemics Models and Data using R 123 OttarN.Bjørnstad CenterforInfectiousDiseaseDynamics PensylvaniaStateUniversity UniversityPark,PA,USA ISSN2197-5736 ISSN2197-5744 (electronic) UseR! ISBN978-3-319-97486-6 ISBN978-3-319-97487-3 (eBook) https://doi.org/10.1007/978-3-319-97487-3 LibraryofCongressControlNumber:2018953687 ©SpringerNatureSwitzerlandAG2018 Thisworkissubjecttocopyright.AllrightsarereservedbythePublisher,whetherthewholeorpartof thematerialisconcerned,specificallytherightsoftranslation,reprinting,reuseofillustrations,recitation, broadcasting,reproductiononmicrofilmsorinanyotherphysicalway,andtransmissionorinformation storageandretrieval,electronicadaptation,computersoftware,orbysimilarordissimilarmethodology nowknownorhereafterdeveloped. Theuseofgeneraldescriptivenames,registerednames,trademarks,servicemarks,etc.inthispublication doesnotimply,evenintheabsenceofaspecificstatement,thatsuchnamesareexemptfromtherelevant protectivelawsandregulationsandthereforefreeforgeneraluse. Thepublisher,theauthorsandtheeditorsaresafetoassumethattheadviceandinformationinthisbook arebelievedtobetrueandaccurateatthedateofpublication.Neitherthepublishernortheauthorsor theeditorsgiveawarranty,expressorimplied,withrespecttothematerialcontainedhereinorforany errorsoromissionsthatmayhavebeenmade.Thepublisherremainsneutralwithregardtojurisdictional claimsinpublishedmapsandinstitutionalaffiliations. ThisSpringerimprintispublishedbytheregisteredcompanySpringerNatureSwitzerlandAG Theregisteredcompanyaddressis:Gewerbestrasse11,6330Cham,Switzerland ForKatriona,Esme,andMichael Preface DespiteanundergraduatedegreeinZoologyandanMSconthebehaviorofvoles, I have long been fascinated by theoretical biology and the relationship between models and data, and the feedback between statistical analysis and conceptual de- velopmentsintheareaofinfectiousdiseasedynamics,inparticular,andecological dynamicsingeneral.Myperpetualfrustrationhasbeentoreadallthewonderfully cleverbooksandjournalarticlesexudingallsortsofniftymathsandstats,butnot quite being able to do any of it myself when it came to infectious diseases that I care about. This frustration led me to attempt to make myself some worked ex- amples of all this cleverness. Over the years the stack of how-tos has grown, and thefollowingchaptersareanattemptatorganizingthesesotheymaybeusefulfor others. I have tried to organize the chapters and sections in a reasonably logical way:Chaps.1–10areamixandmatchofmodels,data,andstatisticspertainingto localdiseasedynamics;Chaps.11–13pertaintospatialandspatiotemporaldynam- ics;Chap.14highlightssimilaritiesbetweenthedynamicsofinfectiousdiseaseand parasitoid-host dynamics; finally, Chaps.15 and 16 overview additional statistical methodology I have found useful in studies of infectious disease dynamics. Some sections are marked as “advanced” for one of two reasons: (1) either the maths or statsisabitmoreinvolvedor(2)thetopicinfocusisabitmoreesoteric.Although notmarkedassuch,mostofChap.10isadvancedinthisrespect.Whilelessrun-of- the-mill, I have thought it important to include these sections, because they cover topicsthatmaybelesseasytofindcodeforonline. I have had invaluable help from students, colleagues, and collaborators in my quest.Thepreconferenceworkshopsof“EcologyandEvolutionofInfectiousDis- eases”thatIco-taughtbetween2005and2008enhancedmymotivationtoannotate manyworkedexamples;barebonesofseveralofthefollowingsectionswerewrit- tenduringfrantic24-hstintspriortotheseworkshops.Muchoftheothermaterial arose from interactions with students and postdocs at Pennsylvania State Univer- sity’s Center for Infectious Disease Dynamics (CIDD). Parts of the epidemics on networksandtheR removalestimatorisfromMattFerrari’sPhDresearch,andthe 0 age-structuredSIRsimulatorandtheSIRWSmodelarefromJennieLavine’sPhD vii viii Preface work.Workingwithdistributed-delaymodelshasbeenacollaborationwithBillNel- sonandmystudentsLindsayBeck-JohnsonandMeganGreischar.AngieLuisandI cookeduptheRcodetodotransferfunctionsaspartofherPhDresearch.Muchof thecodeonthecatalyticmodelisfromcollaborationswithLauraPomeroyandthen CIDDpostdoctoralfellowsGrainneLongandJessMetcalf.Thein-hostTSIRwas also a collaboration with Jess. The Gillespie code arose from collaborations with postdoctoral fellow Shouli Li and my honor student Reilly Mummah. Reilly also taught me how to write my first Shiny app. Away from Penn State, Aaron King and Ben Bolker have at various times been unbelievably patient in teaching me bitsofmaths Ididnotunderstand. Roger Nisbetpainstakingly guided methrough my first transfer functions during my postdoctoral fellowship at NCEAS. During the same period, Jordi Bascompte introduced me to coupled map lattice models. Finally,BryanGrenfellshowedmewaveletsandintroducedmetothefieldofinfec- tiousdiseasedynamicssome20yearsago. ThedatausedhasbeenkindlysharedbyJanisAntonovics,JeremyBurdon,Re- becca Grais, Sylvije Huygen, Jenn Keslow, Sandy Leibhold, Grainne Long, and MaryPoss.ThefirstdraftofthetextwascompletedwhileIwasonsabbaticalatthe University of Western Australia and University of Oslo/the Norwegian Veterinary Instituteduring2017.Myworkleadinguptothistexthasvariouslybeenfundedby theNationalScienceFoundation,theNationalInstitutesofHealth,theUSDepart- mentofAgriculture,andtheBillandMelindaGatesFoundation. UniversityPark,PA,USA OttarN.Bjørnstad May2018 Contents 1 Introduction................................................. 1 1.1 Preamble .............................................. 1 1.2 In-HostPersistence ...................................... 2 1.3 PatternsofEndemicity ................................... 4 1.4 R ..................................................... 6 1.5 OtherResources ........................................ 8 2 SIR......................................................... 9 2.1 TheSIRModel ......................................... 9 2.2 NumericalIntegrationoftheSIRModel .................... 11 2.3 FinalEpidemicSize ..................................... 14 2.4 OpenEpidemic ......................................... 18 2.5 PhaseAnalyses ......................................... 18 2.6 StabilityandPeriodicity.................................. 21 2.7 Advanced:MoreRealisticInfectiousPeriods ................ 23 2.8 ShinyApp.............................................. 27 3 R .......................................................... 31 0 3.1 PrimacyofR .......................................... 31 0 3.2 Preamble:RatesandProbabilities.......................... 32 3.3 EstimatingR fromaSimpleEpidemic ..................... 33 0 3.4 MaximumLikelihood:TheChain-BinomialModel ........... 35 3.5 StochasticSimulation .................................... 40 3.6 FurtherExamples ....................................... 41 3.6.1 InfluenzaA/H1N11977............................ 41 3.6.2 EbolaSierraLeone2014–2015...................... 43 3.6.3 EbolaDRC1995 ................................. 46 3.7 R fromS(E)IRFlows ................................... 47 0 3.8 OtherRulesofThumb ................................... 49 3.8.1 MeanAgeofInfection............................. 49 ix x Contents 3.8.2 FinalEpidemicSize............................... 49 3.8.3 ContactTracing .................................. 49 3.9 Advanced:TheNext-GenerationMatrix .................... 51 3.9.1 SEIR ........................................... 51 3.9.2 SEIHFR......................................... 53 4 FoIandAge-DependentIncidence ............................. 57 4.1 BurdenofDisease....................................... 57 4.2 ForceofInfection ....................................... 58 4.3 ProbabilityofInfectionatAge:TheCatalyticModel.......... 59 4.4 MoreFlexibleφ-Functions ............................... 62 4.5 ALog-SplineModel..................................... 66 4.6 Rubella................................................ 69 4.7 WAIFW ............................................... 74 4.8 Advanced:RASModel................................... 76 5 Seasonality .................................................. 81 5.1 EnvironmentalDrivers ................................... 81 5.2 TheSeasonallyForcedSEIRModel........................ 84 5.3 Seasonalityinβ......................................... 85 5.4 BifurcationAnalysis..................................... 89 5.5 StroboscopicSection..................................... 90 5.6 SusceptibleRecruitment.................................. 92 5.7 ShinyApp.............................................. 94 6 Time-SeriesAnalysis ......................................... 95 6.1 TaxonomyofMethods ................................... 95 6.2 TimeDomain:ACFandARMA ........................... 95 6.2.1 ARMA.......................................... 97 6.3 FrequencyDomain ...................................... 99 6.4 Wavelets............................................... 100 6.5 MeaslesinLondon ...................................... 102 6.6 ProjectTycho........................................... 107 6.7 LombPeriodogram:WhoopingCough...................... 107 6.8 TriennialCycles:PhiladelphiaMeasles ..................... 108 6.9 WaveletReconstructionandWaveletFilter:Diphtheria ........ 111 6.10 Advanced:FFTandReconstruction ........................ 114 7 TSIR ....................................................... 117 7.1 StochasticVariability .................................... 117 7.2 EstimatingParametersinDynamicModels .................. 120 7.3 EstimationUsingtheTSIR ............................... 121 7.3.1 Inference(Hypothetical) ........................... 121 7.4 Inference(forReal)...................................... 122 7.4.1 SusceptibleReconstruction ......................... 122 7.4.2 Estimation....................................... 124
Description: