[R] Arms Race

Thomas Petzoldt thpe at simecol.de
Mon Nov 10 07:47:03 CET 2008


dennis campos wrote:
 > hey can anybody help me? i have to simulate the richardson Arms race 
model on R.. for my simulation class...

Hi Dennis,

this list is not intended for solving your homework, however, the 
following may help you to go one step ahead.

You should have a look into the help pages of packages deSolve and/or 
simecol. Please find below the (IMHO rather elegant) simecol 
implementation but beware, your professor might expect the "basic" 
deSolve style, so be prepared about discussing both. And, don't forget 
to read the background.

## deSolve #####################
library(deSolve)
? ode

## simecol #####################

library(simecol)

## open the directory with R sourcecode examples
browseURL(paste(system.file(package="simecol"), "/examples", sep=""))

.... and modify the example lv.R


Thomas P.

##############################################################
library("simecol")

armsrace <- new("odeModel",
   main = function (time, init, parms) {
     x <- init[1]
     y <- init[2]
     with(as.list(parms), {
       dx <- a * y - m * x + r
       dy <- b * x - n * y + s
       list(c(dx, dy))
     })
   },
   parms  = c(a=2, m=5, r=5, b=2, n=3,  s=5),
   times  = c(from=0, to=10, by=0.5),
   init   = c(x=0.5, y=1),
   solver = "lsoda"
)

ar1 <- ar2 <- ar3 <- ar4 <- armsrace

parms(ar2) <- c(a=2, m=1, r=3, b=2, n=2, s=3)
parms(ar3) <- c(a=1, m=4, r=-1, b=1, n=1, s=-2)
parms(ar4) <- c(a=2, m=1, r=-3, b=2, n=1, s=-3)

ar1 <- sim(ar1); plot(ar1)
ar2 <- sim(ar2); plot(ar2)
ar3 <- sim(ar3); plot(ar3)
ar4 <- sim(ar4); plot(ar4)



More information about the R-help mailing list