lv3                 package:simecol                 R Documentation

_L_o_t_k_a-_V_o_l_t_e_r_r_a-_T_y_p_e _M_o_d_e_l _w_i_t_h _R_e_s_o_u_r_c_e, _P_r_e_y _a_n_d _P_r_e_d_a_t_o_r

_D_e_s_c_r_i_p_t_i_o_n:

     'simecol' example: predator prey-model with three equations:
     predator, prey and resource (e.g. nutriens, grassland).

_U_s_a_g_e:

     data(lv3)

_F_o_r_m_a_t:

     A valid S4 object according to the 'odeModel' specification.  The
     object contains the following slots:


     '_m_a_i_n' Lotka-Volterra equations for predator prey and resource.

     '_p_a_r_m_s' Vector with named parameters of the model:

          '_c' growth rate of the prey population,

          '_d' encounter rate of predator and prey,

          '_e' yield factor (allows conversion with respect to 'd'),

          '_f' death rate of the predator population,

          '_g' recycling parameter.


     '_i_n_p_u_t_s' Time series specifying external delivery of resource.

     '_t_i_m_e_s' Simulation time and integration interval.

     '_i_n_i_t' Vector with start values for 's', 'p' and 'k'.

          '_s' Resource (e.g. grassland or phosphorus).

          '_p' Producer (prey).

          '_k' Consumer (predator).


     '_s_o_l_v_e_r' Character string specifying the integration method.

_S_e_e _A_l_s_o:

     'simecol-package', 'sim', 'parms', 'init', 'times'.

_E_x_a_m_p_l_e_s:

     ##============================================
     ## Basic Usage:
     ##   explore the example
     ##============================================
     data(lv3)
     plot(sim(lv3))
     solver(lv3) <- "lsoda"
     times(lv3)["by"] <- 5  # set maximum external time step to a large value
     plot(sim(lv3))         # wrong! automatic time step overlooks internal inputs
     plot(sim(lv3, hmax=1)) # integration with correct maximum internal time step
         
     ##============================================
     ## Implementation:
     ##   The code of the model
     ##============================================
     lv3<- new("odeModel",
       main = function(time, init, parms) {
         x <- init
         p <- parms

         s <- x[1] # substrate
         p <- x[2] # producer
         k <- x[3] # consumer
         input <- approxTime1(inputs, time, rule=2)
         with(as.list(parms),{
           s.in <- input["s.in"]
           ds <- s.in  - b*s*p + g*k
           dp <- c*s*p - d*k*p
           dk <- e*p*k - f*k
           res<-c(ds, dp, dk)
           list(res)
         })
       },
       parms = c(b=0.1, c=0.1, d=0.1, e=0.1, f=0.1, g=0),
       times  = c(from=0, to=200, by=1),
       inputs = as.matrix(
         data.frame(
           time = c(0,   99, 100,  101, 200),
           s.in = c(0.1, 0.1, 0.5, 0.1, 0.1)
         )
       ),
       init = c(s=1, p=1, k=1),
       solver = "rk4"
     )

