Free Access Week - Data Engineering + BI
Data Engineering and BI courses are free this week!
Free Access Week - Jun 2-8

boral (version 0.4)

get.hpdintervals: Highest posterior density intervals for an boral model

Description

Calculates the lower and upper bounds of the highest posterior density intervals for parameters and latent variables in a fitted boral model.

Usage

get.hpdintervals(y, X = NULL, fit.mcmc, num.lv)

Arguments

y
The response matrix that the boral model was fitted to.
X
The model matrix used in the boral model. Defaults to NULL, in which case it is assumed no model matrix was used.
fit.mcmc
All MCMC samples for the fitted boral model, as obtained from JAGS. These can be extracted by fitting an boral model using boral with save.model = TRUE, and the applying as.mcmc on t
num.lv
The number of latent variables used in the boral model. If zero, then HPD intervals will not be produced for latent variables.

Value

  • lv.coefs.hpd.lower/upperTwo matrices corresponding to the lower and upper bounds of the HPD intervals for the column-specific intercepts, regression coefficients relating to the latent variables, and dispersion parameters.
  • lv.hpd.lower/upperTwo matrices corresponding to the lower and upper bounds of the HPD intervals for the latent variables.
  • site.coefs.hpd.lower/upperTwo matrices corresponding to the lower and upper bounds of the HPD intervals for row effects.
  • X.coefs.hpd.lower/upperTwo matrices corresponding to the lower and upper bounds of the HPD intervals for regression coefficients relating to the model matrix X.
  • cutoffs.hpd.lower/upperTwo vectors corresponding to the lower and upper bounds of the HPD intervals for common cutoffs in proportional odds regression.
  • powerparam.hpd.lower/upperTwo scalars corresponding to the lower and upper bounds of the HPD interval for common power parameter in tweedie regression.

Warnings

  • HPD intervals tend to be quite wide, and inference is somewhat tricky with them. This is made more difficult by the multiple comparison problem due to the construction one interval for each parameter!
  • Be very careful with interpretation of coefficients and HPD intervals if different columns of$y$have different distributions!
  • HPD intervals for the cutoffs in proportional odds regression may be poorly estimated for levels with few data.

Details

The function uses the HPDinterval function from the coda package to obtain the HPD intervals. See HPDinterval for details regarding the defintion of the HPD interval.

Examples

Run this code
library(mvabund) ## Load a dataset from the mvabund package
data(spider)
y <- spider$abun
n <- nrow(y); p <- ncol(y); 
    
## Example 1 - model with two latent variables, site effects, 
## 	and no environmental covariates
spider.fit.nb <- boral(y, family = "negative.binomial", num.lv = 2, 
     site.eff = TRUE, save.model = TRUE)

## Returns a list with components corresponding to values described above.
spider.fit.nb$hpdintervals 

## Example 2 - model with one latent variable, site effects, 
## 	and environmental covariates
spider.fit.nb2 <- boral(y, X = spider$x, family = "negative.binomial", num.lv = 1, 
     site.eff = TRUE, save.model = TRUE)

## Returns a list with components corresponding to values described above.
spider.fit.nb2$hpdintervals

Run the code above in your browser using DataLab