Analysing sparse ecological percent cover data using gllvm

Pekka Korhonen

2026-06-22

This short document showcases how to use the gllvm package to analyse multivariate percent cover data. Namely, we show how to apply the hurdle beta GLLVM (with logistic link), as detailed in Korhonen et al. (2024), to analyse the kelp forest dataset from the Santa Barbara Coastal Long-Term Ecological Research project, available from https://doi.org/10.6073/pasta/0af1a5b0d9dde5b4e5915c0012ccf99c.

A multivariate percent cover dataset often comes in the form of a \(n \times m\) matrix \(\bf{Y}\), with \(n\) being the number of observational units/sites, and \(m\) being the number of species of plants, macroalgae, sessile invertebrates, et cetera. The response \(y_{ij}\) is then the recorded percentage of the relative area covered by species \(j\) on unit/site \(i\). Typically such datasets contain considerable proportion of zero observations, as a given obs. unit is often populated by only a small subset of the \(m\) species in total. More rarely, it might even be the case that one of the species covers some obs. unit completely.

Hurdle beta GLLVM

Traditionally, beta regression has been used to model responses that take the form of percentages. If \(y^*_{ij}\) is in the (open) interval \((0,1)\), and is distributed according to beta distribution, \(y^*_{ij} \sim \text{Beta}(\mu_{ij}, \phi_j)\), then it has the following density: \[ f_{\text{beta}}(y_{ij}^*; \mu_{ij}, \phi_j) = \frac{\Gamma(\phi_j)}{\Gamma(\mu_{ij}\phi_j)\Gamma(\phi_j-\phi_j\mu_{ij})} (y_{ij}^*)^{\mu_{ij}\phi_j-1}(1-y_{ij}^*)^{\phi_j(1-\mu_{ij}-1)}.\]

The mean parameter \(\mu_{ij}\) can be connected to a set of covariates and latent variables through some link function, by the equation \(g(\mu_{ij})=\eta_{ij} = \beta_{0j} + \boldsymbol{\beta}_j^\top\bf{x_i} + \boldsymbol{\lambda}_j^\top\bf{u_i}\).

However, such a model is ill-suited for most percent cover datasets, due to the fact that the beta distribution isn’t capable of handling zero (or \(100\%\)) responses. To make use of the beta regression model in such scenario, one needs to use some transformation in order to ‘push’ the responses away from the boundaries. This procedure might provide reasonable results when the numbers of zeros or ones in the data are relatively low. On the other hand, by transforming the zeros and ones, we might lose some important information.

A more sophisticated way of tackling such issue is by considering a zero-accommodating model, couple of which have been proposed recently. One such model is the hurdle beta model, which models the two (can be extended to three if \(100\%\) covers are recorded, see Korhonen et al. (2024)) classes the response \(y_{ij}\) can take, i.e., \(\{0\}\) and \((0,1)\), by separate processes. Namely, the zeros are assumed to be generated by a Bernoulli process. Conditional on \(y_{ij}\in(0,1)\), the response is modeled using the standard beta distribution as presented above. The likelihood function for a response \(Y_{ij}\) following the hurdle beta distribution is of the form: \[ P(Y_{ij};\mu_{ij}, \mu_{ij}^0, \phi_j) = \begin{cases} 1-\mu_{ij}^0, & Y_{ij} = 0,\\ \mu_{ij}^0 \cdot f_{\text{beta}}(Y_{ij};\mu_{ij},\phi_j), & Y_{ij} \in (0,1). \\ \end{cases} \] where \(g(\mu_{ij}^0) = \eta_{ij}^0 = \beta_{0j}^0 + \bf{x_i}^\top\boldsymbol{\beta}_j^0 + \bf{u_i}^\top\boldsymbol{\lambda}_j^0\) for and \(g(\mu_{ij}) = \eta_{ij} = \beta_{0j} + \bf{x_i}^\top\boldsymbol{\beta}_j + \bf{u_i}^\top\boldsymbol{\lambda}_j\) and \(g(\cdot)\) can be either probit or logistic link function. Note, that here, the separate linear predictors share the same environmental covariates \(\bf{x}_i\) and latent variable scores \(\bf{u}_i\), while the coefficients and loadings are allowed to differ.

The gllvm package implements the hurdle beta GLLVM with two different estimation methods available. First, accessed by the argument method="VA" when calling uses a hybrid approach, where the method of variational approximations, or VA, is applied to the Bernoulli-process part of the data (only probit link allowed), while the method of extended variational approximations, see Korhonen et al. (2023), is applied to the beta distributed part. By instead specifying method="EVA", the EVA method is applied to both parts of the likelihood.

