poccupy: Occupancy Probability Calculations

View source: R/poccupancy.R

poccupyR Documentation

Occupancy Probability Calculations

Description

Predicts occupancy probability given a draw of loadings and (random) covariate loadings. The draw would typically be either (a) from the full posterior of a fitted model, which includes fitted values for the random covariate loadings or (b) drawn from the posterior of the loadings with random covariates simulated.

Usage

poccupy(fit, usethetasummary = NULL, ...)

Arguments

fixedcovar

An array of occupancy covariate values. Each row is a model site, each column is a covariate.

loadfixed

An array of loadings for the covariates in 'fixedcovar'. Each row is a species, each columns is a covariate (in same order as in fixedcovar), and each layer is a draw from the distribution of loadings.

randomcovar

An array of occupancy covariate values that samples the distribution of the covariate. Each row is a model site, each column a covariate, and each layer is a draw.

loadrandom

An array of loadings for 'randomcovar'. Each row is a species, each column a covariate, each layer a draw from the covariate distribution, and must be the same draw as loadfixed.

Value

An array of occupancy probability values. Each row is a modelsite, each column a species, each layer a draw corresponding to the loadings.

Examples

fixedcovar <- matrix(rnorm(10 * 5), nrow = 10, ncol = 5,
                     dimnames = list(paste0("Site", LETTERS[1:10]), paste0("C", letters[1:5])))
loadfixed <- array(unlist(lapply(seq(0, 12, by = 1), function(x) rnorm(7 * 5, x))), dim = c(7, 5, 12), #each layer has a larger mean
                   dimnames = list(paste0("Species", LETTERS[1:7]), paste0("C", letters[1:5]), paste0("LfD", 1:12)))
poccupy_raw.jsodm(fixedcovar, loadfixed)

fitold <- readRDS("../Experiments/7_4_modelrefinement/fittedmodels/7_4_13_allhyp_vif_logwoody500m_msnm_year_Time_Wind.rds")
fit <- translatefit(fitold)
poccupy.jsodm(fit)


randomcovar <- array(rnorm(10 * 2), dim = c(10, 2, 12),
                      dimnames = list(paste0("Site", LETTERS[1:10]), paste0("C", letters[1:2]), paste0("RcD", 1:12)))
loadrandom <- array(unlist(lapply(seq(0, 0.3, by = 0.01), function(x) rnorm(7 * 2, x, sd = 0.01))), dim = c(7, 2, 12), #each layer has a larger mean
                    dimnames = list(paste0("Species", LETTERS[1:7]), paste0("C", letters[1:2]), paste0("LrD", 1:12)))
pocc <- poccupy_raw.jsodm_lv(fixedcovar, loadfixed, randomcovar, loadrandom)
model2lv <- readRDS("../Experiments/7_4_modelrefinement/fittedmodels/7_4_13_model_2lv_e13.rds")
model2lv_new <- translatefit(model2lv)
pocc <- poccupy_raw.jsodm_lv(fixedcovar, loadfixed, randomcovar, loadrandom)
pocc <- poccupy.jsodm_lv(model2lv_new, lvvfromposterior = FALSE)


sustainablefarms/msod documentation built on March 6, 2023, 7:17 a.m.