# Analysing sparse ecological percent cover data using gllvm

#### Pekka Korhonen

#### 2025-07-11

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"]

    # Remove empty rows and rows with missing values from the data
    rem0 <- which((rowSums(Yalg)==0) | is.na(rowSums(Yalg)))
    Yalg <- Yalg[-rem0,]
    Xenv <- Xenv[-rem0,]

    # Use only the data from the year 2016:

    Yalg <- Yalg[Xenv$YEAR==2016,]
    Xenv <- Xenv[Xenv$YEAR==2016,]

    # Remove species which have no observations
    Yalg <- Yalg[,-which(colSums(Yalg>0)==0)]
    # Number of obs. and species:
    dim(Yalg)

    ## [1] 44 53

    # 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
    ## AMZO     -7.436225e-04 -3.671048e-02
    ## AU       -9.363935e-02 -4.622224e-03
    ## BF       -1.043785e-01  5.804607e-03
    ## BLD      -6.793328e-03 -1.009294e-01
    ## BO        2.238731e-01 -2.106224e-02
    ## BR       -7.386380e-03  1.715275e-02
    ## BRA       3.174680e-01 -8.077859e-02
    ## CAL      -1.059938e-01 -9.693657e-03
    ## CC        1.252850e-01  9.204546e-03
    ## CF       -5.577651e-02  7.061250e-03
    ## CG        1.331204e-01 -4.101384e-02
    ## CO       -1.236084e-01  1.932880e-02
    ## COF       8.876311e-03  4.601483e-02
    ## CP       -2.746838e-02 -7.267498e-02
    ## CRYP      7.293432e-04  1.059303e-05
    ## CYOS      5.133549e-02 -1.021229e-02
    ## CZ       -1.988983e-03 -3.691847e-02
    ## DL        1.063651e-01 -5.314059e-03
    ## DMH      -7.011538e-03 -9.238693e-03
    ## DP       -5.059829e-02  5.417037e-03
    ## DU       -3.966955e-01 -3.577545e-02
    ## EAH       5.854518e+00 -9.737616e-03
    ## EC        2.717136e-02  1.624020e-02
    ## EH        6.104677e-01 -1.145824e-01
    ## ER       -7.442585e-02 -5.879335e-03
    ## FASP     -1.297201e-03 -4.177426e-02
    ## FB       -5.797120e-01 -6.386541e-03
    ## FTHR      2.517482e-02 -1.538829e-02
    ## GR        1.001495e-02 -1.993025e-02
    ## GS       -3.138667e-01 -7.221339e-03
    ## GYSP     -2.496514e-01  4.796816e-02
    ## IR       -1.300099e-03 -4.850109e-02
    ## LH       -2.534014e-03 -3.483181e-02
    ## LI       -2.354088e-04 -2.118679e-01
    ## LS       -2.120155e-03 -2.980886e-02
    ## LX       -3.166794e-03 -4.249810e-02
    ## MH        9.388022e-02  1.685211e-04
    ## NIE      -6.170952e-02 -1.847042e-03
    ## PH        1.420901e+00 -2.046384e-01
    ## PHSE     -3.335930e-01 -9.666837e-04
    ## PL        5.569154e-02  2.382637e-02
    ## POLA      7.413706e-02 -1.719618e-02
    ## PRSP     -5.623527e-01  3.704074e-02
    ## R         9.120284e-02  4.908348e-03
    ## RAT       1.488705e-02 -6.593054e-04
    ## SAFU     -1.378206e+00  1.536887e-02
    ## SAHO      6.609548e+00 -3.309570e-03
    ## SAMU     -1.605534e-01  1.816202e-02
    ## SCCA     -7.865339e-03  8.508733e-02
    ## STIN     -7.497876e-05 -6.748088e-02
    ## TALE     -1.406212e-02  3.023316e-03
    ## UEC      -2.583160e-05 -1.291580e-02
    ## UV       -3.002272e-01 -1.625487e-02
    ## H01_AMZO -2.098383e+00  1.288085e-01
    ## H01_AU   -3.369162e-01 -2.227175e-02
    ## H01_BF    1.650655e-02 -4.573091e-02
    ## H01_BLD  -1.307038e-01 -3.185319e-02
    ## H01_BO    3.331598e-01 -2.360068e-02
    ## H01_BR   -1.490916e-01  1.715582e-03
    ## H01_BRA   1.243676e-01 -1.099993e-02
    ## H01_CAL   7.103867e-02  1.136448e-01
    ## H01_CC    7.155246e-01 -1.459510e-01
    ## H01_CF   -4.900503e-02 -1.309104e-02
    ## H01_CG   -5.500433e-02  2.517382e-01
    ## H01_CO    1.237192e-03 -5.527116e-03
    ## H01_COF  -1.653765e+00  1.875374e-01
    ## H01_CP   -1.519279e-01  1.655654e-01
    ## H01_CRYP -2.275211e-02 -2.421569e-02
    ## H01_CYOS  1.313066e-01 -1.984204e-02
    ## H01_CZ   -4.207105e-01  1.602603e-01
    ## H01_DL    1.310699e-01 -2.575455e-02
    ## H01_DMH   3.751818e-02 -2.967410e-02
    ## H01_DP   -1.712355e-01  2.273527e-02
    ## H01_DU   -4.620106e-01  2.333266e-01
    ## H01_EAH  -6.220292e+00  1.115720e-01
    ## H01_EC    9.884631e-02  4.708691e-02
    ## H01_EH    2.171195e-01 -3.856409e-02
    ## H01_ER   -6.541662e-02  4.500429e-02
    ## H01_FASP -6.619838e-01  1.118242e-01
    ## H01_FB   -3.073225e-01 -8.025710e-03
    ## H01_FTHR -3.101397e-01 -8.067413e-02
    ## H01_GR   -1.031280e-02  2.716115e-01
    ## H01_GS   -5.826430e-01 -1.739818e-01
    ## H01_GYSP -7.082709e-02  2.439396e-02
    ## H01_IR   -5.484904e-01  1.214426e-01
    ## H01_LH    3.793882e-03  1.194351e-01
    ## H01_LI   -7.612699e+00 -5.565538e-02
    ## H01_LS    9.877008e-02  6.705327e-02
    ## H01_LX   -2.333906e-01 -9.597084e-02
    ## H01_MH    8.973128e+00 -3.880235e-02
    ## H01_NIE   2.527910e-01 -4.983776e-02
    ## H01_PH    1.521331e+00 -2.000625e-01
    ## H01_PHSE -4.800690e-01 -9.167716e-02
    ## H01_PL    4.141229e-02 -5.357834e-03
    ## H01_POLA  6.516767e-01 -9.958064e-02
    ## H01_PRSP -2.286618e-01 -2.060026e-02
    ## H01_R    -3.121616e-02 -7.793983e-03
    ## H01_RAT  -2.942360e-02  1.646418e-02
    ## H01_SAFU -6.352776e+00 -1.482627e-01
    ## H01_SAHO -6.884759e+00  2.205889e-01
    ## H01_SAMU -4.562622e-03  5.496130e-04
    ## H01_SCCA -6.600245e-02  3.038893e-02
    ## H01_STIN -7.964077e+00 -2.142069e-02
    ## H01_TALE -6.022125e-01  2.339574e-01
    ## H01_UEC  -9.360192e-01  1.532197e-01
    ## H01_UV   -8.766576e-01 -9.659760e-03

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)

## 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.