Package 'nimbleJSextras'

Title: Aadditional Functions and Distributions For Bayesian Inference Of Jolly-Seber Models For The NIMBLE Package
Description: This package provides functions and simulation capability for modeling and testing code when analyzing capture-recapture data using Jolly-Seber type models.
Authors: Devin Johnson [aut, cre]
Maintainer: Devin Johnson <[email protected]>
License: CC0
Version: 0.1.9002
Built: 2026-10-13 23:34:41 UTC
Source: https://github.com/dsjohnson/nimbleJSextras

Help Index


Collapse all capture histories to only unique histories

Description

Collapse all individuals to unique histories and number of times each history occurs

Usage

collapse_ch(ch_matrix)

Arguments

ch_matrix

A matrix of capture histories where each row represents a single individual.


Hidden Markov Model distribution for binomial and Poisson capture histories

Description

Hidden Markov Model distribution for binomial and Poisson capture histories

Usage

dhmm_binom(x, init, prob, size, probTrans, len = 0, log = 0)

rhmm_binom(n, init, prob, size, probTrans, len = 0)

dhmm_pois(x, init, rate, probTrans, len = 0, log = 0)

rhmm_pois(n, init, rate, probTrans, len = 0)

Arguments

x

Vector of observed counts for an individual

init

Vector of initial state probabilities.

prob

2d array that is (length of x) x (number of states) which contains the probability of detection for each state at time t.

size

Vector of sizes for the binomial observation at each time.

probTrans

Time-dependent array of system state transition probabilities. Dimension of 'probTrans' is (number of possible system states) x (number of possible system states) x (number of occasions). 'probTrans[i,j,t]' is the probability that an individual truly in state i at time t will be in state j at time t+1.

len

Length of 'x'

log

Logical. Return log density

n

number of random draws, each returning a vector of length 'len'. Currently only 'n = 1' is supported, but the argument exists for standardization of 'rhmm_**' functions.

rate

A vector of rates for each time in the 'dhmm_pois' distribution function.


Jolly-Seber distributions For nimble models

Description

dJS_ms provides multistate Jolly-Seber (JS) distributions, dJS_binom provides binomial JS distributions for standard JS and robust design JS models. dJS_pois provides JS distributions for Poisson robust design, i.e., continuous-time secondary occasions. pstar_** functions calculate the overall probability of detection and are necessary for the JS model distributions.

Usage

dJS_ms(x, init, probObs, probTrans, pstar, weight = 1, len = 1, log = 0)

rJS_ms(n, init, probObs, probTrans, pstar = 0, weight = 1, len)

pstar_ms(init, probObs, probTrans, len)

dJS_binom(x, init, prob, size, probTrans, pstar, weight = 1, len = 0, log = 0)

rJS_binom(n, init, prob, size, probTrans, pstar = 0, weight = 1, len)

pstar_binom(init, prob, size, probTrans, len)

dJS_pois(x, init, rate, probTrans, pstar, weight = 1, len = 0, log = 0)

rJS_pois(n, init, rate, probTrans, pstar = 0, weight = 1, len)

pstar_pois(init, rate, probTrans, len)

Arguments

x

In dividual capture history

init

A vector of initial state probability vectors.

probObs

Time-dependent 3D array of observation probabilities. First two dimensions of 'probObs' are of size x (number of possible system states) x (number of possible observation classes) and the third dimension is the number of occasions. 'probObs[i, j ,t]' is the probability that an individual in the ith latent state is recorded as being in the jth detection state at time t.

probTrans

Time-dependent array of system state transition probabilities. Dimension of 'probTrans' is (number of possible system states) x (number of possible system states) x (number of occasions). 'probTrans[i,j,t]' is the probability that an individual truly in state i at time t will be in state j at time t+1.

pstar

Overall probability of detection. Calculated using the 'pstar_**' functions in nimble model code.

weight

The number of times the capture history occurs in the full data set of capture histories.

len

Length of 'x'

log

Logical. Return log-distribution.

n

number of random draws, each returning a vector of length 'len'. Currently only 'n = 1' is supported, but the argument exists for standardization of 'rJS_**' functions.

prob

For 'dJS_binom' this is a 2d array that is (number of occasions) x (number of states) which contains the probability of detection for each state at time t. For a standard robust design there are 3 states: prior to entry, entered, and exited. In this case the first and third column would contain all 0s.

size

A vector of the number of secondary occasions for each primary occasion in a robust design.

rate

A vector of detection rates for continuous-time secondary occasions in 'dJS_pois'. This should be proportional to the interval of time each secondary occasion was executed.


