if (FALSE) {
# Simulate an occupancy dataset
# Covariates to include in simulation
forms <- list(state=~elev, det=~1)
# Covariate effects and intercept values
coefs <- list(state=c(intercept=0, elev=-0.4), det=c(intercept=0))
# Study design
design <- list(M=300, J=8) # 300 sites, 8 occasions per site
# Simulate an unmarkedFrameOccu
occu_umf <- simulate("occu", formulas=forms, coefs=coefs, design=design)
# Fit occupancy model to simulated data
# This will contain all the model structure info powerAnalysis needs
# The estimates from the model aren't used
template_model <- occu(~1~elev, occu_umf)
# If we run powerAnalysis without specifying coefs we'll get a template list
powerAnalysis(template_model)
# Set desired effect sizes to pass to coefs
effect_sizes <- list(state=c(intercept=0, elev=-0.4), det=c(intercept=0))
# Run power analysis and look at summary
(pa <- powerAnalysis(template_model, coefs=effect_sizes, alpha=0.05))
# Try a smaller sample size in the study design
(pa2 <- powerAnalysis(template_model, coefs=effect_sizes, alpha=0.05,
design=list(M=100, J=2)))
}
Run the code above in your browser using DataLab