BC
is the main function for running BayesComm models.
It is a wrapper function for BCfit
; it checks inputs, sets up the model types and specifies a number of default BCfit
settings.
BC(Y, X = NULL, model = "null", covlist = NULL, condition = NULL, its = 100, ...)
BCfit
bayescomm
containing the model call and parameter chains which can be viewed and manipulated using window
, plot
, print
and summary
.
Y
must be a matrix with records as rows and species as columns and X
a matrix with records as rows and covariates as columns.
model
must be one of: "null"
(intercept only), "environment"
(intercept & covariates), "community"
(intercept & community matrix) or "full"
(intercept, covariates & community matrix).
covlist
must have the same length as the number of species with, each element a vector of column indices for X
. covlist
defaults to NULL
, which includes all covariates for all species.
For more details of arguments for model fitting see BCfit
. condition
is an optional matrix of conditioning variables.
These are fitted in the same way as X
but are not removed in null and community models.
BCfit
# create fake data
n <- 100
nsp <- 4
k <- 3
X <- matrix(c(rep(1, n), rnorm(n * k)), n) # covariate matrix
W <- matrix(rnorm(nsp * nsp), nsp)
W <- W %*% t(W) / 2 # true covariance matrix
B <- matrix(rnorm(nsp * (k + 1), 0, 3), nsp) # true covariates
mu <- apply(B, 1, function(b, x) x %*% b, X) # true mean
e <- matrix(rnorm(n * nsp), n) %*% chol(W) # true e
z <- mu + e # true z
Y <- ifelse(z > 0, 1, 0) # true presence/absence
# run BC (after removing intercept column from design matrix)
m1 <- BC(Y, X[, -1], model = "full", its = 100)
Run the code above in your browser using DataLab