simulate-methods {unmarked}R Documentation

Methods for Function simulate in Package ‘unmarked’

Description

Simulate data from a fitted model.

Usage

## S4 method for signature 'unmarkedFitColExt'
simulate(object, nsim, seed, na.rm)
## S4 method for signature 'unmarkedFitDS'
simulate(object, nsim, seed, na.rm)
## S4 method for signature 'unmarkedFitMPois'
simulate(object, nsim, seed, na.rm)
## S4 method for signature 'unmarkedFitOccu'
simulate(object, nsim, seed, na.rm)
## S4 method for signature 'unmarkedFitOccuRN'
simulate(object, nsim, seed, na.rm)
## S4 method for signature 'unmarkedFitPCount'
simulate(object, nsim, seed, na.rm)
## S4 method for signature 'character'
simulate(object, nsim=1, seed=NULL, formulas, coefs=NULL,
  design, guide=NULL, ...)

Arguments

object

Fitted model of appropriate S4 class

nsim

Number of simulations

seed

Seed for random number generator. Not currently implemented

na.rm

Logical, should missing values be removed?

formulas

A named list of formulas, one per submodel (e.g. a formula for occupancy "state" and a formula for detection "det"). To get the correct submodel names for a given model, fit an example for that model, and then call names(fitted_model)

coefs

A named list of vectors of coefficients associated with the regression intercepts and slopes for each submodel. List should be named as with formulas above. Each element of the list should be a named vector, where the names correspond to the names of the parameters in the model (intercept and covariates). If you are not sure how to structure this list, just run simulate with coefs=NULL; this will generate a template list you can copy and fill in.

design

A named list of components of the study design. Must include at least M, the number of sites, and J the number of observations per site. If you are fitting a model with multiple primary periods you must also provide T, the number of primary periods.

guide

An optional list defining the format (continuous or categorical/factor) and distribution, if continuous, of covariates you want to simulate. By default all covariates are simulated from a standard normal. See example below for an example of how to specify entries in the guide list.

...

Additional arguments that are needed to fully specify the simulated dataset for a particular model. For example, mixture for pcount models or keyfun for distsamp models.

Methods

object = "unmarkedFitColExt"

A model fit by colext

object = "unmarkedFitDS"

A model fit by distsamp

object = "unmarkedFitMPois"

A model fit by multinomPois

object = "unmarkedFitOccu"

A model fit by occu

object = "unmarkedFitOccuRN"

A model fit by occuRN

object = "unmarkedFitPCount"

A model fit by pcount

object = "character"

An unmarkedFrame of the appropriate type

Examples


## Not run: 

# Simulation of an occupancy dataset from scratch

# Formulas for each submodel
# occupancy is a function of elevation, detection is intercept-only
forms <- list(state=~elev, det=~1)

# Specify list of coefficients - there must be a value for each
# covariate plus an intercept for each submodel
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

# If we don't specify coefs, unmarked will generate a template you can copy and use
simulate("occu", formulas=forms, design=design)

# Generate unmarkedFrameOccu
occu_umf <- simulate("occu", formulas=forms, coefs=coefs, design=design)
head(occu_umf) # note one covariate, elev

# What if we wanted to add a categorical/factor covariate or
# customize the distribution of elev?
# Use the guide argument

# Updated formulas with new covariate
forms2 <- list(state=~elev+landcover, det=~1)

# Guide
# landcover is factor, you must provide the levels
guide <- list(landcover=factor(levels=c("forest","grass")),  
              elev=list(dist=rnorm, mean=2, sd=0.5)) # custom distribution

# Updated coefficients list
coefs2 <- list(state=c(intercept=0, elev=-0.4, landcovergrass=0.2), det=c(intercept=0))

# Simulate new dataset
head(simulate("occu", formulas=forms2, coefs=coefs2, design=design, guide=guide))
# Note new categorical covariate

# For some models you may want to specify other arguments, such as 'mixture'
# for pcount or 'keyfun' for distsamp
# See the documentation for the associated fitting function and unmarkedFrame
# for what arguments are possible to include for a given model
head(simulate("pcount", formulas=forms, coefs=coefs, design=design, mixture="NB"))

## End(Not run)

[Package unmarked version 1.4.1 Index]