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.)