# simulate dynamics, with r=1, d=0, and d_sd=0.1
xtout<-symdyn(r=1, f=1, d=0, d_sd=0.1, sf=0.1, tmax=100)
# abundance in current time step
x0<-xtout$state[1:(nrow(xtout)-1)]
# abundance at t+1
x1<-xtout$state[2:nrow(xtout)]
dt<-diff(xtout$time)
ndist<-xtout$disturbed[-1]
# fit model - note square root transform of response variable,
# and log transform of parameter values
mod<-nls(sqrt(x1^2)~sqrt(xt2fun(x0, r=exp(lr), d=0, d_sd=exp(ld_sd), dt, ndist)),
start=c(lr=log(1), ld_sd=log(0.1)))
exp(coef(mod)) # model estimates
Run the code above in your browser using DataLab