Learn R Programming

secr (version 4.6.10)

secr.test: Goodness-of-Fit Test

Description

Simple Monte-Carlo goodness-of-fit tests for full-likelihood SECR models. The approach is to calculate a statistic from either the raw data or a fitted model, and to relate this to the distribution of the statistic under the original fitted model. The distribution is estimated by simulating data from the model, and possibly re-fitting the model to each simulated dataset.

The suitability of different test statistics has yet to be assessed.

Usage

secr.test(object, nsim = 99, statfn, fit = FALSE, seed =
NULL, ncores = NULL, tracelevel = 1, ...)

Value

An object of class c('secrtest','list') with components:

object

as input

nsim

as input

statfn

as input

fit

as input

seed

as input

output

list comprising the simulated values, the observed value(s), and estimated probabilities

For multi-session input when fit = FALSE, `output' is a list in which each session provides one component.

Print and plot methods are provided for `secrtest' objects.

Arguments

object

a fitted secr model

nsim

integer number of replicates

statfn

function to compute a numeric vector of one or more statistics from a single-session `capthist' object or from a fitted model (see Details)

fit

logical; if TRUE the model is re-fitted to each simulated dataset

seed

either NULL or an integer that will be used in a call to set.seed

ncores

integer number of threads for parallel processing

tracelevel

see sim.secr

...

other arguments passed to statfn, if needed

Details

The test statistic(s) may be computed either on a dataset or on a fitted model, as determined by the argument fit. The single argument expected by statfn should be either a `capthist' object (fit = FALSE) or an `secr' object (fit = TRUE).

The default statistic when fit = FALSE is the proportion of individuals observed on only one occasion, which is equivalent to statfn = function(CH) c(f1 = sum(apply(abs(CH) > 0,1,sum) == 1) / nrow(CH)). Repeat detections on one occasion at the same or different detectors are not counted. The default statistic is therefore not appropriate for some data, specifically from `count' or `polygon' detectors with few occasions or only one.

The default statistic when fit = TRUE is the deviance divided by the residual degrees of freedom (i.e., statfn = function(object) c(devdf = deviance(object) / df.residual(object))).

The reported probability (p) is the rank of the observed value in the vector combining the observed value and simulated values, divided by (nsim + 1). Ranks are computed with rank using the default ties.method = "average".

Simulations take account of the usage attribute of detectors in the original capthist object, given that usage was defined and ignoreusage was not set.

Setting ncores = NULL uses the existing value from the environment variable RCPP_PARALLEL_NUM_THREADS (see setNumThreads).

statfn may return a vector of statistics for each observed or simulated dataset or model: then the value of each statistic will be calculated for every simulated dataset, and summarised. If fit = TRUE the vector of statistics may include both those computed on the raw data (object$capthist) and the fitted model.

See Also

print.secrtest, plot.secrtest, simulate.secr, sim.secr, deviance.secr

Examples

Run this code

if (FALSE) {

secr.test(secrdemo.0, nsim = 99)

secr.test(ovenbird.model.1, nsim = 20)

## example combining raw data summary and model fit
## assumes single-session
bothfn <- function(object) {
    CH <- object$capthist
    f1 <- sum(apply(abs(CH) > 0, 1, sum) == 1) / nrow(CH)
    devdf <- deviance(object) / df.residual(object)
    c(f1 = f1, devdf = devdf)
}
test <- secr.test (secrdemo.0, nsim = 19, statfn = bothfn, fit = TRUE)
test
plot(test, main = '')

}

Run the code above in your browser using DataLab