Sample states for undetected (not captured) individuals

Description

Sample states for undetected (not captured) individuals

Usage

sample_det_ms(x, init, probObs, probTrans)

sample_det_binom(x, init, prob, size, probTrans)

sample_det_pois(x, init, rate, probTrans)

Arguments

x

Observation sequence (capture-history) for an individual

init

A vector of initial state probabilities

probObs

Time-dependent 3D array of observation probabilities. First two dimensions of 'probObs' are of size x (number of possible system states) x (number of possible observation classes) and the third dimension is the number of occasions. 'probObs[i, j ,t]' is the probability that an individual in the ith latent state is recorded as being in the jth detection state at time t.

probTrans

Time-dependent array of system state transition probabilities. Dimension of 'probTrans' is (number of possible system states) x (number of possible system states) x (number of occasions). 'probTrans[i,j,t]' is the probability that an individual truly in state i at time t will be in state j at time t+1.

prob

For 'dJS_binom' this is a 2d array that is (number of occasions) x (number of states) which contains the probability of detection for each state at time t. For a standard robust design there are 3 states: prior to entry, entered, and exited. In this case the first and third column would contain all 0s.

size

A vector of the number of secondary occasions for each primary occasion in a robust design.

rate

A vector of detection rates for continuous-time secondary occasions in 'dJS_pois'. This should be proportional to the interval of time each secondary occasion was executed.


Sample states for undetected (not captured) individuals

Description

Sample states for undetected (not captured) individuals

Usage

sample_undet_ms(n = 1, init, probObs, probTrans)

sample_undet_binom(n = 1, init, prob, size, probTrans)

sample_undet_pois(n = 1, init, rate, probTrans)

Arguments

n

Integer number of individuals to generate samples. This returns a 'n' x (number of occasions) matrix of sampled states for individuals that were never captured.

init

A vector of initial state probabilities

probObs

Time-dependent 3D array of observation probabilities. First two dimensions of 'probObs' are of size x (number of possible system states) x (number of possible observation classes) and the third dimension is the number of occasions. 'probObs[i, j ,t]' is the probability that an individual in the ith latent state is recorded as being in the jth detection state at time t.

probTrans

Time-dependent array of system state transition probabilities. Dimension of 'probTrans' is (number of possible system states) x (number of possible system states) x (number of occasions). 'probTrans[i,j,t]' is the probability that an individual truly in state i at time t will be in state j at time t+1.

prob

For 'dJS_binom' this is a 2d array that is (number of occasions) x (number of states) which contains the probability of detection for each state at time t. For a standard robust design there are 3 states: prior to entry, entered, and exited. In this case the first and third column would contain all 0s.

size

A vector of the number of secondary occasions for each primary occasion in a robust design.

rate

A vector of detection rates for continuous-time secondary occasions in 'dJS_pois'. This should be proportional to the interval of time each secondary occasion was executed.


Simulation output object

Description

Simulation output object

Usage

sim_js_list

Fields

ch

A matrix of observed states for the simulated data (included all zero capture hostories as well)

true_states

A matrix of true states for the simulated data

observed

An indicator vector that shows which individuals were actually captured.


Simulate Traditional Jolly-Seber Capture-Recapture Data

Description

Simulate Traditional Jolly-Seber Capture-Recapture Data

Usage

simulate_js(N, xi, phi, p)

Arguments

N

Superpopulation size

xi

Vector of entry probabilities, not necessarily normalized (length = 'K').

phi

A 'K-1' vector of survival probabilities.

p

A 'K' vector of capture probabilities for when an individual is available for capture.


Simulate Multistate Jolly-Seber Capture-Recapture Data

Description

Simulate Multistate Jolly-Seber Capture-Recapture Data

Usage

simulate_multistate_js(N, xi, alpha, phi, psi, p)

Arguments

N

Superpopulation size

xi

Vector of entry probabilities, not necessarily normalized (length = 'K').

alpha

A matrix of initial state assignment probabilites upon entry (dim = 'J-2'x'K'). The total number of states including pre-birth and death is 'J'.

phi

A 'J-2'x'K-1' matrix of survival probabilities for each of the 'J-2' alive states

psi

A 'J-2'x'J-2'x'K-1' array where 'psi[,,t]' is the probability transition matrix between the 'J-2' alive states.

p

A 'J-2'x'O'x'K' array where 'p[i,j,t]' is the probability of making observation 'j' when the individual is in true state 'i' on occasion 't'. The number of observation states is 'O'. The observation states do not need to be directly related the the true states.