IDEAS home Printed from https://ideas.repec.org/a/jss/jstsof/v033i09.html
   My bibliography  Save this article

Solving Differential Equations in R: Package deSolve

Author

Listed:
  • Soetaert, Karline
  • Petzoldt, Thomas
  • Setzer, R. Woodrow

Abstract

In this paper we present the R package deSolve to solve initial value problems (IVP) written as ordinary differential equations (ODE), differential algebraic equations (DAE) of index 0 or 1 and partial differential equations (PDE), the latter solved using the method of lines approach. The differential equations can be represented in R code or as compiled code. In the latter case, R is used as a tool to trigger the integration and post-process the results, which facilitates model development and application, whilst the compiled code significantly increases simulation speed. The methods implemented are efficient, robust, and well documented public-domain Fortran routines. They include four integrators from the ODEPACK package (LSODE, LSODES, LSODA, LSODAR), DVODE and DASPK2.0. In addition, a suite of Runge-Kutta integrators and special-purpose solvers to efficiently integrate 1-, 2- and 3-dimensional partial differential equations are available. The routines solve both stiff and non-stiff systems, and include many options, e.g., to deal in an efficient way with the sparsity of the Jacobian matrix, or finding the root of equations. In this article, our objectives are threefold: (1) to demonstrate the potential of using R for dynamic modeling, (2) to highlight typical uses of the different methods implemented and (3) to compare the performance of models specified in R code and in compiled code for a number of test cases. These comparisons demonstrate that, if the use of loops is avoided, R code can efficiently integrate problems comprising several thousands of state variables. Nevertheless, the same problem may be solved from 2 to more than 50 times faster by using compiled code compared to an implementation using only R code. Still, amongst the benefits of R are a more flexible and interactive implementation, better readability of the code, and access to R’s high-level procedures. deSolve is the successor of package odesolve which will be deprecated in the future; it is free software and distributed under the GNU General Public License, as part of the R software project.

