Learn R Programming

boral (version 0.4)

make.jagsboralmodel: Write a text file containing an boral model for use into JAGS

Description

This function is designed to write boral models with one or more latent variables.

Usage

make.jagsboralmodel(family, X.eff, site.eff, n, p, hypparams = c(100,100))

Arguments

family
Either a single element, or a vector of length equal to the number of columns in $y$. The former assumes all columns of $y$ come from this distribution. The latter option allows for different distributions for each column of $y$. Elements can be one of "b
X.eff
A logical value indicating whether covariates are to be included in the model.
site.eff
A logical value indicating whether to include row effects or not.
n
The number of rows in the response matrix $y$.
p
The number of columns in the response matrix $y$.
hypparams
Vector of 2 hyperparameters in the Bayesian estimation. The first hyperparameter is the variance for the normal priors of all coefficients i.e., row effects, column-specific intercepts, column-specific regression coefficients corresponding to all latent v

Value

  • A text file named "jagsboralmodel.txt" is created, containing the JAGS model to be called by the boral function for entering into jags. This file is automatically deleted once boral has finished running save.model = TRUE.

Details

This function is automatically executed inside boral, and therefore does not need to be run separately before fitting the boral model. It can however be run independently if one is: 1) interested in what the actual JAGS file for a particukar boral model looks like, 2) wanting to modify a basic JAGS model file to construct more complex model e.g., include environmental variables. Note however boral currently does not allow the user to manually enter a script to be run.

When running the main function boral, setting save.model = TRUE which automatically save the JAGS model file as a text file called "jagsboralmodel.txt" in the current working directory.

See Also

make.jagsboralnullmodel for writing boral models JAGS scripts with no latent variables (so-called "null models").

Examples

Run this code
library(mvtnorm)
library(mvabund) ## Load a dataset from the mvabund package
data(spider)
y <- spider$abun
n <- nrow(y); p <- ncol(y); 

## Create a boral model JAGS script, where distributions alternative 
## between Poisson and negative binomial distributions 
##   across the rows of y...cool!
make.jagsboralmodel(family = rep(c("poisson","negative.binomial"),length=n), 
	site.eff = TRUE, X.eff = FALSE, n, p)

## Create a boral model JAGS script, where distributions are all negative 
## 	binomial distributions and covariates will be included.
make.jagsboralmodel(family = "negative.binomial", 
	site.eff = FALSE, X.eff = TRUE, n, p)

## Simulate some ordinal data and create a JAGS model script
true.lv <- rbind(rmvnorm(10,mean=c(-2,-2)),rmvnorm(10,mean=c(2,2)))
## 20 rows (sites) with two latent variables 
true.lv.coefs <- rmvnorm(30,mean = rep(0,3)); 
## 30 columns (species)
true.lv.coefs[nrow(true.lv.coefs),1] <- -sum(true.lv.coefs[-nrow(true.lv.coefs),1])
## Impose a sum-to-zero constraint on the column effects
true.ordinal.cutoffs <- seq(-2,10,length=10-1)
## Cutoffs for proportional odds regression (must be in increasing order)

sim.y <- create.life(true.lv = true.lv, lv.coefs = true.lv.coefs, 
     family = "ordinal", cutoffs = true.ordinal.cutoffs) 

make.jagsboralmodel(family = "ordinal", X.eff = FALSE, site.eff = FALSE, n=20, p=30)

Run the code above in your browser using DataLab