Calculates the species environment covariance matrix for a gllvm object.
# S3 method for gllvm
getEnvironCov(object, x = NULL, relative = TRUE, ...)
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
an object of class 'gllvm'.
(optional) vector of covariate values to calculate the covariance for. Defaults to a vector of 1s. If both 'randomX' and random species effects are present in the model this should be a list of length two.
defaults to TRUE. For getEnvironCor
, if there are residual latent effects in the model (such as due to num.lv or num.lv.c), this scales the covariance matrix by the sum of the environmental and residual variances instead, so that the diagonal of the correlation matrix is smaller than one. This matrix then represents the contribution of the environment to the overall species associations in the model.
arguments passed on to getResidualCov.gllvm
Bert van der Veen
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 and without correlations, 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. When correlations are included, we have:
$$\Sigma_e = kronecker(x_i', I_m)kronecker(\Sigma,\Theta\Theta')kronecker(x_i, I_m),$$
and similarly for LV-specific variances with correlations. Expressions for the quadratic models in the package are determined similarly but not documented here for brevity.
getEnvironCor
,getResidualCov.gllvm
, getResidualCor.gllvm
,.
if (FALSE) {
# 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)
}
Run the code above in your browser using DataLab