Example

In the following, we show how to fit the logistic hurdle beta GLLVM using EVA on the SBC LTER marine macroalgae (i.e., seaweed) percent cover dataset. The data has been collected in 2000-2020 along 44 permanent transect lines along coastal southern California. We will specify a model with two latent variables (for ordination) and will include the rockiness of the seabed and the average number of stripes of giant kelp as environmental covariates in the model.

library(gllvm)
data("kelpforest")
Yabund <- kelpforest$Y
Xenv <- kelpforest$X
SPinfo <- kelpforest$SPinfo

# Data contains both algae and sessile invertebrates
table(SPinfo$GROUP)
## 
##  ALGAE INVERT  PLANT 
##     61     69      2
# Select only the macroalgae:
Yalg <- Yabund[,SPinfo$GROUP=="ALGAE"]

# To demonstrate the models, use only the data from the year 2016:
Yalg <- Yalg[Xenv$YEAR==2016,]
Xenv <- Xenv[Xenv$YEAR==2016,]

# Remove species which have no observations or just one
Yalg <- Yalg[,-which(colSums(Yalg>0)<2)]

# Number of obs. and species:
dim(Yalg)
## [1] 44 42
# Specify the covariates in the linear predictor
Xformulai = ~KELP_FRONDS + PERCENT_ROCKY

After setting up the data, LV design and the covariates, the model is estimated by

fit <- gllvm(Yalg, X=Xenv, formula = Xformulai, family = "betaH", method="EVA", 
             num.lv = 2, link="logit", control=list(reltol=1e-12))

To inspect e.g., the covariate effects, use

fit$params$Xcoef
##            KELP_FRONDS PERCENT_ROCKY
## AU       -1.013880e-01 -4.724495e-04
## BF       -2.487885e+00  1.099410e-01
## BO        2.098018e-02 -2.460852e-03
## BR       -4.591168e-02  2.245169e-02
## BRA       3.250781e-01 -8.188835e-02
## CAL      -1.739428e-01 -1.514354e-01
## CC        1.223957e-01  7.898618e-04
## CF       -8.803738e-02  9.909499e-03
## CG       -5.110920e-03 -3.599310e-02
## CO       -5.379647e-02  8.438689e-03
## COF      -3.677566e-01  5.539502e-02
## CP       -1.422141e-02 -1.056876e-01
## CRYP      1.513781e-03  1.126785e-05
## CYOS      3.735364e-02 -8.421308e-03
## DL        6.822257e-02 -4.420682e-04
## DMH      -1.434229e-01 -5.133406e-03
## DP       -5.380764e-02  7.893054e-03
## DU       -4.290070e-02 -7.821515e-03
## EAH       7.382062e+00 -6.536593e-02
## EC        3.950257e-02  1.790603e-02
## EH        6.156132e-01 -1.146798e-01
## ER        1.359653e-01  2.790188e-02
## FB       -4.664432e-01 -8.944906e-04
## FTHR     -2.513756e-01 -1.867772e-02
## GR        8.114077e-02  1.569813e-02
## GS       -4.314578e-01 -6.898069e-03
## GYSP     -1.702809e-01  8.491179e-03
## MH        9.455312e-02 -2.211462e-03
## NIE      -3.137399e-02 -6.160912e-03
## PH        1.433539e+00 -2.049199e-01
## PHSE     -5.433307e-01  8.347886e-03
## PL        8.135429e-02  8.546121e-03
## POLA     -7.307152e-01 -1.160537e-02
## PRSP     -4.404353e-06  1.117286e-07
## R         5.937542e-02  9.097785e-03
## RAT       5.659865e-02  2.412178e-03
## SAFU     -8.986772e-01  2.385311e-02
## SAHO      3.787715e+00 -3.293743e-02
## SAMU     -4.959294e-02 -7.051954e-04
## SCCA     -1.329191e-04  2.275465e-02
## TALE      2.302233e-02  3.499769e-02
## UV       -8.243220e-02 -1.195282e-02
## H01_AU   -2.083531e-01 -2.726309e-02
## H01_BF    5.507560e-02 -5.187252e-02
## H01_BO    2.284767e-01 -1.700030e-02
## H01_BR   -1.146060e-01 -5.203770e-04
## H01_BRA  -4.398328e-01 -1.951335e-02
## H01_CAL  -2.231247e-01  2.158039e-01
## H01_CC    2.031363e-01 -1.031977e-01
## H01_CF   -7.217803e-03 -1.128072e-02
## H01_CG    3.901961e-02  3.085968e-01
## H01_CO    3.660236e-02 -9.952391e-03
## H01_COF  -1.126976e+00  2.947424e-01
## H01_CP   -1.415997e+00  2.812103e-01
## H01_CRYP  6.537794e-02 -2.201999e-02
## H01_CYOS  2.537823e-01 -3.834405e-02
## H01_DL    5.944980e-02 -1.413654e-02
## H01_DMH  -2.651595e-01 -2.401626e-02
## H01_DP   -1.305892e-01  2.194531e-02
## H01_DU   -3.832930e-01  2.355605e-01
## H01_EAH  -1.163850e+01  1.587828e-01
## H01_EC    2.057204e-01  5.111600e-02
## H01_EH   -8.105573e-02 -2.296213e-02
## H01_ER   -7.035114e-02  4.330515e-02
## H01_FB   -3.341276e-01 -1.717165e-02
## H01_FTHR -8.632758e-01 -3.259739e-02
## H01_GR   -1.706945e-01  3.685095e-01
## H01_GS   -4.612208e-01 -2.297949e-01
## H01_GYSP  5.242699e-02  4.591198e-03
## H01_MH    2.330174e+00 -1.143238e-02
## H01_NIE   2.448747e-01 -6.436792e-02
## H01_PH    1.662762e-01 -9.340331e-02
## H01_PHSE -1.504011e+00 -8.769848e-02
## H01_PL    5.435793e-02 -1.490611e-03
## H01_POLA -2.645024e-01 -4.416796e-02
## H01_PRSP -2.011027e-01 -4.193284e-03
## H01_R    -9.003936e-02 -4.408076e-03
## H01_RAT  -1.265648e-01  2.084117e-02
## H01_SAFU -3.713454e+00 -1.745355e-01
## H01_SAHO -3.261900e+00  2.347616e-01
## H01_SAMU -1.456076e-01  3.791985e-03
## H01_SCCA -8.238921e-02  3.180287e-02
## H01_TALE -4.878582e-01  2.337806e-01
## H01_UV   -5.544205e-01 -1.662595e-02

