0

I'm running an individual-based simulation in which each individual is governed by a stochastic variable mort_rate. N number of mort_rate may be randomized as a function of 2 parameters: mort_distr(N, parm1, parm2). Here, for the purpose of illustration,

mort_distr <- function(N, parm1, parm2)

{
  v    <- rnorm(n=N, mean=parm1)
  mort <- v * exp(1./parm2)

  data.frame(id=1:N,
             mort=mort,
             parm1=parm1,
             parm2=parm2)
}

So,

> mort_distr(N=3, parm1=2., parm2=10.)
  id     mort parm1 parm2
1  1 1.908670     2    10
2  2 5.351502     2    10
3  3 2.440259     2    10

My question is: in order to cut down computational time, how do I pre-generate a 3D look-up table in R that includes N=500 samples of mort_rate for each combination of parm1 and parm2, varying from seq(0.,4.,0.2) and seq(5.,10.,1.), respectively? In other words, I wish to have a table mort_tab that allows me to rapidly sample mort_rate based on known parameters simply by running, e.g. mort_tab(1.,9.)

neither-nor
  • 1,245
  • 2
  • 17
  • 30
  • 1
    Sounds like you could just use `outer(seq(0.,4.,0.2), seq(5.,10.,1.), mort_distr)`. It would be helpful to have a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jun 20 '18 at 18:41
  • 2
    @G5W I think they're asking for 500 samples per pair of parameters since `mort_rate` is stochastic. – Dan Jun 20 '18 at 18:46
  • @Lyngbark You are correct. – neither-nor Jun 20 '18 at 18:48
  • @MrFlick Thank you for the helpful suggestion. I've now edited my question to include a reproducible example. – neither-nor Jun 20 '18 at 19:26

0 Answers0