if (FALSE) {
# Simulate data based on a real dataset
# Formulas for each model
formulas <- list(lam=~elev, ds=~1, phi=~1)
# Sample sizes
design <- list(Mds=2912, J=6, Mpc=506)
# Model parameters
coefs <- list(lam = c(intercept=3, elev=-0.5),
ds = c(intercept=-2.5),
phi = c(intercept=-1.3))
# Survey durations
durs <- list(ds = rep(5, design$Mds), pc=runif(design$Mpc, 3, 30))
set.seed(456)
sim_umf <- simulate("IDS", # name of model we are simulating for
nsim=1, # number of replicates
formulas=formulas,
coefs=coefs,
design=design,
# arguments used by unmarkedFrameDS
dist.breaks = seq(0, 0.30, length.out=7),
unitsIn="km",
# arguments used by IDS
# could also have e.g. keyfun here
durationDS=durs$ds, durationPC=durs$pc, durationOC=durs$oc,
maxDistPC=0.5, maxDistOC=0.5,
unitsOut="kmsq")
# Look at the results
lapply(sim_umf, head)
# Fit a model
(mod_sim <- IDS(lambdaformula = ~elev, detformulaDS = ~1,
dataDS=sim_umf$ds, dataPC=sim_umf$pc,
availformula = ~1, durationDS=durs$ds, durationPC=durs$pc,
maxDistPC=0.5,
unitsOut="kmsq"))
# Compare with known parameter values
# Note: this is an unusually good estimate of availability
# It is hard to estimate in most cases
cbind(truth=unlist(coefs), est=coef(mod_sim))
# Predict density at each distance sampling site
head(predict(mod_sim, 'lam'))
}
Run the code above in your browser using DataLab