In the above, the prefix indicates that the coefficient relates to the Bernoulli part of the hurdle model.

Ordination plot can then be generated as per usual:

ordiplot(fit, jitter = TRUE, s.cex = .8)

Ordered beta GLLVM

Another solution for modeling percentage cover data in gllvm is to use ordered beta response model. It handles zeros and ones slightly differently compared to hurdle beta model. Instead of assuming that the zeros and ones comes from separate process from the percent cover, the model assumes that there is an underlying process \(z_{ij}\) where all observations comes from.

For species \(j = 1, . . . , m\), let \(z_{ij}\) denote an underlying continuous variable, and define two cutoff parameters \(\zeta_{j0} < \zeta_{j1}\) such that \(Y_{ij} = 0\) occurs when \(z_{ij} < \zeta_{j0}\), \(Y_{ij}=1\) occurs when \(z_{ij}>\zeta_{j1}\), and \(Y_{ij} \in (0,1)\) occurs when \(\zeta_{j0} < z_{ij} < \zeta_{j1}\). Conditional on \(Y_{ij} \in (0,1)\), the response variable follows a beta distribution. By assuming \(z_{ij}\) follows a logistic distribution, then marginalising over \(z_{ij}\) we obtain the following distribution for the percent cover responses that characterizes the ordered beta GLLVM,

\[\begin{align} P(Y_{ij};\eta_{ij}, \phi_j) = \begin{cases} \rho^0_{ij}, & if Y_{ij} = 0 ,\\ \left(\rho^1 - \rho^0 \right) \cdot f_{\text{beta}}(Y_{ij}; \mu_{ij}, \phi_j), & if Y_{ij} \in (0,1) ,\\ 1-\rho^1_{ij}, & if Y_{ij} = 1 ,\\ \end{cases} \end{align}\]

Adjusting ordered beta to data without ones

Lets demonstrate the ordered beta response model for the previous example. As the data has no ones:

sum(Yalg ==1)
## [1] 0

