Questions tagged [desolve]

deSolve is an R package with functions for solving first-order ordinary differential equations ('ODE'), partial differential equations ('PDE'), differential algebraic equations ('DAE'), and delay differential equations. This tag should be used for questions regarding how to build or debug statistical models done with functions that belong to deSolve.

Package deSolve includes functions for solving initial value problems of a system of first-order ordinary differential equations (ODE), of partial differential equations (PDE), of differential algebraic equations (DAE), and of delay differential equations. The package provides an interface to the of the ODEPACK FORTRAN collection and a C-implementation of solvers of the Runge-Kutta family with fixed or variable time steps. The package also contains routines designed for solving ODEs resulting from 1-D, 2-D and 3-D partial differential equations (PDE).

Official website (r-project.org)

Repositories

Vignettes

64 questions
2
votes
1 answer

Differences between Rs deSolve and Pythons odeint

I'm currently exploring the Lorenz system with Python and R and have noticed subtle differences in the ode packages. odeint from Python and ode both say they use lsoda to calculate their derivatives. However, using the lsoda command for both seems…
AW27
  • 481
  • 3
  • 15
2
votes
1 answer

How do I get outputs at fixed steps?

I have a system of differential equations, there a bit complex but the closest analogy I can come to is for a catalized checmical reaction where the catalist decomposes over time, e.g. A + B -> C + B (rate k1) B -> D (rate k2) So we have…
Stephen Connolly
  • 13,872
  • 6
  • 41
  • 63
1
vote
1 answer

R: Varying parameters based on states in ODE

Please pardon me as this is my first time typing a post on SO. If you think I need to format my changes do let me know :) I am currently trying to run an SIR model that introduces vaccination, and this vaccination will stop after hitting a threshold…
ckng
  • 13
  • 2
1
vote
1 answer

R - Issue coupling DeSolve ODE with purrr:map

I'm trying to automate my code, which requires solving ODE, over the changes of different parameters. I have a nested data frame, with 2 columns: PP, which is my "main" variable data, which gathers 14 variables computed from the PP value. This…
Rachel
  • 13
  • 3
1
vote
1 answer

How to include time-varying parameters in an ODE system with deSolve R without modification of cumulative indicators when using approxfun?

I need to summarise the total number of people alive, the total number of deaths, and some other cumulative indicators, in a deterministic compartmental model with parameters that vary each year. I’m using approxfun for the time-varying parameters…
Andyga
  • 15
  • 4
1
vote
1 answer

Moderately large rate of change yields negative state

I'm working on Susceptible-Infected-Recovered model, that is defined on a meta-population, and relates cells pairwise through a distance-based scoring. While doing that, my state goes below zero, (S). And I don't understand why. Turns out that this…
Mossa
  • 1,656
  • 12
  • 16
1
vote
1 answer

Unequal derivative number and length of initial condition vectors when working with ODEs

I am have issues with the ODE function in R. I keep getting the error "Error in checkFunc(Func2, times, y, rho) : The number of derivatives returned by func() (3006) must equal the length of the initial conditions vector (6)". The function seems to…
Sofia John
  • 21
  • 2
1
vote
2 answers

Variable always equal to 0 in my ode model

I have written an ODE model in R using the ode() function from the deSolve package. The equation predicts the evolution of the mass of pesticide on foliar surface. app1 is equal to the pesticide's mass applied (on day 156) and the function should…
Pablo
  • 39
  • 1
  • 7
1
vote
1 answer

Multiple forcings in a multi-patch ode model - R package desolve and compiled C code

I am trying to create an SEIR model with multiple patches using the package deSolve in R. At each time step, there is some movement of individuals between patches that can infect individuals in other patches. I also have an external forcing…
m.evans
  • 606
  • 3
  • 15
1
vote
1 answer

Vary parameter through time in ODE

I am using the deSolve package to solve a differential equation describing predator-prey dynamics. As an example, below is a simple L-V predator-prey model. I would like some of the parameters in the model to vary through time. I can vary state…
flee
  • 1,253
  • 3
  • 17
  • 34
1
vote
1 answer

Find timepoint when a state variable meets a condition

I have set up a model that looks like this library(deSolve) model <- function(t, x, parms) { S <- x[1] E <- x[2] I <- x[3] R <- x[4] K <- x[5] V <- x[6] # with(as.list(parms), { Q <- ifelse(t < day0 | t > day0 + duration, 0,…
James Azam
  • 88
  • 8
1
vote
2 answers

How to set up a Monte Carlo simulation in an ODE to estimate uncertainty?

I am aiming to do a Monte Carlo simulation of my ODE to see the variance of possible outcomes and graph the solutions to visualize the results for the entire time-sequence. However, I am struggling to set up the simulation and can't seem to find…
Mandy94
  • 37
  • 4
1
vote
1 answer

ODE doesn't find the parameters given dataframe unless I use "<-" and not "="

My ODE-model is given parameters from existing dataframes, but doesn't seem to find some of the parameters unless I use "<-" and not "=". In a recent question I posted for a different model I was corrected in the way I used "<-" and "=", so I am…
Mandy94
  • 37
  • 4
1
vote
2 answers

Sensitivity analysis for ODE with list as parameters - result gives standard deviation of 0

Note: Initial problem was "Sensitivity analysis for ODE with parameters that include lists", as the sensRange-function gave an error due to the lists passed in the parameters. The question evolved as the list-parameters were fixed but a different…
Mandy94
  • 37
  • 4
1
vote
1 answer

Consumer-resource model with dynamic growth rate in R with deSolve

I have the following 3 main pieces of code that first plots rainfall, then plots rainfall's effect on prey (resource) growth rate, then plots consumer-resource (herbivore-plant) dynamics using a constant growth rate. My goal is to implement the…
Clara
  • 13
  • 4