[R] stochastic growth rate (package popbio)
Chris Stubben
stubben at lanl.gov
Mon Jan 14 18:24:48 CET 2008
privalan wrote:
>
> However, I cannot figure out the way to compute the asymptotic stochastic
> population growth rate using “popbio”. I would like to perform a
> stochastic model in which my demographic rates are sampled from beta
> distribution with known mean and SD. For example, rather than 0.50 (4th
> term of my matrix), I want to sample this parameter from a beta function
> at each time-step {e.g., betaval(0.5, 0.05)}.
>
I guess you can't do this right now, but it shouldn't be too difficult to
add an option to accept an expression as input to stoch.growth.rate or
stoch.projection in the next version of popbio.
Maybe this will get you started.
A<-expression(c(0.70, 0.70,0.35, betaval(0.5, 0.05)))
## stoch.growth.rate(A) ## this doesn't work yet, so try...
matrix(eval(A), nrow=2,byrow=TRUE)
## code from simulation section in stoch.growth.rate
## just replace A with matrix(eval(A), nrow=2,byrow=TRUE)
maxt<-10000
r<-numeric(maxt)
n0<-c(1,1)
for (t in 1:maxt)
{
n0<- matrix(eval(A), nrow=2,byrow=TRUE) %*% n0
N<-sum(n0)
r[t]<-log(N)
n0<-n0/N
}
loglsim<-mean(r)
dse<-1.96*sqrt(var(r)/maxt)
CI<-c(loglsim-dse, loglsim+dse)
loglsim
#[1] 0.09982282
CI
#[1] 0.0994700 0.1001757
# check
eigen.analysis( matrix(c(0.70, 0.70,0.35,0.50), nrow=2,byrow=TRUE))$lambda1
exp(loglsim)
Thanks,
Chris
--
View this message in context: http://www.nabble.com/stochastic-growth-rate-%28package-biopop%29-tp14800951p14806622.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list