Return to site

R Lotka Volterra

broken image


Lotka-Volterra ( Predator prey) We consider time-dependent growth of a species whose population size will be represented by a function x(t) (say green ies!). If we assume the food supply of this species is unlimited it seems reasonable that the rate of growth of this population would be proportional to the current population. This paper is concerned with traveling wavefronts in a Lotka- Volterra model with nonlocal delays for two cooperative species. By using comparison principle, some existence and nonexistence results are obtained.

In this post, I'll explore using R to analyze dynamical systems. Using the Lotka-Volterra predator prey model as a simple case-study, I use the R packages deSolve to solve a system of differential equations and FME to perform a sensitivity analysis.

Lotka-Volterra model

The Lotka-Volterra model describes the dynamics of a two-species system in which one is a predator and the other is its prey. The equations governing the dynamics of the prey (with density (x) and predator (with density (y)) are:

Slots avion. [begin{aligned} frac{dx}{dt} & = alpha x - beta xy frac{dy}{dt} & = delta beta xy - gamma y end{aligned}]

where (alpha) is the (exponential) growth rate of the prey in the absence of predation, (beta) is the predation rate or predator search efficiency, (delta) describes the predator food conversion efficiency, and (gamma) is the predator mortality.

Solving the ODE

Given a set of initial conditions and parameter estimates, deSolve::ode() can be used to evolve a dynamical system described by a set of ODEs. I start by defining parameters, as a named list, and the initial state, as a vector. For the initial state, it is the order that matters not the names.

Next, I need to define a function that computes the derivatives in the ODE system at a given point in time.

The vignette for FME suggets rolling all this into a function as follows. This function will become the input for the FME sensitivity analysis.

The ouput of ode() is a matrix with one column for each state variable. I convert this to a data frame and plot the evolution of the system over time.

Lotka Volterra Variables

This choice of paramters leads to periodic dynamics in which the prey population initially increases, leading to an abundance of food for the predators. The predators increase in response (lagging the prey population), eventually overwhelming the prey population, which crashes. This in turn causes the predators to crash, and the cycle repeats. The period of these dynamics is about 15 seconds, with the predators lagging the prey by about a second.

R Lotka-volterra

Sensitivity analysis

A sensitivity analysis examines how changes in the parameters underlying a model affect the behaviour of the system. It can help us understand the impact of uncertainty in parameter estimates. The FME vignette covers two types of sensitivity analyses: global and local.

Global sensitivity

According to the FME vingette, in a global sensitivity analysis certain parameters (the sensitivity parameters) are varied over a large range, and the effect on model output variables (the sensitivity variables) is measured. To accomplish this, a distribution is defined for each sensitivity parameter and the model is run multiple times, each time drawing values for the sensistivity parameters from their distribution. The sensitivity variables are recorded for each iteration over a range of times. The function sensRange() carries out global sensitivity analyses.

I'll look at the sensitivity of the populations to the growth rate ((alpha)) and the predation rate ((beta)). Defining the sensitivity parameter distributions requires providing a data frame in which the first column is the minimum value, the second column the maximum, and the row names are the parameter names.

Now I use sensRange() to solve the models over the range of parameters. The argument dist = 'grid' sets the sensitivity parameter distribution to a regular grid of values, sensvar defines which variables are the sensitivity variables (i.e. the ones whose time series will be returned in the output), num is the number of iterations and therefore the number of different sensistivity parameter values (note that if there are (k) sensitivity parameters, num must have an integer (k)th root), and times is the time series over which to evaluate the model.

The output of this function is a data frame with rows corresponding to the different sensitivity parameter values and columns corresponding to the combination of time steps and sensitivity variables. So, for n time steps, there are n columns for each sensitivity variable. First I run a simple sensitivity analysis to aid examination of the output.

Here variables such as x0.5 refer to the values of (x) at (t=0.5). FME provides a plot() method for sensRange objects, which adds envelopes to the variables showing the range and mean ± standard deviation. Now I run a more realistic sensitivity analysis and produce the plots. Note that summary() must be called before plot() to get the desired plots.

R Lotka Volterra

To actually work with these data, I'll transform the data frame from wide to long format using tidyr. gather() converts from wide to long format, then separate() splits column names x1.5 into two fields: one identifying the variable (x) and one specifying the time step (1.5).

Now, I can, for example, recreate the above plot with ggplot2. First, I summarize the data to calculate the envelopes, then I plot.

In this format, it's also easy to fix one of the values for a sensitivity parameter and only vary the other one.

Local sensitivity analysis

According to the FME vingette, in a local sensitivity analysis, 'the effect of a parameter value in a very small region near its nominal value is estimated'. The method used by FME is to calculate a matrix of sensitivity functions, (S_{i,j}), defined by:

R Lotka Volterra
Volterra

To actually work with these data, I'll transform the data frame from wide to long format using tidyr. gather() converts from wide to long format, then separate() splits column names x1.5 into two fields: one identifying the variable (x) and one specifying the time step (1.5).

Now, I can, for example, recreate the above plot with ggplot2. First, I summarize the data to calculate the envelopes, then I plot.

In this format, it's also easy to fix one of the values for a sensitivity parameter and only vary the other one.

Local sensitivity analysis

According to the FME vingette, in a local sensitivity analysis, 'the effect of a parameter value in a very small region near its nominal value is estimated'. The method used by FME is to calculate a matrix of sensitivity functions, (S_{i,j}), defined by:

[S_{i,j} = f(v_i, p_i) = frac{dv_i}{dp_j} frac{s_{p_j}}{s_{v_i}}]

where (v_i) is a sensitivity variable (i) (which is dependent on time (t)), (p_j) is sensitivity parameter (j), and (s_{v_i}) and (s_{p_j}) are scaling factors for variables and parameters, respectively. By default, FME takes the scaling values to be equal to the underlying quantities, in which case the above equation simplifies to:

[S_{i,j} = f(v_i, p_i) = frac{dv_i}{dp_j} frac{p_j}{v_i}]

The function sensFun() is used to numerically estimate these sensitivity functions at a series of time steps. The arguments sensvar and senspar are used to define which variables and parameters, respectively, will be investigated in the sensitivity analysis. By default, all variables are parameters are included. The arguments varscale and parscale define the scaling factors; however, for now, I'll leave them blank, which sets them to the underlying quantities as in the above equation.

In practice, sensFun() works by applying a small perturbation, (delta_j), to parameter (j), solving the model for a range of time steps to determine (v_i), then taking the ratio of the changes to the parameters and variables. The perturbation is defined by the argument tiny as (delta_j = text{max}(tiny, tiny * p_j)). tiny defaults to (10^{-8}).

Typical running back build with above average bulk relative to average height. Not the frame of a big back but enough space to get to 200-plus with relative ease. Athletic playmaker with impressive. Slot Running Back casino games on the Web, we have compiled a selection of the Slot Running Back best online casinos for US players. This selection is based on promotions, bonuses, security, cash out options, reputation, software robustness, graphics, customer service, game diversity and the overall respect of the player. Slot Running Back affiliate program will be determined by the number of first-time depositors Slot Running Back of the previous month, and this will be summarized from all the casinos you market. However, Slot Running Back the net revenue will be calculated separately for. Fullbacks are considered Running Backs in the game. The maximum number of starters at the RB slot is eight. Running Back/Wide Receiver (RB/WR): If this utility slot is selected, team managers have. The third option is the Running Back on the Wheel route. In practice, drill it into your QBs that it's better to over throw the receiver instead of under throwing him. If the Wheel route is covered, the final read is going back to the Slot in the middle or finding the Center.

To test that sensFun() is doing what I think it is, I'll implement a version of it. For simplicity, I'll only consider the variable (x) (prey density):

Now I compare this implementation to the actual results.

A perfect match! Now that I know what sensFun() is actually doing, I'll put it to use to solve the original LV model. One difference here is that I'll consider both variables as sensitivity variables and the results for each variable will be stacked rowwise. In addition, in the FME documentation, (s_{v_i}) is set to 1, which is on the order of the actual variable values, but has the benefit of being constant over time. I'll do the same here.

summary() can be used to summarize these results over the time series, for example, to see which parameters the model is most sensitive too.

(gamma) (predator mortality rate) and (beta) (predator search efficiency) have the largest values for the sensitivity function, on average, suggesting that this model is most sensitive to these parameters. There is also plot method for the output of sensFun(), which plots the sensitivity functions as time series.

Lotka Volterra Competition Model Example

However, it's also possible to use ggplot2 provided I transpose the data to long format first.

Clearly this model is particularly sensitive to (gamma). Furthermore, this sensitivity shows peaks every 16 seconds or so, which is the periodicity of the original dynamics. To see what's going on here, I'll take a look at what happens to the two species when I increase (gamma) by 1%:

Increasing (gamma) leads to a time dependent period to the dynamics. As a result, the two models initially overlap, but they become increasingly out of sync over time. This explains both the periodicity of the sensitivity function and the increasing amplitude.

Lotka Volterra Equation Explained

Related





broken image