mu_critical: Calculate mu_critical

View source: R/mu_critical.R

mu_criticalR Documentation

Calculate mu_critical

Description

This function uses the full posterior distributions of parameters estimated by joint_model() to calculate mu_critical, or the expected catch rate at which the probabilities of a false positive eDNA detection and true positive eDNA detection are equal. See more examples in the Package Vignette.

Usage

mu_critical(model_fit, cov_val = NULL, ci = 0.9)

Arguments

model_fit

An object of class stanfit

cov_val

A numeric vector indicating the values of site-level covariates to use for prediction. Default is NULL.

ci

Credible interval calculated using highest density interval (HDI). Default is 0.9 (i.e., 90% credible interval).

Value

A list with median mu_critical and lower and upper bounds on the credible interval. If multiple gear types are used, a table of mu_critical and lower and upper credible interval bounds is returned with one column for each gear type.

Note

Before fitting the model, this function checks to ensure that the function is possible given the inputs. These checks include:

  • Input model fit is an object of class 'stanfit'.

  • Input credible interval is a univariate numeric value greater than 0 and less than 1.

  • Input model fit contains p10 parameter.

  • If model fit contains alpha, cov_val must be provided.

  • Input cov_val is numeric.

  • Input cov_val is the same length as the number of estimated covariates.

  • Input model fit has converged (i.e. no divergent transitions after warm-up).

If any of these checks fail, the function returns an error message.

Examples


# Ex. 1: Calculating mu_critical with site-level covariates

# Load data
data(goby_data)

# Fit a model including 'Filter_time' and 'Salinity' site-level covariates
fit_cov <- joint_model(data = goby_data, cov = c('Filter_time','Salinity'),
                       family = "poisson", p10_priors = c(1,20), q = FALSE,
                       multicore = FALSE)

# Calculate mu_critical at the mean covariate values (covariates are
# standardized, so mean = 0)
mu_critical(fit_cov$model, cov_val = c(0,0), ci = 0.9)

# Calculate mu_critical at habitat size 0.5 z-scores greater than the mean
mu_critical(fit_cov$model, cov_val = c(0,0.5), ci = 0.9)

# Ex. 2: Calculating mu_critical with multiple traditional gear types

# Load data
data(green_crab_data)

# Fit a model with no site-level covariates
fit_q <- joint_model(data = green_crab_data, cov = NULL, family = "negbin",
                     p10_priors = c(1,20), q = TRUE, multicore = FALSE)

# Calculate mu_critical
mu_critical(fit_q$model, cov_val = NULL, ci = 0.9)



eDNAjoint documentation built on June 21, 2025, 9:08 a.m.