Suggested Citation

  • Soetaert, Karline & Petzoldt, Thomas & Setzer, R. Woodrow, 2010. "Solving Differential Equations in R: Package deSolve," Journal of Statistical Software, Foundation for Open Access Statistics, vol. 33(i09).
  • Handle: RePEc:jss:jstsof:v:033:i09
    DOI: http://hdl.handle.net/10.18637/jss.v033.i09
    as

    Download full text from publisher

    File URL: https://www.jstatsoft.org/index.php/jss/article/view/v033i09/v33i09.pdf
    Download Restriction: no

    File URL: https://www.jstatsoft.org/index.php/jss/article/downloadSuppFile/v033i09/deSolve_1.7.tar.gz
    Download Restriction: no

    File URL: https://www.jstatsoft.org/index.php/jss/article/downloadSuppFile/v033i09/v33i09.R
    Download Restriction: no

    File URL: https://www.jstatsoft.org/index.php/jss/article/downloadSuppFile/v033i09/LVmod0D.c
    Download Restriction: no

    File URL: https://www.jstatsoft.org/index.php/jss/article/downloadSuppFile/v033i09/LVmod0D.f
    Download Restriction: no

    File URL: https://libkey.io/http://hdl.handle.net/10.18637/jss.v033.i09?utm_source=ideas
    LibKey link: if access is restricted and if your library uses this service, LibKey will redirect you to where you can use your library subscription to access this item
    ---><---

    References listed on IDEAS

    as
    1. Soetaert, Karline & Petzoldt, Thomas, 2010. "Inverse Modelling, Sensitivity and Monte Carlo Analysis in R Using Package FME," Journal of Statistical Software, Foundation for Open Access Statistics, vol. 33(i03).
    2. Petzoldt, Thomas & Rinke, Karsten, 2007. "simecol: An Object-Oriented Framework for Ecological Modeling in R," Journal of Statistical Software, Foundation for Open Access Statistics, vol. 22(i09).
    Full references (including those not matched with items on IDEAS)

    Most related items

    These are the items that most often cite the same works as this one and are cited by the same works as this one.
    1. repec:jss:jstsof:33:i09 is not listed on IDEAS
    2. Zhou, W. & O’Neill, E. & Moncaster, A. & Reiner, D. & Guthrie, P., 2019. "Applying Bayesian Model Averaging to Characterise Urban Residential Stock Turnover Dynamics," Cambridge Working Papers in Economics 1986, Faculty of Economics, University of Cambridge.
    3. Hanson, Paul C. & Stillman, Aviah B. & Jia, Xiaowei & Karpatne, Anuj & Dugan, Hilary A. & Carey, Cayelan C. & Stachelek, Joseph & Ward, Nicole K. & Zhang, Yu & Read, Jordan S. & Kumar, Vipin, 2020. "Predicting lake surface water phosphorus dynamics using process-guided machine learning," Ecological Modelling, Elsevier, vol. 430(C).
    4. Hannah Al Ali & Alireza Daneshkhah & Abdesslam Boutayeb & Zindoga Mukandavire, 2022. "Examining Type 1 Diabetes Mathematical Models Using Experimental Data," IJERPH, MDPI, vol. 19(2), pages 1-20, January.
    5. Taffi, Marianna & Paoletti, Nicola & Liò, Pietro & Pucciarelli, Sandra & Marini, Mauro, 2015. "Bioaccumulation modelling and sensitivity analysis for discovering key players in contaminated food webs: The case study of PCBs in the Adriatic Sea," Ecological Modelling, Elsevier, vol. 306(C), pages 205-215.
    6. Carus, Jana & Heuner, Maike & Paul, Maike & Schröder, Boris, 2017. "Which factors and processes drive the spatio-temporal dynamics of brackish marshes?—Insights from development and parameterisation of a mechanistic vegetation model," Ecological Modelling, Elsevier, vol. 363(C), pages 122-136.
    7. Lucash, Melissa S. & Marshall, Adrienne M. & Weiss, Shelby A. & McNabb, John W. & Nicolsky, Dmitry J. & Flerchinger, Gerald N. & Link, Timothy E. & Vogel, Jason G. & Scheller, Robert M. & Abramoff, Ro, 2023. "Burning trees in frozen soil: Simulating fire, vegetation, soil, and hydrology in the boreal forests of Alaska," Ecological Modelling, Elsevier, vol. 481(C).
    8. Eline M. Krijkamp & Fernando Alarid-Escudero & Eva A. Enns & Hawre J. Jalal & M. G. Myriam Hunink & Petros Pechlivanoglou, 2018. "Microsimulation Modeling for Health Decision Sciences Using R: A Tutorial," Medical Decision Making, , vol. 38(3), pages 400-422, April.
    9. Meier, Laura & Brauns, Mario & Grimm, Volker & Weitere, Markus & Frank, Karin, 2022. "MASTIFF: A mechanistic model for cross-scale analyses of the functioning of multiple stressed riverine ecosystems," Ecological Modelling, Elsevier, vol. 470(C).
    10. Hussnain Mukhtar & Yu-Pin Lin & Oleg V. Shipin & Joy R. Petway, 2017. "Modeling Nitrogen Dynamics in a Waste Stabilization Pond System Using Flexible Modeling Environment with MCMC," IJERPH, MDPI, vol. 14(7), pages 1-15, July.
    11. Sehjeong Kim & Abdessamad Tridane, 2017. "Thalassemia in the United Arab Emirates: Why it can be prevented but not eradicated," PLOS ONE, Public Library of Science, vol. 12(1), pages 1-13, January.
    12. repec:jss:jstsof:22:i01 is not listed on IDEAS
    13. Lee, Kyoungjae & Lee, Jaeyong & Dass, Sarat C., 2018. "Inference for differential equation models using relaxation via dynamical systems," Computational Statistics & Data Analysis, Elsevier, vol. 127(C), pages 116-134.
    14. Jinyoung Yang & Jeffrey S. Rosenthal, 2017. "Automatically tuned general-purpose MCMC via new adaptive diagnostics," Computational Statistics, Springer, vol. 32(1), pages 315-348, March.
    15. Tancredi Caruso & Jeff R Powell & Matthias C Rillig, 2012. "Compositional Divergence and Convergence in Local Communities and Spatially Structured Landscapes," PLOS ONE, Public Library of Science, vol. 7(4), pages 1-10, April.
    16. McCullough, Ian M. & Dugan, Hilary A. & Farrell, Kaitlin J. & Morales-Williams, Ana M. & Ouyang, Zutao & Roberts, Derek & Scordo, Facundo & Bartlett, Sarah L. & Burke, Samantha M. & Doubek, Jonathan P, 2018. "Dynamic modeling of organic carbon fates in lake ecosystems," Ecological Modelling, Elsevier, vol. 386(C), pages 71-82.
    17. Kneib, Thomas & Petzoldt, Thomas, 2007. "Introduction to the Special Volume on "Ecology and Ecological Modeling in R"," Journal of Statistical Software, Foundation for Open Access Statistics, vol. 22(i01).
    18. Venolia, Celeste T. & Lavaud, Romain & Green-Gavrielidis, Lindsay A. & Thornber, Carol & Humphries, Austin T., 2020. "Modeling the Growth of Sugar Kelp (Saccharina latissima) in Aquaculture Systems using Dynamic Energy Budget Theory," Ecological Modelling, Elsevier, vol. 430(C).
    19. James W Rudge & Piya Hanvoravongchai & Ralf Krumkamp & Irwin Chavez & Wiku Adisasmito & Pham Ngoc Chau & Bounlay Phommasak & Weerasak Putthasri & Chin-Shui Shih & Mart Stein & Aura Timen & Sok Touch &, 2012. "Health System Resource Gaps and Associated Mortality from Pandemic Influenza across Six Asian Territories," PLOS ONE, Public Library of Science, vol. 7(2), pages 1-10, February.
    20. Haas, Marcelo B. & Guse, Björn & Pfannerstill, Matthias & Fohrer, Nicola, 2015. "Detection of dominant nitrate processes in ecohydrological modeling with temporal parameter sensitivity analysis," Ecological Modelling, Elsevier, vol. 314(C), pages 62-72.
    21. Keane, Robert E. & McKenzie, Donald & Falk, Donald A. & Smithwick, Erica A.H. & Miller, Carol & Kellogg, Lara-Karena B., 2015. "Representing climate, disturbance, and vegetation interactions in landscape models," Ecological Modelling, Elsevier, vol. 309, pages 33-47.
    22. Shoya Iwanami & Kosaku Kitagawa & Hirofumi Ohashi & Yusuke Asai & Kaho Shionoya & Wakana Saso & Kazane Nishioka & Hisashi Inaba & Shinji Nakaoka & Takaji Wakita & Odo Diekmann & Shingo Iwami & Koichi , 2020. "Should a viral genome stay in the host cell or leave? A quantitative dynamics study of how hepatitis C virus deals with this dilemma," PLOS Biology, Public Library of Science, vol. 18(7), pages 1-17, July.

    More about this item

    Statistics

    Access and download statistics

    Corrections

    All material on this site has been provided by the respective publishers and authors. You can help correct errors and omissions. When requesting a correction, please mention this item's handle: RePEc:jss:jstsof:v:033:i09. See general information about how to correct material in RePEc.

    If you have authored this item and are not yet registered with RePEc, we encourage you to do it here. This allows to link your profile to this item. It also allows you to accept potential citations to this item that we are uncertain about.

    If CitEc recognized a bibliographic reference but did not link an item in RePEc to it, you can help with this form .

    If you know of missing items citing this one, you can help us creating those links by adding the relevant references in the same way as above, for each refering item. If you are a registered author of this item, you may also want to check the "citations" tab in your RePEc Author Service profile, as there may be some citations waiting for confirmation.

    For technical questions regarding this item, or to correct its authors, title, abstract, bibliographic or download information, contact: Christopher F. Baum (email available below). General contact details of provider: http://www.jstatsoft.org/ .

    Please note that corrections may take a couple of weeks to filter through the various RePEc services.

    IDEAS is a RePEc service. RePEc uses bibliographic data supplied by the respective publishers.