Description Usage Arguments Details Value Author(s) References See Also Examples
View source: R/makejagsboralmodel.R
This function is designed to write models with one or more latent variables.
1 2 3 4 5 6 7 8 9 | make.jagsboralmodel(family, num.X = 0, X.ind = NULL, num.traits = 0,
which.traits = NULL, lv.control = list(num.lv = 2, type = "independent"),
row.eff = "none", row.ids = NULL, offset = NULL, trial.size = 1,
n, p, model.name = NULL,
prior.control = list(type = c("normal","normal","normal","uniform"),
hypparams = c(10, 10, 10, 30), ssvs.index = -1, ssvs.g = 1e-6,
ssvs.traitsindex = -1),
num.lv = NULL)
|
family |
Either a single element, or a vector of length equal to the number of columns in Please see |
num.X |
Number of columns in |
X.ind |
An matrix of 1s and 0s, indicating whether a particular covariate should be included (1) or excluded (0) in the mean structure of a particular response. The matrix should the number of rows equal to the number of columns in |
num.traits |
Number of columns in the model matrix |
which.traits |
A list of length equal to (number of columns in For example, if Defaults to |
lv.control |
A list (currently) with the following arguments:
Please see |
row.eff |
Single element indicating whether row effects are included as fixed effects ("fixed"), random effects ("random") or not included ("none") in the fitted model. If fixed effects, then for parameter identifiability the first row effect is set to zero, which analogous to acting as a reference level when dummy variables are used. If random effects, they are drawn from a normal distribution with mean zero and unknown standard deviation. Defaults to "none". |
row.ids |
A matrix with the number of rows equal to the number of rows in |
offset |
A matrix with the same dimensions as the response matrix |
trial.size |
Either equal to a single element, or a vector of length equal to the number of columns in y. If a single element, then all columns assumed to be binomially distributed will have trial size set to this. If a vector, different trial sizes are allowed in each column of y. The argument is ignored for all columns not assumed to be binomially distributed. Defaults to 1, i.e. Bernoulli distribution. |
n |
The number of rows in the response matrix |
p |
The number of columns in the response matrix |
model.name |
Name of the text file that the JAGS script is written to. Defaults to |
prior.control |
A list of parameters for controlling the prior distributions. These include:
|
num.lv |
Old argument superceded by |
This function is automatically executed inside boral
, and therefore does not need to be run separately before fitting the model. It can however be run independently if one is: 1) interested in what the actual JAGS file for a particular model looks like, 2) wanting to modify a basic JAGS model file to construct more complex model e.g., include environmental variables.
Please note that 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 (with name based on the model.name
) in the current working directory.
A text file is created, containing the 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
.
NA
Maintainer: NA
Gelman, et al. (2008). A weakly informative default prior distribution for logistic and other regression models. The Annals of Applied Statistics, 2, 1360-1383.
make.jagsboralnullmodel
for writing JAGS scripts for models with no latent variables i.e., so-called "null models".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | library(mvtnorm)
library(mvabund) ## Load a dataset from the mvabund package
data(spider)
y <- spider$abun
n <- nrow(y)
p <- ncol(y)
## Example 1 - Create a JAGS model file, where distributions alternative
## between Poisson and negative binomial distributions
## across the rows of y.
make.jagsboralmodel(family = rep(c("poisson","negative.binomial"),length=p),
row.eff = "fixed", num.X = 0, n = n, p = p)
## Example 2 - Create a JAGS model file, where distributions are all
## negative binomial distributions and covariates will be included.
make.jagsboralmodel(family = "negative.binomial", num.X = ncol(spider$x),
n = n, p = p)
## Example 3 - Simulate some ordinal data and create a JAGS model file
## 30 rows (sites) with two latent variables
true.lv <- rbind(rmvnorm(15,mean=c(-2,-2)),rmvnorm(15,mean=c(2,2)))
## 10 columns (species)
true.lv.coefs <- rmvnorm(10,mean = rep(0,3));
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)
simy <- create.life(true.lv = true.lv, lv.coefs = true.lv.coefs,
family = "ordinal", cutoffs = true.ordinal.cutoffs)
make.jagsboralmodel(family = "ordinal", num.X = 0,
row.eff = FALSE, n=30, p=10, model.name = "myawesomeordmodel.txt")
## Have a look at the JAGS model file for a model involving traits,
## based on the ants data from mvabund.
library(mvabund)
data(antTraits)
y <- antTraits$abun
X <- as.matrix(antTraits$env)
## Include only traits 1, 2, and 5, plus an intercept
traits <- as.matrix(antTraits$traits[,c(1,2,5)])
## Please see help file for boral regarding the use of which.traits
example_which_traits <- vector("list",ncol(X)+1)
for(i in 1:length(example_which_traits))
example_which_traits[[i]] <- 1:ncol(traits)
## Not run:
## NOTE: The values below MUST NOT be used in a real application;
## they are only used here to make the examples run quick!!!
example_mcmc_control <- list(n.burnin = 10, n.iteration = 100,
n.thin = 1)
fit_traits <- boral(y, X = X, traits = traits, which.traits = example_which_traits,
family = "negative.binomial", lv.control = list(num.lv = 2),
model.name = "anttraits.txt", mcmc.control = example_mcmc_control)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.