Table Of ContentUseR!
Ottar N. Bjørnstad
Epidemics
Models and Data Using R
Second Edition
Use R!
SeriesEditors
RobertGentleman,23andMeInc.,SouthSanFrancisco,USA
KurtHornik,DepartmentofFinance,AccountingandStatistics,WU
Wirtschaftsuniversita¨tWien,Vienna,Austria
GiovanniParmigiani,Dana-FarberCancerInstitute,Boston,USA
ThisseriesofinexpensiveandfocusedbooksonRisaimedatpractitioners.Books
candiscusstheuseofRinaparticularsubjectarea(e.g.,epidemiology,economet-
rics,psychometrics)orasitrelatestostatisticaltopics(e.g.,missingdata,longitu-
dinaldata).Inmostcases,bookscombineLaTeXandRsothatthecodeforfigures
andtablescanbeputonawebsite.Authorsshouldassumeabackgroundassupplied
byDalgaard’sIntroductoryStatisticswithRorotherintroductorybookssothateach
bookdoesnotrepeatbasicmaterial.
HowtoSubmitYourProposal
Book proposals and manuscripts should be submitted to one of the publishing
editors in your region per email - for the list of statistics editors by their loca-
tion please see https://www.springer.com/gp/statistics/contact-us. All submissions
shouldincludeacompletedBookProposalForm.
Forgeneralandtechnicalquestionsregardingtheseriesandthesubmissionpro-
cesspleasecontactFaithSu([email protected])orVeronikaRosteck(veronika.
[email protected]).
Ottar N. Bjørnstad
Epidemics
Models and Data Using R
Second Edition
OttarN.Bjørnstad
CenterforInfectiousDiseaseDynamics
PennsylvaniaStateUniversity
UniversityPark,PA,USA
ISSN2197-5736 ISSN2197-5744 (electronic)
UseR!
ISBN978-3-031-12055-8 ISBN978-3-031-12056-5 (eBook)
https://doi.org/10.1007/978-3-031-12056-5
1stedition:©SpringerNatureSwitzerlandAG2018
2ndedition:©Theeditor(s)(ifapplicable)andTheAuthor(s),underexclusivelicensetoSpringerNature
SwitzerlandAG2023
Thisworkissubjecttocopyright.AllrightsaresolelyandexclusivelylicensedbythePublisher,whether
thewholeorpartofthematerialisconcerned,specificallytherightsoftranslation,reprinting,reuse
ofillustrations,recitation,broadcasting,reproductiononmicrofilmsorinanyotherphysicalway,and
transmissionorinformationstorageandretrieval,electronicadaptation,computersoftware,orbysimilar
ordissimilarmethodologynowknownorhereafterdeveloped.
Theuseofgeneraldescriptivenames,registerednames,trademarks,servicemarks,etc.inthispublication
doesnotimply,evenintheabsenceofaspecificstatement,thatsuchnamesareexemptfromtherelevant
protectivelawsandregulationsandthereforefreeforgeneraluse.
Thepublisher,theauthors,andtheeditorsaresafetoassumethattheadviceandinformationinthisbook
arebelievedtobetrueandaccurateatthedateofpublication.Neitherthepublishernortheauthorsor
theeditorsgiveawarranty,expressedorimplied,withrespecttothematerialcontainedhereinorforany
errorsoromissionsthatmayhavebeenmade.Thepublisherremainsneutralwithregardtojurisdictional
claimsinpublishedmapsandinstitutionalaffiliations.
ThisSpringerimprintispublishedbytheregisteredcompanySpringerNatureSwitzerlandAG
Theregisteredcompanyaddressis:Gewerbestrasse11,6330Cham,Switzerland
ForKatriona,Esme,andMichael
Preface
PrefacetoSecondEdition
Aswiththefirstedition,thesecondeditionhasfurtherbenefittedheavilyfromin-
putfromnumerouspeople,particularlymyvariousstudents,postdocs,andcollab-
orators. The book club at the London School of Tropical Medicine and Hygiene
provided valuable feedback on the first edition clarifying how the text should be
better fleshed out and organized. Reorganizing, restructuring, and recoding meant
that the current material is not fully back-compatible, so the epimdr2 Rpackage
shouldbeusedwiththenewedition.Typesettingofequationshasbeenchangedfor
clarityandshinyAppshaslargelybeenreparameterizedwithreproductionnumber,
R ,ratherthantransmissionrate(β)sincethatismoreintuitive.TheSARS-CoV-2
0
pandemicspurredsignificantnewanalysesofinfectiousdiseasedynamics.Muchof
the new age-structured modeling in Chap.4 were developed with Jessica Metcalf,
RuiyunLi,andDamiPak.Thecatalyticmodelisnowdiscussedinaseparatechapter
(Chap.5).Newcompetingstrainmodelshavebeenadded(Sect.3.12).Thechapter
onnetworkshasbeengreatlyexpanded.FunctionsforautomationofJacobianma-
tricesandnextgenerationcalculationarepresented.Anewchapteroninvasionand
persistence(Chap.15)hasnewtreatmentofzoonosesincludingvisitsonbranching
processes, spatial diffusion, synchrony, and metapopulation persistence. New data
sets were provided by Lance Waller and Laura Pomeroy as well as various pub-
licly available sources. Rustom Antia has kindly helped me better understand the
rudimentsofadaptiveimmunityandimmunememory.
Tounderstandthephilosophybehindthistext,Iencourageanyreadertoperuse
theprefacetothefirstedition.1 WhiletheR ecosystemisevolvingrapidly,Ihave
deliberatelystriventousegenericS3codeforallcalculations(exceptforoccasional
strayingforanimations,etc.,inaccompanyingshinyApps)forthereasonthatIdi-
dactically believe that the logic of programming with data laid out by Chambers
(1998) is the simplest and most elegant way. With respect to mathematical sym-
1Theprefacetothefirsteditionhasbeenupdatedsochapterandsectionlabelsareconsistentwith
thenewtext.
vii
viii Preface
bols, I have tried as best as possible to be consistent in usage (thus some changes
innotationfromfirstedition)suchthat,forexample,βisgenerallyusedfortrans-
mission,φforforceofinfection,ωforlossofimmunity,ratesarelowercaseGreek,
andprobabilitiesareuppercaseGreek.Thetextcoversalotofmaterialthough,so
keepingtheGreekalphabetsoupsortedhasbeenchallenging.
In addition to previous funding, this text has also benefitted from support from
the Norwegian Research Council. The text and associated teaching materials have
beenmymainpassionforalmostadecade.
UniversityPark,PA,USA OttarN.Bjørnstad
May2022
Preface ix
PrefacetoFirstEdition
Despite an undergraduate degree in Zoology and a MSc on the behavior of voles,
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
clever books and journal articles exuding all sort of nifty maths and stats, but not
quite being able to do any of it myself when it came to infectious diseases that I
care about. This frustration led me to make myself some worked examples of all
this cleverness. Over the years the stack of how-to’s has grown, and the following
chaptersareanattemptatorganizingthesesotheymaybeusefultoothers.Ihave
tried to organize the chapters and sections in a reasonably logical way: Chaps.2–
11 is a mix and match of models, data and statistics pertaining to local disease
dynamics;Chaps.12–15pertainstospatialandspatiotemporaldynamics;Chap.16
highlights similarities between the dynamics of infectious disease and parasitoid–
hostdynamics;Finally,Chaps.17–18overviewsadditionalstatisticalmethodology
Ihavefoundusefulinthestudyofinfectiousdiseasedynamics.Somesectionsare
marked as “advanced” for one of two reasons: (i) either the maths or stats is a bit
more involved and/or (ii) the topic in focus is a bit more esoteric. Although not
markedassuch,mostofChap.11isadvancedinthisrespect.Whilelessrun-of-the-
mill,Ihavethoughtitimportanttoincludethesesections,becausetheycovertopics
thatmaybelesseasytofindcodeforelsewhere.
I have had invaluable help from students, colleagues and collaborators in my
quest.Thepre-conferenceworkshopsof“EcologyandEvolutionofInfectiousDis-
ease”thatIco-taughtbetween2005and2008enhancedmymotivationtoannotate
manyworkedexamples;Bare-bonesofseveralofthefollowingsectionswerewrit-
tenduringfrantic24hrsstintspriortotheseworkshops.Muchoftheothermaterial
arose from interactions with students and post-docs at Pennsylvania State Univer-
sity’s Center for Infectious Disease Dynamics (CIDD). Parts of the epidemics on
networksandtheR removalestimatorisfromMattFerrari’sPhDresearch,theage-
0
structuredSIRsimulatorandtheSIRWSmodelisfromJennieLavine’sPhDwork.
Working with distributed-delay models has been a collaboration with Bill Nelson
and my students Lindsay Beck-Johnson and Megan Greischar. Angie Luis and I
cookedupthecodetodotransferfunctionsinRaspartofherPhDresearch.Much
ofthecodeonthecatalyticmodelisfromcollaborationswithLauraPomeroyand
then-CIDDpostdoctoralfellowsGrainneLongandJessMetcalf.Thein-hostTSIR
was also a collaboration with Jess. The Gillespie code arose from collaborations
with postdoctoral fellow Shouli Li and my honor student Reilly Mummah. Reilly
alsotaughtmehowtowritemyfirstshinyApp.AwayfromPennState,AaronKing
andBenBolkerhaveatvarioustimesbeenunbelievablypatientinteachingmebits
of maths I didn’t understand. Roger Nisbet painstakingly guided me through my
first transfer functions during my postdoctoral fellowship at NCEAS. During the
sameperiodJordiBascompteintroducedmetocoupled-maplatticemodels.Finally,
x Preface
BryanGrenfellshowedmewaveletsandintroducedmetothefieldofinfectiousdis-
easedynamicssome20yearsago.
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
the National Science Foundation, the National Institute of Health, the US Depart-
mentofAgricultureandtheBillandMelindaGatesFoundation.