We can accommodate the model to better handle data that by fixing the upper cutoff parameters to some large value, for example 20. With gllvm this can be done by setting starting values for the cutoff parameter, ´zetacutoff = c(0, 20)´ and fixing the upper cutoff parameters with ´setMap = list(zeta = factor(rbind(1:m, rep(NA, m))))´. We assume that the number of species/response variables in the data is saved to object m. There are ´m´ (number of species) lower cutoff parameters \(\zeta_{j0}\) we let be freely estimated (that’s indexes ´1:m´ in ´setMap´) and ´m´ upper cutoff parameters \(\zeta_{j1}\) that we fix (that’s ´rep(NA, m)´ in ´setMap´).

Setting shape parameter to common across species

Some species are observed only a few times:

colSums(Yalg>0)
##   AU   BF   BO   BR  BRA  CAL   CC   CF   CG   CO  COF   CP CRYP CYOS   DL  DMH 
##   23    3   11    5    2    5   30   13    5   24    5    3    3   33   26    8 
##   DP   DU  EAH   EC   EH   ER   FB FTHR   GR   GS GYSP   MH  NIE   PH PHSE   PL 
##   14    4    3   36    2    6    6    6   11   20    7   36   13    2    5    4 
## POLA PRSP    R  RAT SAFU SAHO SAMU SCCA TALE   UV 
##    6    4   31   17    6    2    7    7    5    6

so there is not much information to estimate the shape parameter of the beta distribution for each species separately. Thus we can also set the shape parameter to be common across species with ´disp.formula = rep(1, m)´. This can be applied for all beta based models in gllvm.

Model fit

Now we are ready to fit the model:

# save the number of species to object m
m <- ncol(Yalg)
fit_ob <- gllvm(Yalg, X=Xenv, formula = Xformulai, family = "orderedBeta", 
    method="EVA", num.lv = 2, link="logit",
    disp.formula = rep(1, m), zetacutoff = c(0, 20),
    setMap = list(zeta = factor(rbind(1:m, rep(NA, m)))) )
fit_ob
## Call: 
## gllvm(y = Yalg, X = Xenv, formula = Xformulai, family = "orderedBeta", 
##     num.lv = 2, method = "EVA", link = "logit", disp.formula = rep(1, 
##         m), setMap = list(zeta = factor(rbind(1:m, rep(NA, m)))), 
##     zetacutoff = c(0, 20))
## family: 
## [1] "orderedBeta"
## method: 
## [1] "EVA"
## 
## log-likelihood:  239.7871 
## Residual degrees of freedom:  1554 
## AIC:  108.4259 
## AICc:  220.1194 
## BIC:  1731.852

Now if we check the cutoff values we see that the upper bounds are fixed to 20

fit_ob$params$zeta
##        cutoff0 cutoff1
## AU   -2.253214      20
## BF   -1.251314      20
## BO   -2.718055      20
## BR   -1.361771      20
## BRA  -1.806604      20
## CAL  -2.030746      20
## CC   -5.133260      20
## CF   -2.881754      20
## CG   -3.627948      20
## CO   -2.939729      20
## COF  -5.513601      20
## CP   -3.693915      20
## CRYP -1.305949      20
## CYOS -3.771781      20
## DL   -4.666261      20
## DMH  -2.610885      20
## DP   -2.349122      20
## DU   -2.682536      20
## EAH  -5.857012      20
## EC   -4.137155      20
## EH   -3.390855      20
## ER   -2.625228      20
## FB   -1.011205      20
## FTHR -2.597725      20
## GR   -4.372955      20
## GS   -3.898109      20
## GYSP -1.956803      20
## MH   -4.344225      20
## NIE  -3.129506      20
## PH   -1.497350      20
## PHSE -2.489283      20
## PL   -1.423868      20
## POLA -2.558219      20
## PRSP -2.436488      20
## R    -4.645781      20
## RAT  -3.181538      20
## SAFU -4.601453      20
## SAHO -8.748899      20
## SAMU -1.484021      20
## SCCA -2.419619      20
## TALE -3.101808      20
## UV   -1.586696      20

Ordination plot:

ordiplot(fit_ob, jitter = TRUE, s.cex = .8)

References

Korhonen, P., F.K.C. Hui, J. Niku, and S. Taskinen. 2023. Fast and Universal Estimation of Latent Variable Models Using Extended Variational Approximations. 33: 26. https://doi.org/10.1007/s11222-022-10189-w.
Korhonen, P., F.K.C. Hui, J. Niku, S. Taskinen, and B. van der Veen. 2024. A Comparison of Joint Species Distribution Models for Percent Cover Data. https://doi.org/10.48550/arXiv.2403.11562.