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.
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.
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
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
## KELP_FRONDS PERCENT_ROCKY
## AU -0.1263154613 0.0003723101
## BF -1.3453414962 0.0573209281
## BO 0.0034323747 0.0023824387
## BR -0.0642574032 0.0192377577
## BRA 0.3152102655 -0.0823411674
## CAL -0.3111579899 -0.0863545071
## CC 0.1408463759 -0.0052271907
## CF -0.0832129192 0.0098154374
## CG -0.0009088389 -0.0358297917
## CO -0.0742776295 0.0103015530
## COF -0.4297693635 0.0639877351
## CP 0.1008818261 -0.0155112736
## CRYP -0.0023569647 0.0001078169
## CYOS 0.0227128352 -0.0064792928
## DL 0.0907817572 -0.0048380646
## DMH -0.2116645365 0.0013055952
## DP -0.0443183096 0.0082447226
## DU -0.1846508377 -0.0074637422
## EAH 6.9208397516 -0.0470034783
## EC 0.0672489687 0.0121074211
## EH 0.6073100599 -0.1145560158
## ER 0.0690383589 0.0285303349
## FB -0.5524192647 0.0094101695
## FTHR -0.4822952016 -0.0106365820
## GR 0.0830758374 0.0081737236
## GS -0.4709480778 0.0016602173
## GYSP -0.2302370012 0.0186638172
## MH 0.0964669310 -0.0016627233
## NIE -0.0295521997 -0.0061106165
## PH 0.7998148019 -0.2881250484
## PHSE -0.6040481267 0.0127025899
## PL 0.0840806543 0.0063306272
## POLA -0.8919582018 0.0066773339
## PRSP 0.0726392763 -0.0039023975
## R 0.0892306261 0.0068224464
## RAT 0.0839634422 -0.0016345129
## SAFU -0.5337651117 0.0183959897
## SAHO 7.6205825863 -0.0386220691
## SAMU -0.0413998688 0.0013969453
## SCCA -0.0098445403 0.0202155782
## TALE 0.0719561892 0.0173070536
## UV -0.3234502982 -0.0212963488
## H01_AU -0.2402265934 -0.0173312201
## H01_BF -0.1120598855 -0.0310454916
## H01_BO 0.1839840427 -0.0092763650
## H01_BR -0.1972466295 0.0060609919
## H01_BRA -0.9267079452 0.0151064856
## H01_CAL -0.2609673733 0.2267969329
## H01_CC -0.4405300048 0.0211162767
## H01_CF -0.0744298288 -0.0029989532
## H01_CG -0.0043225162 0.3095694311
## H01_CO 0.0461055188 -0.0108076597
## H01_COF -1.0247737959 0.2911390805
## H01_CP -1.4017048279 0.2275785382
## H01_CRYP 0.0120175969 -0.0215631935
## H01_CYOS 0.1921091156 -0.0164186617
## H01_DL 0.0481316232 -0.0125176021
## H01_DMH -0.3247133053 -0.0131128432
## H01_DP -0.0707638486 0.0146743969
## H01_DU -0.4295020842 0.2294174718
## H01_EAH -7.6006877677 0.2032283320
## H01_EC 0.1357409197 0.0530182896
## H01_EH -0.3084588145 -0.0140367456
## H01_ER -0.0581249563 0.0328385021
## H01_FB -0.5446841297 -0.0071107404
## H01_FTHR -0.9604390455 -0.0250951058
## H01_GR -0.2332679388 0.3409437500
## H01_GS -0.9424551759 -0.1528403762
## H01_GYSP 0.0044095359 0.0132349534
## H01_MH 2.2189036066 -0.0179866975
## H01_NIE -0.0860536814 -0.0248852922
## H01_PH -0.4258630263 -0.0645984396
## H01_PHSE -1.8208997141 -0.0173239407
## H01_PL 0.0791976799 -0.0033710888
## H01_POLA -0.6587766107 0.0004070270
## H01_PRSP -0.1215537393 -0.0034560838
## H01_R -0.1285759013 0.0077464055
## H01_RAT -0.1535619024 0.0263981644
## H01_SAFU -3.5508664641 -0.1030173978
## H01_SAHO -3.0603521985 0.2208320727
## H01_SAMU -0.0866393350 0.0030439653
## H01_SCCA -0.0271272541 0.0214252525
## H01_TALE -0.4314057237 0.2371561955
## H01_UV -0.5853600175 -0.0069909347
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:
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}\]
Lets demonstrate the ordered beta response model for the previous example. As the data has no ones:
## [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´).
Some species are observed only a few times:
## 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.
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: 17173798
## Residual degrees of freedom: 1554
## AIC: -34347008
## AICc: -34346897
## BIC: -34345385
Now if we check the cutoff values we see that the upper bounds are fixed to 20
## cutoff0 cutoff1
## AU -1.1058880 20
## BF -2.2258712 20
## BO -3.4895188 20
## BR 0.1308799 20
## BRA 0.6660875 20
## CAL -1.6300081 20
## CC -4.0806455 20
## CF -3.2212507 20
## CG -0.8452071 20
## CO -3.6189514 20
## COF -6.2801940 20
## CP -5.5699323 20
## CRYP -2.0347652 20
## CYOS -4.3612133 20
## DL -4.8914817 20
## DMH -2.3938827 20
## DP -0.5728909 20
## DU 1.3442193 20
## EAH -4.0752034 20
## EC -4.9495673 20
## EH -0.6213867 20
## ER -1.5742677 20
## FB -3.6737327 20
## FTHR -4.3012101 20
## GR -5.4662406 20
## GS -6.1451421 20
## GYSP -4.2488997 20
## MH -8.4785237 20
## NIE -1.6133103 20
## PH 0.5424585 20
## PHSE -2.7141755 20
## PL -1.2767376 20
## POLA -4.5393620 20
## PRSP -1.9769591 20
## R -5.0855738 20
## RAT -4.4185579 20
## SAFU -6.5272820 20
## SAHO -0.7662569 20
## SAMU -1.8066766 20
## SCCA 0.1695390 20
## TALE -1.2114590 20
## UV -4.1769607 20
Ordination plot: