getResidualCov.gllvm: Extract residual covariance matrix from gllvm object

View source: R/getResidualCov.gllvm.R

getResidualCov.gllvmR Documentation

Extract residual covariance matrix from gllvm object

Description

Calculates the residual covariance matrix for gllvm model.

Usage

## S3 method for class 'gllvm'
getResidualCov(object, adjust = 1, site.index = NULL, ...)

Arguments

object

an object of class 'gllvm'.

adjust

The type of adjustment used for negative binomial, binomial and normal distribution when computing residual correlation matrix. Options are 0 (no adjustment), 1 (the default adjustment) and 2 (alternative adjustment for NB distribution), see details.

site.index

A site index, vector of length one or 1, that is used in the calculation of a GLLVM with quadratic response model.

...

not used.

Details

Residual covariance matrix, storing information on species co-occurrence that is not explained by the environmental variables (if included), is calculated using the matrix of latent variables loadings, that is, \Theta\Theta', and the dispersion parameter related to the distribution of choice, is applicable (e.g. in the case of negative-binomial distributed responses).

When the responses are modelled using the negative binomial distribution, the residual variances for each species must be adjusted for overdispersion. The two possible adjustment terms are log(\phi_j + 1) (adjust = 1) and \psi^{(1)}(1/\phi_j) (adjust = 2), where \psi^{(1)} is the trigamma function.

The negative binomial model can be written using different parameterizations. The residual covariance with adjust = 1 can be obtained using the lognormal-Poisson parametrization, that is,

Y_{ij} \sim Poisson(\mu_{ij} \lambda_j),

where \lambda_j \sim lognormal(-\sigma^2/2, \sigma^2) and \sigma^2 = log(\phi_j + 1) and log(\mu_{ij}) = \eta_{ij}. Now E[Y_{ij}] = \mu_{ij} and variance V(\mu_{ij}) = \mu_{ij} + \mu_{ij}^2 (exp(\sigma^2) - 1) = \mu_{ij} + \mu_{ij}^2 \phi_j, which are the same as for the NB distribution. Therefore, on linear predictor scale, we have the variance

V(log(\mu_{ij} \lambda_j)) = V(log\mu_{ij}) + V(log\lambda_j) = V(u_i'\theta_j) + \sigma^2 = \theta_j'\theta_j + log(\phi_j + 1).

which leads to the residual covariance matrix \Theta \Theta' + \Psi, where \Psi is the diagonal matrix with log(\phi_j + 1) as diagonal elements (adjust = 1).

Or, for a GLLVM where species are a quadratic function of the latent variables, we instead have

V(log(\mu_{ij} \lambda_j)) = V(log\mu_{ij}) + V(log\lambda_j) = V(u_i'\theta_j-u_i' D_j u_i) + \sigma^2

= \theta_j'\theta_j + 2diag(D_j)'diag(D_j)log(\phi_j + 1).

which leads to the residual covariance matrix \Theta \Theta' + 2 \Gamma_j \Gamma_j' + diag(\Phi), where \Gamma_j holds the quadratic coefficients. Since the quadratic coefficients are constrained to be positive, the residual covariance in the latter case is, given the same coefficients on the linear term, equal or more positive than in the linear case.

The residual covariance matrix with adjust = 2 can be obtained by using Poisson-Gamma parametri-zation

Y_{ij} \sim Poisson(\mu_{ij} \lambda_j),

where \lambda_j \sim Gamma(1/\phi_j, 1/\phi_j) and \mu_{ij} is as above. The mean and the variance are of similar form as above and we have that

V(log(\mu_{ij} \lambda_j)) = V(log\mu_{ij}) + V(log\lambda_j) = \theta_j'\theta_j + \psi^{(1)}(1/\phi_j),

where \psi^{(1)} is the trigamma function.

In the case of binomial distribution, the adjustment terms (adjust = 1) are 1 for probit link and \pi^2/3 for logit link. These are obtained by treating binomial model as latent variable model. Assume

Y^*_{ij} = \eta_{ij} + e_{ij},

where e_{ij} \sim N(0, 1) for probit model, and e_{ij} \sim logistic(0, 1) for logit model. Then binary response is defined as Y_{ij} = 1, if Y^*_{ij} > 0 and 0 otherwise. Now we have that \mu_{ij} = P(Y_{ij} = 1) = P(Y^*_{ij} > 0) = P(\eta_{ij} > -e_{ij}) = P(e_{ij} <= \eta_{ij}) which leads to probit and logit models. On linear predictor scale we then have that

V(\eta_{ij} + e_{ij}) = V(\eta_{ij}) + V(e_{ij}).

For the probit model, the residual covariance matrix is then \Theta\Theta' + I_m, and for the logit model \Theta\Theta' + \pi^2/3 I_m. Similarly as above, for a GLLVM where species are a quadratic function of the latent variables, the term 2\Gamma_j\Gamma_j' is added to the residual covariance matrix.

For normal distribution, we can write

Y_{ij} = \eta_{ij} + e_{ij},

where e_{ij} \sim N(0, \phi_j^2) and thus we have that

V(\eta_{ij} + e_{ij}) = V(\eta_{ij}) + V(e_{ij}).

For the gaussian model, the residual covariance matrix is then \Theta\Theta' + diag(\Phi^2).

Value

Function returns following components:

cov

residual covariance matrix

trace

trace of the residual covariance matrix, the total variance explained

var.q

trace of the residual covariance matrix per latent variable, variance explained per latent variable

var.q2

trace of the squared term of the residual covariance matrix per latent variable, for quadratic responses. Variance explained per latent variable by the quadratic term

Author(s)

Francis K.C. Hui, Jenni Niku, David I. Warton, Bert van der Veen

Examples

## Not run: 
# Load a dataset from the mvabund package
data(antTraits)
y <- as.matrix(antTraits$abund)
# Fit gllvm model
fit <- gllvm(y = y, family = poisson())
# residual covariance:
rescov <- getResidualCov(fit)
rescov$cov
# Trace of the covariance matrix
rescov$trace
# Variance explained per latent variable
rescov$var.q

## End(Not run)

gllvm documentation built on Sept. 18, 2023, 5:22 p.m.