Gibbs Samplers

GibbsBase

Base class for Gibbs samplers of species spatial occupancy models.

LogitICARGibbs

Gibbs sample using logit link and ICAR model for spatial random effects.

LogitRSRGibbs

Gibbs sampler using logit link and RSR model for spatial random effects.

ProbitRSRGibbs

Sampler using probit link and RSR model for spatial random effects.

Base Sampler

class occuspytial.gibbs.base.GibbsBase(Q, W, X, y, hparams=None, random_state=None)[source]

Base class for Gibbs samplers of species spatial occupancy models.

Parameters
Qnp.ndarray

Spatial precision matrix of spatial random effects.

WDict[int, np.ndarray]

Dictionary of detection corariates where the keys are the site numbers of the surveyed sites and the values are arrays containing the design matrix of each corresponding site.

Xnp.ndarray

Design matrix of species occupancy covariates.

yDict[int, np.ndarray]

Dictionary of survey data where the keys are the site numbers of the surveyed sites and the values are number arrays of 1’s and 0’s where 0’s indicate “no detection” and 1’s indicate “detection”. The length of each array equals the number of visits in the corresponding site.

hparams{None, Dict[str, Union[float, np.ndarray]}, optional

Hyperparameters of the occupancy model. valid keys for the dictionary are:

  • a_mu: mean of the normal prior of detection covariates.

  • a_prec: precision matrix of the normal prior of detection covariates.

  • b_mu: mean of the normal prior of occupancy covariates.

  • b_prec: precision matrix of the normal prior of occupancy covariates.

  • tau_rate: rate parameter of the Gamma prior of the spatial parameter.

  • tau_shape: shape parameter of the Gamma prior of the spatial parameter.

random_state{None, int, numpy.random.SeedSequence}

A seed to initialize the bitgenerator.

Attributes
chainChain

Posterior chain object. An instance of occuspytial.chain.Chain

distsFixedState

Container for conditional probability distribution instances of posterior parameters.

fixedFixedState

A Container for fixed values and parameters who’s values remain constant during sampling. This variable must be an instance of FixedState.

rngnumpy.random.Generator

Instance of numpy’s Generator class, which exposes a number of random number generating methods.

stateState

A container to store model parameter values and other variables whose values change at various stages during sampling.

copy()[source]

Create a copy of this classes’s instance.

Returns
outself

A copy of this object’s instance with the same attribute values.

sample(size, burnin=0, start=None, chains=2, progressbar=True)[source]

Obtain posterior samples of the parameters of interest.

Only parameters {alpha, beta, tau} are stored after sampling, meaning the conditional detection and occupancy covariate coefficients, plus the posterior spatial parameter \(\\tau\) .

Parameters
sizeint

The number of total samples to generate.

burninint, optional

The number of initial samples to discard as “burnin” samples. burnin must be less than size.

start{None, Dict[str, np.ndarray]}, optional

Starting values of the parameters alpha, beta, tau and eta.

chainsint, optional

Number of chains to generate in parallel. Defauls to 1.

progressbarbool, optional

Whether to display the progress bar during sampling. Defaults to True.

Returns
outPosteriorParameter

Posterior samples of the parameters of interest.

Raises
ValueError

If the burnin values is larger than the number of samples requested or when the number of chains is not a positive integer.

step()[source]

Step through one iteration of the sampler.

This method should execute the parameter update steps the Gibbs sampler should take in order to complete one iteration of the sampler.

Raises
NotImplementedError

If sample method is called but subclass does not implement a step method.