R/getEnvironCov.gllvm.R
getEnvironCov.gllvm.Rd
Calculates the species environment covariance matrix for a gllvm object.
# S3 method for class 'gllvm'
getEnvironCov(object, x = NULL, ...)
Function returns the following components:
species covariances due to covariates
trace of the covariance matrix due to random canonical coefficients
trace of the covariance matrix components due to squared model terms
trace of the covariance matrix due to random column (species) effects
Species covariance matrix due to the environment is calculated.
Covariances due to the covariates can only be calculated when random effects are included in the model, and are thus limited to reduced rank models (those including constrained and concurrent ordinations) fitted with random slopes, models fitted with random effects via the formula interface, or the fourth corner model fitted with random slopes. For full rank models with random slopes, i.e., with the formula interface or the fourth corner model, the covariances of species are formulated as:
$$\Sigma_e = kronecker(C\rho + (1-\rho)I_p, R),$$
where \(C\) is a correlation matrix for the columns in the response (e.g., a Phylogenetic matrix), \(\rho\) the signal parameter, and R the covariance matrix for the random effects. Here, $$I = kronecker(I_p, x)$$, with x a vector of covariate values for each of the random effects, which defaults to a vector of 1s. when there are covariate-specific phylogenetic signal parameters in the model, this is instead:
$$\Sigma_e = kronecker(x_i', I_m)*bdiag(L_k)*kronecker(\Sigma_r, I_m)*bdiag(L_k')*kronecker(x_i, I_m),$$
where \(bdiag(L_k)\) is a block-diagonal lower triangular matrix, and each \(L_k\) the lower triangular matrix of the covariance matrix for each covariate.
For reduced rank models, the covariance is separately defined for the different variance structures of the canonical coefficients in the package. With LV-specific variances, we have:
$$\Sigma_e = \Theta*S*\Theta',$$
where \(\Theta\) is the matrix of loadings, and S the (diagonal) covariance matrix for the canonical coefficients. With predictor-specific variances, we instead have:
$$\Sigma_e = \sum^K_{k=1} \Theta(I_d*\sigma_k^2)\Theta',$$
with I_d an identity matrix for the number of constrained and informed latent variables, and \(\sigma_k^2\) the variance per predictor for the canonical coefficients.
getEnvironCor
,getResidualCov.gllvm
, getResidualCor.gllvm
,.
if (FALSE) { # \dontrun{
# Example with the spider dataset
data(eSpider)
y = eSpider$abund[eSpider$nonNA,]
X = eSpider$X[eSpider$nonNA,]
fit <- gllvm(y, X = scale(X), num.RR = 2,
randomB = "P", family = "negative.binomial")
envcov <- getEnvironCov(fit)
envcov$trace.randomB
# As proportion of variance in the model
envcov$trace.randomB/sum(envcov$trace.randomB)
} # }