Skip to main content

Exploring Modeling by Programming: Insights from Numerical Experimentation

  • Chapter
  • First Online:
  • 1090 Accesses

Part of the book series: Foundations for Undergraduate Research in Mathematics ((FURM))

Abstract

This chapter aims to provide students the background necessary to use computational methods and numerical experimentation to pursue mathematical research. We provide a brief refresher on differential equations, model building, and programming, followed by in-depth discussions of how numerical experimentation was critical to three undergraduate research projects involving parasite transmission in feral cats, the role of protein regulation in establishing circadian rhythms, and treatment costs in an influenza outbreak. Code (written in R) is provided for most of the models and nearly all of the figures presented in the chapter, so that the reader may learn the programming as they go along. We also propose ideas for extending the research projects presented in the text. Both deterministic and stochastic models are presented and the critical role of computational methods in obtaining solutions is illustrated.

Electronic supplementary material The online version of this chapter (https://doi.org/10.1007/978-3-030-33645-5_4) contains supplementary material, which is available to authorized users.

This is a preview of subscription content, log in via an institution.

Buying options

eBook
USD   19.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   29.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD   39.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

References

  1. L. J. S. Allen. An Introduction to Stochastic Processes with Applications to Biology. CRC Press, second edition, 2010.

    Google Scholar 

  2. R. M. Anderson and R. M. May. Infectious Diseases of Humans: Dynamics and Control. Oxford University Press, 1992.

    Google Scholar 

  3. C. A. Beauchemin and A. Handel. A review of mathematical models of influenza a infections within a host or cell culture: lessons learned and challenges ahead. BMC Public Health, 11 (1): S7, 2 2011.

    Article  Google Scholar 

  4. S. Becker-Weimann, J. Wolf, H. Herzel, and A. Kramer. Modeling feedback loops of the mammalian circadian oscillator. Biophysical Journal, 87 (5): 3023 – 3034, 2004.

    Article  Google Scholar 

  5. P. Blanchard, R. L. Devaney, and G. R. Hall. Differential Equations. Cengage Learning, 2012.

    Google Scholar 

  6. H. W. Borchers. pracma: Practical Numerical Math Functions, 2019. URL https://CRAN.R-project.org/package=pracma. R package version 2.2.5.

  7. W. E. Boyce, R. C. DiPrima, and D. B. Meade. Elementary Differential Equations and Boundary Value Problems. Wiley, 2017.

    Google Scholar 

  8. F. Brauer. Mathematical epidemiology: Past, present, and future. Infectious Disease Modelling, 2 (2): 113–127, 2017.

    Article  Google Scholar 

  9. R. L. Burden, J. D. Faires, and A. M. Burden. Numerical Analysis. Cengage Learning, 2016.

    MATH  Google Scholar 

  10. B. J. Coburn, B. G. Wagner, and S. Blower. Modeling influenza epidemics and pandemics: insights into the future of swine flu (H1N1). BMC Medicine, 7 (1): 30, 6 2009.

    Google Scholar 

  11. O. Diekmann, J. A. P. Heesterbeek, and J. A. J. Metz. On the definition and the computation of the basic reproduction ratio R 0 in models for infectious diseases in heterogeneous populations. Journal of Mathematical Biology, 28 (4): 365–382, 6 1990.

    Google Scholar 

  12. O. Diekmann, J. A. P. Heesterbeek, and M. Roberts. The construction of next-generation matrices for compartmental epidemic models. Journal of the Royal Society, Interface, 7 (47): 873—885, 6 2010.

    Google Scholar 

  13. L. Edelstein-Keshet. Mathematical Models in Biology. Classics in Applied Mathematics. Society for Industrial and Applied Mathematics (SIAM, 3600 Market Street, Floor 6, Philadelphia, PA 19104), 1988.

    Google Scholar 

  14. B. Ermentrout. Bifurcation calculations with AUTO, 1995. URL http://www.math.pitt.edu/~bard/bardware/tut/xppauto.html.

  15. B. Ermentrout. Simulating, Analyzing, and Animating Dynamical Systems. Society for Industrial and Applied Mathematics, 2002.

    Book  Google Scholar 

  16. B. Ermentrout. XPPAUT 8.0, 2016. URL http://www.math.pitt.edu/~bard/xpp/xpp.html.

  17. Z. Feng, J. Velasco-Hernandez, and B. Tapia-Santos. A mathematical model for coupling within-host and between-host dynamics in an environmentally-driven infectious disease. Mathematical Biosciences, 241: 49–55, 01 2013.

    Article  MathSciNet  Google Scholar 

  18. L. Fu and N. M. Kettner. Chapter nine - the circadian clock in cancer development and therapy. In M. U. Gillette, editor, Chronobiology: Biological Timing in Health and Disease, volume 119 of Progress in Molecular Biology and Translational Science, pages 221 – 282. Academic Press, 2013.

    Google Scholar 

  19. C. Gardiner. Stochastic Methods: A Handbook for the Natural and Social Sciences. Springer Series in Synergetics. Springer Berlin Heidelberg, 2009.

    MATH  Google Scholar 

  20. D. T. Gillespie. A general method for numerically simulating the stochastic time evolution of coupled chemical reactions. Journal of Computational Physics, 22 (4): 403 – 434, 1976.

    Article  MathSciNet  Google Scholar 

  21. D. T. Gillespie. Exact stochastic simulation of coupled chemical reactions. The Journal of Physical Chemistry, 81 (25): 2340–2361, 1977.

    Article  Google Scholar 

  22. D. T. Gillespie. A diffusional bimolecular propensity function. The Journal of Chemical Physics, 131 (16): 164109, 2009.

    Article  Google Scholar 

  23. G. C. González-Parra, A. J. Arenas, D. F. Aranda, R. J. Villanueva, and L. Jódar. Dynamics of a model of toxoplasmosis disease in human and cat populations. Computers & Mathematics with Applications, 57 (10): 1692 – 1700, 2009.

    MathSciNet  MATH  Google Scholar 

  24. N. J. Gotelli. A Primer of Ecology. Sinauer, 2008.

    Google Scholar 

  25. J. A. P. Heesterbeek. The law of mass-action in epidemiology: A historical perspective. In B. Beisner and K. Cuddington, editors, Ecological paradigms lost: routes of theory change, Theoretical Ecology Series, chapter 5, pages 81–106. Elsevier Science, 2005.

    Google Scholar 

  26. H. Hethcote. The mathematics of infectious diseases. SIAM Review, 42 (4): 599–653, 2000.

    Article  MathSciNet  Google Scholar 

  27. D. E. Hill and J. P. Dubey. Toxoplasma gondii. In Y. R. Ortega and C. R. Sterling, editors, Foodborne Parasites, pages 119–138. Springer International Publishing, Cham, 2018.

    Chapter  Google Scholar 

  28. M.-C. Huang, C.-W. Ho, C.-H. Chen, S.-C. Liu, C.-C. Chen, and S.-J. Leu. Reduced expression of circadian clock genes in male alcoholic patients. Alcoholism: Clinical and Experimental Research, 34: 1899–904, 11 2010.

    Article  Google Scholar 

  29. J. Keener and J. Sneyd. Mathematical Physiology: I: Cellular Physiology. Interdisciplinary Applied Mathematics. Springer New York, 2008.

    MATH  Google Scholar 

  30. J. Keener and J. Sneyd. Mathematical Physiology: II: Systems Physiology. Interdisciplinary Applied Mathematics. Springer New York, 2009.

    Book  Google Scholar 

  31. E. K. Kelting. Toxoplasma gondii: A mathematical model of its transfer between cats and the environment. SIAM Undergraduate Research Online, 11, 2018.

    Google Scholar 

  32. W. O. Kermack and A. G. McKendrick. A Contribution to the Mathematical Theory of Epidemics. Proc. R. Soc. A Math. Phys. Eng. Sci., 115 (772): 700–721, 1927.

    MATH  Google Scholar 

  33. K. Koelle, S. Cobey, B. Grenfell, and M. Pascual. Epochal evolution shapes the phylodynamics of interpandemic influenza a (H3N2) in humans. Science, 314 (5807): 1898–1903, 2006.

    Google Scholar 

  34. H. Kokko. Modelling for Field Biologists and Other Interesting People. Cambridge University Press, 2007.

    Book  Google Scholar 

  35. M. Kot. Elements of Mathematical Ecology. Elements of Mathematical Ecology. Cambridge University Press, 2001.

    Book  Google Scholar 

  36. L. Lyall, C. A Wyse, N. Graham, A. Ferguson, D. Lyall, B. Cullen, C. Celis-Morales, S. Biello, D. Mackay, J. Ward, R. Strawbridge, J. Gill, M. Bailey, J. P Pell, and D. J Smith. Association of disrupted circadian rhythmicity with mood disorders, subjective wellbeing, and cognitive function: a cross-sectional study of 91,105 participants from the UK Biobank. The Lancet Psychiatry, 5, 05 2018.

    Article  Google Scholar 

  37. H. McCallum, N. Barlow, and J. Hone. How should pathogen transmission be modelled? Trends in Ecology & Evolution, 16 (6): 295 – 300, 2001.

    Article  Google Scholar 

  38. J. McVernon, C. McCaw, and J. Mathews. Model answers or trivial pursuits? the role of mathematical models in influenza pandemic preparedness planning. Influenza and Other Respiratory Viruses, 1 (2): 43–54, 2007.

    Article  Google Scholar 

  39. N.-A. M. Molinari, I. R. Ortega-Sanchez, M. L. Messonnier, W. W. Thompson, P. M. Wortley, E. Weintraub, and C. B. Bridges. The annual impact of seasonal influenza in the US: Measuring disease burden and costs. Vaccine, 25 (27): 5086 – 5096, 2007.

    Article  Google Scholar 

  40. J. Montoya and O. Liesenfeld. Toxoplasmosis. The Lancet, 363 (9425): 1965 – 1976, 2004.

    Google Scholar 

  41. F. Portaluppi, R. Tiseo, M. H Smolensky, R. Hermida, D. E Ayala, and F. Fabbian. Circadian rhythms and cardiovascular health. Sleep Medicine Reviews, 16: 151–66, 06 2011.

    Article  Google Scholar 

  42. R Core Team. R: A language and environment for statistical computing, 2018.

    Google Scholar 

  43. K. Soetaert, T. Petzoldt, and R. W. Setzer. Solving differential equations in R: Package deSolve. Journal of Statistical Software, 33 (9): 1–25, 2010.

    Article  Google Scholar 

  44. S. H. Strogatz. Nonlinear Dynamics and Chaos: With Applications to Physics, Biology, Chemistry, and Engineering. Studies in Nonlinearity. Avalon Publishing, 2014.

    MATH  Google Scholar 

Download references

Acknowledgements

The authors wish to acknowledge undergraduate students Emily Kelting, Grace Kelting, and Chaissone Moore whose research helped inspire many of the projects in this chapter. Though their work is not explicitly featured in the collection of projects described in the chapter, Sean’s work with two former students, Katie Link and Bryan Dawkins, had an important impact on the development of many of the programming-infused approaches to the pursuit of undergraduate mathematical biology research and the role of numerical experimentation. Many of these projects have benefitted from research and travel funding from the University of Central Oklahoma’s Office of High-Impact Practices and the RCSA program, and the College of Mathematics and Science’s CURE-STEM program. We appreciate the supportive research environment provided for undergraduate students at University of Central Oklahoma.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Sean M. Laverty .

Editor information

Editors and Affiliations

Appendices

Appendix 1: Notes on Programming

Where possible we have attempted to simplify code in such a way to allow you to more simply reproduce the figures in this Chapter. We expect that the results you are able to produce from running code snippets will match those that we have included in the chapter, but please do not be alarmed by slight aesthetic differences. In particular, we prefer to use the mtext(...) command in R to generate axis labels which can be adjusted slightly more easily than can the defaults. For example, to produce many of our figures in the text, by plotting the model output ..., we recommend the code

plot(..., xlab=’Time’, ylab=’Population size’)

For our own use, we prefer the slightly more complex code below, which results in slightly better looking output, though this is a matter of preference.

par(mfrow=c(1, 1), mar=c(4.1, 4.1, 1.1, 1.1)) plot(..., xlab=’’, ylab=’’) # empty axis labels mtext(’Time’, 1, line=2.5, font=2, cex=1.25) mtext(’Population size’, 2, line=2.5, font=2, cex=1.25)

The first line of this code sets the layout of the plot, here one row by one column, and the second sets the plot margins in the order bottom-left-top-right. We add our plot (with blank labels) to a window of that shape and configuration and add text to the margins. The ambitious reader may be interested in exploring the graphics capabilities of the ggplot2 package.

Figures can be saved from menu selections or using the following approach

pdf(’filename.pdf’, height=5, width=5) ## insert arbitrary figure code dev.off()

Entering ?pdf into the R console will show how the pdf(...) command works and related commands like png(...} or jpeg(...).

A few examples of syntax and useful commands for basic calculations or plotting are given in Table 4. A brief overview of available differential equations solvers from the deSolve package is given in Table 5.

Table 4 List of useful commands and operations included in the base installation of R
Table 5 List of differential equations solvers and commands included in deSolve

Appendix 2: Circadian Rhythm Code

Start by defining the model. We have included some if statements that allow us to turn the alcohol parameter on or off at a given time (t.switch1 and t.switch2), to test how the system responds. Earlier we mentioned having to find and replace in order to replace the printed single quote used to specify many arguments in R if you copy code from an electronic source. Here we use double asterisks (∗∗) to enter exponents rather than the more familiar caret (ˆ), since the latter does not copy well from electronic text.

## the model CLOCKmod <- function(t, x, parms)  {   with(as.list(c(parms, x)), {     ## alcohol value switch     if(t > t.switch1){     a <- 1     }     if(t > t.switch2){     a <- 1     } #conc. of Per2/Cry mRNA     dY1 <- (a∗v1b∗(Y7+c))/(k1b∗(1+(Y3/k1i)∗∗p+Y7+c))        -k1d∗Y1 # conc. of PER2/CRY complex in the cytoplasm     dY2 <- k2b∗(Y1)∗∗q - k2d∗Y2 - k2t∗Y2 + k3t∗Y3 # conc. of PER2/CRY complex in the nucleus     dY3 <- k2t∗Y2 - k3t∗Y3 - k3d∗Y3 # conc. of Bmal1 mRNA     dY4 <- (v4b∗(Y3)∗∗r)/((k4b)∗∗r + (Y3)∗∗r) - k4d∗Y4 # conc. of BMAL1 protein in the cytoplasm     dY5 <- k5b∗Y4 - k5d∗Y5 - k5t∗Y5 + k6t∗Y6 # conc. of BMAL1 protein in the nucleus     dY6 <- k5t∗Y5 - k6t∗Y6 - k6d∗Y6 + k7a∗Y7 - k6a∗Y6 # conc. of transcriptionally active form BMAL1     dY7 <- k6a∗Y6 - k7a∗Y7 - k7d∗Y7 # the output     list(c(dY1, dY2, dY3, dY4, dY5, dY6, dY7)) })}

Again to verify our assignments, we print the parameters and initial conditions to the screen, but since times refers to a very long vector, we assign it but do not print it to the screen.

(parms <- c(v1b = 9, k1b = 1, k1i = 0.56, c = 0.01,    p = 8, k1d = 0.12, k2b = 0.3, q = 2, k2d = 0.05,    k2t = 0.24, k3t = 0.02, k3d = 0.12, v4b = 3.6,    k4b = 2.16, r = 3, k4d = 0.75, k5b = 0.24,    k5d = 0.06, k5t = 0.45, k6t = 0.06, k6d = 0.12,    k6a = 0.09, k7a = 0.003, k7d = 0.09,    a = 1, t.switch1 = 5000, t.switch2 = 5000)) times <- seq(0, 5000, by=0.1) (xstart <- c(Y1 = 0.25, Y2 = 0.3, Y3 = 1.15,    Y4 = 0.85, Y5 = 0.72, Y6 = 1.35, Y7 = 1.075))

To assess the role of the alcohol sensitivity parameter on dynamics, we first numerically solve the model for the original parameter value a = 1, store, and plot the solution over the interval of interest.

## calculate solution    out  <- lsoda(xstart, times, CLOCKmod, parms)    out  <- as.data.frame(out) ## plots    plot(out$time, out$Y3, type=’l’, col=’gray’,       lty=1, lwd=2, ylim=c(0, 5), xlim=c(0, 250),       xlab=’Time (hours)’,       ylab=’Protein amounts (nM)’, las=1)    lines(out$time, out$Y5 + out$Y6 + out$Y7,       type=’l’, col=’black’, lty=2, lwd=2)

Then, we change the value of a in the list of parameters by manually resetting it. Since the initial conditions, solution times, and the structure of the model itself are unchanged, we can simply calculate a new solution with the updated parameters and add the desired results to the existing plot. This realization allows us to greatly simplify our computer code by leaving out large, redundant chunks that would otherwise be tempting to repeat.

## fix parameter value, repeat as necessary    parms[’a’] <- 0.1    out2  <- lsoda(xstart, times, CLOCKmod, parms)    out2  <- as.data.frame(out2)

After computing the solution for the parameter of interest, we can add these solutions to our existing plot to better understand the role of the parameter.

## add corresponding solutions    lines(out2$time, out2$Y3, type=’l’, col=’red’,       lty=1, lwd=2)    lines(out2$time, out2$Y5 + out2$Y6 + out2$Y7,       type=’l’, col=’red4’, lty=2, lwd=2)

Finally, since the plot is now quite complex, we add a nice legend.

## add legend    legend(’topleft’, c(’PER2/CRY Protein’,       ’BMAL1 Protein’, ’PER2/CRY Protein (w/ alcohol)’,       ’BMAL1 Protein (w/ alcohol)’), col=c(’gray’,       ’black’, ’red’, ’red4’), lty=c(1, 2, 1, 2), lwd=2,       bg=’white’)

For space purposes, we have not included the code in which peak concentrations were calculated and stored. This was done using the pracma package [6], and can be found in the project’s GitHub page.

Appendix 3: Influenza Code

First we define the model, since the equation for the change in cost is long, the + at the end of the first two parts of the equation ensures that each subsequent line is counted as continuation of the previous line.

## the model FLUmod <- function(t, x, parms)  {   with(as.list(c(parms, x)), { #for all, m is parameter for natural mortality #Susceptible    dS <- p - m∗S - beta∗S∗I - zeta∗S + omega∗(V + N + R) #Vaccination    dV <- zeta∗S - m∗V - omega∗V #Infectious    dI <- beta∗S∗I - gamma∗I - m∗I #Recovered Naturally    dN <- (1 - delta)∗(1 - rho)∗gamma∗I - m∗N - omega∗N #Treated, coded as R to avoid confusion with T for TRUE    dR <- (1 - delta)∗(rho)∗gamma∗I - m∗R - omega∗R #Mortality    dD <- delta∗gamma∗I #Added cost equation    dC <- z∗zeta∗S + b∗beta∗S∗I + d∗delta∗gamma∗I +      + n∗(1 - delta)∗(1 - rho)∗gamma∗I  +      + r∗(1 - delta)∗(rho)∗gamma∗I     list(c(dS, dV, dI, dN, dR, dD, dC)) # the output })}

Then we define parameters, the list of times for which to calculate the solution, and initial conditions. The factor of 1∕52 included in many of the parameter values was used to scale all values to be measured in weeks. To provide example dynamics in Fig. 12, we solve the model over a period of 2 years.

## parameters    parms <- c(p = (13)∗(1/52), m = (0.013)∗(1/52),       beta = (0.08)∗(1/52), zeta = (1.2)∗(1/52),       gamma = (12)∗(1/52), omega = (0.8)∗(1/52),       delta = 0.0005, rho = (1/3), z = 52.92,       b = 3.00, d = 542430.70, n = 110.28, r = 5613.65) ## time points    times <- seq(0, 52∗2, by=0.1) ## initial values    xstart <- parms[’p’]/parms[’m’]∗c(S = 0.98,V = 0.01,       I = 0.01, N = 0, R = 0, D = 0, C = 0)

Finally, we use the numerical solver lsoda to find the model solution.

out <- lsoda(xstart, times, FLUmod, parms) out <- as.data.frame(out)

The matplot(...) command lets us plot multiple columns simultaneously (even allowing for different line styles or widths in addition to colors). We can access multiple columns of output, each of which corresponds to a model variable, by referring to their numbers (e.g., out[, c(2, 4, 6)]), a range of numbers (e.g., out[, 2:6], which is all of the entries 2 through 6), or by name (as shown in the sample code below). Since the vector of custom colors is rather long, we define the cols at the start, which can be referenced anytime the variables are plotted.

## define colors cols <- c("red", "gray", "green", "blue", "magenta") ## panel 1 matplot(out$time, out[, c(’S’, ’V’, ’I’, ’R’,’N’)],    type=’l’, lty=1, lwd=2, col=cols,    xlab=’Time (weeks)’, ylab=’Population    densities (number/area)’, las=1) legend(’topright’, c(’Susceptible’, ’Vaccinated’,    ’Infectious’, ’Treated’, ’Natural’),    col=cols, lty=1, lwd=2, bg=’white’) ## panel 2 (cost scaled to millions) plot(out$time, out$C/1e6, type=’l’, lty=1,    xlab=’Time (weeks)’, ylab=’Cost (millions USD)’,       las=1)

To solve the model for a range of ζ parameter values, then plot the long-term behaviors as a function of ζ as it varies, we use the code below.

## time vector    times <- seq(0, 52∗200, by=0.1) ## range of zeta values    zetas <- c(seq(0.0, 0.2, by=0.01)) ## object to store model output    vals <- NULL for(i in 1:length(zetas)){    parms[’zeta’] <- zetas[i]    out  <-  lsoda(xstart, times, FLUmod, parms)    out  <- as.data.frame(out)    if(i/10==floor(i/10))print(i) ## progress bar    vals <- rbind(vals, out[nrow(out), ]) }

The above code assigns the parameter value of interest, calculates the corresponding solution, and stores the final output of the solution in an object called vals. Here we take advantage of the power of the computer to generate solutions over a very long span of time, just to ensure that solutions have equilibrated. Inspecting plots of solutions against time (as in Fig. 12) offers some explanation, as the dynamics of the two recovered groups are especially slow.

matplot(zetas, vals[, c(’S’, ’V’, ’I’, ’R’, ’N’)],    type=’l’, lty=1, lwd=2, col=cols,    xlim=c(0, 0.2), ylim=c(0, 1000), xlab=’Vaccination    rate’, ylab=’Population steady-state values’, las=1) legend(’topleft’, c(’Susceptible’, ’Vaccinated’,    ’Infectious’, ’Treated’, ’Natural’),    col=cols, lty=1, lwd=2, bg=’white’)

Rights and permissions

Reprints and permissions

Copyright information

© 2020 Springer Nature Switzerland AG

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Bannish, B.E., Laverty, S.M. (2020). Exploring Modeling by Programming: Insights from Numerical Experimentation. In: Callender Highlander, H., Capaldi, A., Diaz Eaton, C. (eds) An Introduction to Undergraduate Research in Computational and Mathematical Biology. Foundations for Undergraduate Research in Mathematics. Birkhäuser, Cham. https://doi.org/10.1007/978-3-030-33645-5_4

Download citation

Publish with us

Policies and ethics