The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Introduction to gllvm Part 1: Ordination

Jenni Niku

2024-11-26

Introduction to gllvm

R package gllvm

# From CRAN
install.packages(gllvm)
# OR
# From GitHub using devtools package's function install_github
devtools::install_github("JenniNiku/gllvm")
Problems?

gllvm package depends on R packages TMB and mvabund, try to install these first.

Distributions

Response Distribution Method Link
Counts Poisson VA/LA log
NB VA/LA log
ZIP LA log
Binary Bernoulli VA/LA probit
EVA/LA logit
Ordinal Ordinal VA probit
Normal Gaussian VA/LA identity
Positive continuous Gamma VA/LA log
Non-negative continuous Exponential VA/LA log
Biomass Tweedie LA/EVA log
Percent cover beta LA/EVA probit/logit

Data input

Main function of the gllvm package is gllvm(), which can be used to fit GLLVMs for multivariate data with the most important arguments listed in the following:

gllvm(y = NULL, X = NULL, TR = NULL, family, num.lv = 2, 
 formula = NULL, method = "VA", row.eff = FALSE, n.init=1, starting.val ="res", ...)
library(gllvm)

Example: Spiders

Data fitting

Fitting basic GLLVM \(g(E(y_{ij})) = \beta_{0j} + \boldsymbol{u}_i'\boldsymbol{\theta}_j\) with gllvm:

data("spider", package = "mvabund")
library(gllvm)
fitnb <- gllvm(y = spider$abund, family = "negative.binomial", num.lv = 2)
fitnb
## Call: 
## gllvm(y = spider$abund, family = "negative.binomial", num.lv = 2)
## family: 
## [1] "negative.binomial"
## method: 
## [1] "VA"
## 
## log-likelihood:  -733.6807 
## Residual degrees of freedom:  289 
## AIC:  1561.361 
## AICc:  1577.028 
## BIC:  1740.766

Residual analysis

par(mfrow = c(1,2))
plot(fitnb, which = 1:2)

Model selection

fitp <- gllvm(y = spider$abund, family = poisson(), num.lv = 2)
fitnb <- gllvm(y = spider$abund, family = "negative.binomial", num.lv = 2)
AIC(fitp)
## [1] 1761.655
AIC(fitnb)
## [1] 1561.361

Exercises

Try to do these exercises for the next 10 minutes, as many as time is enough for.

E1. Load spider data from mvabund package and take a look at the dataset.

library(gllvm)
data("spider", package = "mvabund")
# more info: 
# ?spider
Show the answers.

1. Print the data and covariates and draw a boxplot of the data.

# response matrix:
spider$abund
##       Alopacce Alopcune Alopfabr Arctlute Arctperi Auloalbi Pardlugu Pardmont
##  [1,]       25       10        0        0        0        4        0       60
##  [2,]        0        2        0        0        0       30        1        1
##  [3,]       15       20        2        2        0        9        1       29
##  [4,]        2        6        0        1        0       24        1        7
##  [5,]        1       20        0        2        0        9        1        2
##  [6,]        0        6        0        6        0        6        0       11
##  [7,]        2        7        0       12        0       16        1       30
##  [8,]        0       11        0        0        0        7       55        2
##  [9,]        1        1        0        0        0        0        0       26
## [10,]        3        0        1        0        0        0        0       22
## [11,]       15        1        2        0        0        1        0       95
## [12,]       16       13        0        0        0        0        0       96
## [13,]        3       43        1        2        0       18        1       24
## [14,]        0        2        0        1        0        4        3       14
## [15,]        0        0        0        0        0        0        6        0
## [16,]        0        3        0        0        0        0        6        0
## [17,]        0        0        0        0        0        0        2        0
## [18,]        0        1        0        0        0        0        5        0
## [19,]        0        1        0        0        0        0       12        0
## [20,]        0        2        0        0        0        0       13        0
## [21,]        0        1        0        0        0        0       16        1
## [22,]        7        0       16        0        4        0        0        2
## [23,]       17        0       15        0        7        0        2        6
## [24,]       11        0       20        0        5        0        0        3
## [25,]        9        1        9        0        0        2        1       11
## [26,]        3        0        6        0       18        0        0        0
## [27,]       29        0       11        0        4        0        0        1
## [28,]       15        0       14        0        1        0        0        6
##       Pardnigr Pardpull Trocterr Zoraspin
##  [1,]       12       45       57        4
##  [2,]       15       37       65        9
##  [3,]       18       45       66        1
##  [4,]       29       94       86       25
##  [5,]      135       76       91       17
##  [6,]       27       24       63       34
##  [7,]       89      105      118       16
##  [8,]        2        1       30        3
##  [9,]        1        1        2        0
## [10,]        0        0        1        0
## [11,]        0        1        4        0
## [12,]        1        8       13        0
## [13,]       53       72       97       22
## [14,]       15       72       94       32
## [15,]        0        0       25        3
## [16,]        2        0       28        4
## [17,]        0        0       23        2
## [18,]        0        0       25        0
## [19,]        1        0       22        3
## [20,]        0        0       22        2
## [21,]        0        1       18        2
## [22,]        0        0        1        0
## [23,]        0        0        1        0
## [24,]        0        0        0        0
## [25,]        6        0       16        6
## [26,]        0        0        1        0
## [27,]        0        0        0        0
## [28,]        0        0        2        0
# Environmental variables
spider$x
##    soil.dry bare.sand fallen.leaves   moss herb.layer reflection
## 1    2.3321    0.0000        0.0000 3.0445     4.4543     3.9120
## 2    3.0493    0.0000        1.7918 1.0986     4.5643     1.6094
## 3    2.5572    0.0000        0.0000 2.3979     4.6052     3.6889
## 4    2.6741    0.0000        0.0000 2.3979     4.6151     2.9957
## 5    3.0155    0.0000        0.0000 0.0000     4.6151     2.3026
## 6    3.3810    2.3979        3.4340 2.3979     3.4340     0.6931
## 7    3.1781    0.0000        0.0000 0.6931     4.6151     2.3026
## 8    2.6247    0.0000        4.2627 1.0986     3.4340     0.6931
## 9    2.4849    0.0000        0.0000 4.3307     3.2581     3.4012
## 10   2.1972    3.9318        0.0000 3.4340     3.0445     3.6889
## 11   2.2192    0.0000        0.0000 4.1109     3.7136     3.6889
## 12   2.2925    0.0000        0.0000 3.8286     4.0254     3.6889
## 13   3.5175    1.7918        1.7918 0.6931     4.5109     3.4012
## 14   3.0865    0.0000        0.0000 1.7918     4.5643     1.0986
## 15   3.2696    0.0000        4.3944 0.6931     3.0445     0.6931
## 16   3.0301    0.0000        4.6052 0.6931     0.6931     0.0000
## 17   3.3322    0.0000        4.4543 0.6931     3.0445     1.0986
## 18   3.1224    0.0000        4.3944 0.0000     3.0445     1.0986
## 19   2.9232    0.0000        4.5109 1.6094     1.6094     0.0000
## 20   3.1091    0.0000        4.5951 0.6931     0.6931     0.0000
## 21   2.9755    0.0000        4.5643 0.6931     1.7918     0.0000
## 22   1.2528    3.2581        0.0000 4.3307     0.6931     3.9120
## 23   1.1939    3.0445        0.0000 4.0254     3.2581     4.0943
## 24   1.6487    3.2581        0.0000 4.0254     3.0445     4.0073
## 25   1.8245    3.5835        0.0000 1.0986     4.1109     2.3026
## 26   0.9933    4.5109        0.0000 1.7918     1.7918     4.3820
## 27   0.9555    2.3979        0.0000 3.8286     3.4340     3.6889
## 28   0.9555    3.4340        0.0000 3.7136     3.4340     3.6889
# Plot data using boxplot:
boxplot(spider$abund)

E2. Fit GLLVM to spider data with a suitable distribution. Data consists of counts of spider species.

# Take a look at the function documentation for help: 
?gllvm
Show the answers.

2. Response variables in spider data are counts, so Poisson, negative binomial and zero inflated Poisson are possible. However, ZIP is implemented only with Laplace method, so it need to be noticed, that if models are fitted with different methods they can not be compared with information criteria. Let’s try just with a Poisson and NB. NOTE THAT the results may not be exactly the same as below, as the initial values for each model fit are slightly different, so the results may also differ slightly.

# Fit a GLLVM to data
fitp <- gllvm(y = spider$abund, family = poisson(), num.lv = 2)
fitp
## Call: 
## gllvm(y = spider$abund, family = poisson(), num.lv = 2)
## family: 
## [1] "poisson"
## method: 
## [1] "VA"
## 
## log-likelihood:  -845.8277 
## Residual degrees of freedom:  301 
## AIC:  1761.655 
## AICc:  1770.055 
## BIC:  1895.254
fitnb <- gllvm(y = spider$abund, family = "negative.binomial", num.lv = 2)
fitnb
## Call: 
## gllvm(y = spider$abund, family = "negative.binomial", num.lv = 2)
## family: 
## [1] "negative.binomial"
## method: 
## [1] "VA"
## 
## log-likelihood:  -733.6807 
## Residual degrees of freedom:  289 
## AIC:  1561.361 
## AICc:  1577.028 
## BIC:  1740.766

Based on AIC, NB distribution suits better. How about residual analysis: NOTE THAT The package uses randomized quantile residuals so each time you plot the residuals, they look a little different.

# Fit a GLLVM to data
plot(fitp)

plot(fitnb)

You could do these comparisons with Laplace method as well, using the code below, and it would give the same conclusion that NB distribution suits best:

fitLAp <- gllvm(y = spider$abund, family = poisson(), method = "LA", num.lv = 2)
fitLAnb <- gllvm(y = spider$abund, family = "negative.binomial", method = "LA", num.lv = 2)
fitLAzip <- gllvm(y = spider$abund, family = "ZIP", method = "LA", num.lv = 2)
AIC(fitLAp)
AIC(fitLAnb)
AIC(fitLAzip)

E3. Explore the fitted model. Where are the estimates for parameters? What about predicted latent variables? Standard errors?

Show the answers.

3. Lets explore the fitted model:

# Parameters:
coef(fitnb)
## $Species.scores
##                 LV1         LV2
## Alopacce  1.0000000  0.00000000
## Alopcune -0.2629602  1.00000000
## Alopfabr  0.9017718 -0.48387218
## Arctlute -0.7021486  2.02837069
## Arctperi  0.5939771 -1.58964167
## Auloalbi -0.6522467  1.53294757
## Pardlugu -0.8880039 -0.02809718
## Pardmont  0.7496224  0.58852199
## Pardnigr -0.5742755  1.78003186
## Pardpull -0.4143816  1.94810392
## Trocterr -0.4691976  0.78790742
## Zoraspin -0.6960342  1.15687649
## 
## $sigma.lv
##      LV1      LV2 
## 1.803795 1.828189 
## 
## $Intercept
##   Alopacce   Alopcune   Alopfabr   Arctlute   Arctperi   Auloalbi   Pardlugu 
##  0.7737499  0.5525202 -0.1427501 -3.5858139 -3.3684185 -0.7288924  0.3198452 
##   Pardmont   Pardnigr   Pardpull   Trocterr   Zoraspin 
##  1.6252855 -0.2728510 -0.1327234  2.6569167  0.2476339 
## 
## $inv.phi
##   Alopacce   Alopcune   Alopfabr   Arctlute   Arctperi   Auloalbi   Pardlugu 
##  1.3061188  1.4673469  0.7054924  0.8981297  2.3301899  1.5379736  1.1533136 
##   Pardmont   Pardnigr   Pardpull   Trocterr   Zoraspin 
##  1.6171909  2.5398533  2.1970182 12.9756797  2.5717246 
## 
## $phi
##   Alopacce   Alopcune   Alopfabr   Arctlute   Arctperi   Auloalbi   Pardlugu 
## 0.76562714 0.68150213 1.41744978 1.11342495 0.42914957 0.65020620 0.86706683 
##   Pardmont   Pardnigr   Pardpull   Trocterr   Zoraspin 
## 0.61835617 0.39372353 0.45516237 0.07706725 0.38884413
# Where are the predicted latent variable values? just fitp$lvs or
getLV(fitnb)
##               LV1           LV2
## Row1   0.92797452  1.2702887996
## Row2  -0.68339148  0.7933889373
## Row3   0.67667101  1.2746081850
## Row4  -0.24747473  1.1497717347
## Row5  -0.36059115  1.2174388035
## Row6  -0.35228333  1.0086050619
## Row7   0.02962986  1.4263984953
## Row8  -1.52139591 -0.0714306843
## Row9   0.91038432  0.0001081857
## Row10  1.03724468 -0.4942999226
## Row11  1.48919330  0.3024451117
## Row12  1.32425744  0.8070638569
## Row13  0.11543446  1.3567291488
## Row14 -0.43643959  1.0147300024
## Row15 -1.31885031 -0.5454775216
## Row16 -1.17440849 -0.2433889075
## Row17 -1.11221531 -0.5136176269
## Row18 -1.15837292 -0.5437356904
## Row19 -1.34062361 -0.5037365149
## Row20 -1.36675132 -0.5928393046
## Row21 -1.13972303 -0.4767011433
## Row22  0.76458898 -1.3475359039
## Row23  0.92089716 -1.3817933975
## Row24  0.97892056 -1.3959576996
## Row25  0.63178639  0.5765279110
## Row26  0.27461975 -1.9656116308
## Row27  1.11533204 -1.3109334360
## Row28  1.01915570 -0.8270334856
# Standard errors for parameters:
fitnb$sd
## $theta
##                LV1       LV2
## Alopacce 0.0000000 0.0000000
## Alopcune 0.2732833 0.0000000
## Alopfabr 0.3301079 0.2043463
## Arctlute 0.6734403 0.7838363
## Arctperi 0.4753595 0.5592241
## Auloalbi 0.4400577 0.3893141
## Pardlugu 0.2273720 0.2004671
## Pardmont 0.2196636 0.1816917
## Pardnigr 0.4726854 0.3799847
## Pardpull 0.4958677 0.4107617
## Trocterr 0.2095030 0.1568856
## Zoraspin 0.3474830 0.2796923
## 
## $sigma.lv
##       LV1       LV2 
## 0.4164408 0.4255879 
## 
## $beta0
##  Alopacce  Alopcune  Alopfabr  Arctlute  Arctperi  Auloalbi  Pardlugu  Pardmont 
## 0.4519032 0.4628413 0.5478562 1.7068304 1.4652986 0.7887091 0.4389213 0.3996445 
##  Pardnigr  Pardpull  Trocterr  Zoraspin 
## 0.7863927 0.8335824 0.3336754 0.5826983 
## 
## $inv.phi
##  Alopacce  Alopcune  Alopfabr  Arctlute  Arctperi  Auloalbi  Pardlugu  Pardmont 
## 0.6024853 0.6020533 0.3959909 0.5790585 1.8027954 0.8378729 0.5813565 0.7752528 
##  Pardnigr  Pardpull  Trocterr  Zoraspin 
## 1.3144341 1.2477198 6.8916938 1.2845764 
## 
## $phi
##   Alopacce   Alopcune   Alopfabr   Arctlute   Arctperi   Auloalbi   Pardlugu 
## 0.35316781 0.27962072 0.79561064 0.71786759 0.33201967 0.35422595 0.43706668 
##   Pardmont   Pardnigr   Pardpull   Trocterr   Zoraspin 
## 0.29642906 0.20376123 0.25849358 0.04093226 0.19422764

E4. Fit model with different numbers of latent variables.

Show the answers.

4. Default number of latent variables is 2. Let’s try 1 and 3 latent variables as well:

# In exercise 2, we fitted GLLVM with two latent variables 
fitnb
## Call: 
## gllvm(y = spider$abund, family = "negative.binomial", num.lv = 2)
## family: 
## [1] "negative.binomial"
## method: 
## [1] "VA"
## 
## log-likelihood:  -733.6807 
## Residual degrees of freedom:  289 
## AIC:  1561.361 
## AICc:  1577.028 
## BIC:  1740.766
# How about 1 or 3 LVs
fitnb1 <- gllvm(y = spider$abund, family = "negative.binomial", num.lv = 1)
fitnb1
## Call: 
## gllvm(y = spider$abund, family = "negative.binomial", num.lv = 1)
## family: 
## [1] "negative.binomial"
## method: 
## [1] "VA"
## 
## log-likelihood:  -759.4012 
## Residual degrees of freedom:  300 
## AIC:  1590.802 
## AICc:  1599.712 
## BIC:  1728.218
getLV(fitnb1)
##               LV1
## Row1  -0.81675775
## Row2  -0.94956087
## Row3  -0.91679455
## Row4  -1.10565621
## Row5  -1.22143666
## Row6  -1.03394128
## Row7  -1.26768979
## Row8  -0.53466528
## Row9   0.36615090
## Row10  1.00893217
## Row11  0.31304553
## Row12 -0.31661710
## Row13 -1.17618381
## Row14 -1.03494111
## Row15 -0.09003592
## Row16 -0.27456227
## Row17 -0.02441213
## Row18 -0.02072645
## Row19 -0.12965858
## Row20 -0.06883432
## Row21 -0.04315509
## Row22  1.54075392
## Row23  1.65007160
## Row24  1.68361555
## Row25 -0.28898428
## Row26  1.92876452
## Row27  1.62327534
## Row28  1.20028809
fitnb3 <- gllvm(y = spider$abund, family = "negative.binomial", num.lv = 3)
fitnb3
## Call: 
## gllvm(y = spider$abund, family = "negative.binomial", num.lv = 3)
## family: 
## [1] "negative.binomial"
## method: 
## [1] "VA"
## 
## log-likelihood:  -733.6807 
## Residual degrees of freedom:  279 
## AIC:  1581.361 
## AICc:  1605.146 
## BIC:  1798.937
getLV(fitnb3)
##               LV1           LV2           LV3
## Row1   0.92822638  1.2702505090  7.862130e-06
## Row2  -0.68263172  0.7934313523 -1.856794e-05
## Row3   0.67630882  1.2743317385  5.738479e-06
## Row4  -0.24677066  1.1497976401  6.691897e-07
## Row5  -0.36087133  1.2171257389  4.598610e-05
## Row6  -0.35178365  1.0086410311  2.917300e-05
## Row7   0.02934779  1.4260806364  1.394889e-05
## Row8  -1.52150671 -0.0715202215 -1.019743e-04
## Row9   0.91099312  0.0005030105 -3.071324e-05
## Row10  1.03751408 -0.4944820180 -4.127732e-05
## Row11  1.48933209  0.3026385650 -4.358094e-05
## Row12  1.32503296  0.8072152749 -4.299219e-05
## Row13  0.11586301  1.3567838519  7.313012e-06
## Row14 -0.43693123  1.0142431715 -1.151618e-05
## Row15 -1.31916714 -0.5457816242  2.273325e-05
## Row16 -1.17418551 -0.2434272268  2.250755e-05
## Row17 -1.11264281 -0.5140579042  2.597970e-05
## Row18 -1.15869161 -0.5437850278  1.347334e-05
## Row19 -1.34018248 -0.5036603401  1.263063e-05
## Row20 -1.36680641 -0.5929069294  1.613081e-06
## Row21 -1.13911990 -0.4767517096 -2.562782e-05
## Row22  0.76448858 -1.3472392529  1.186810e-05
## Row23  0.92104732 -1.3815652108 -1.122195e-05
## Row24  0.97917183 -1.3964075273 -1.243771e-06
## Row25  0.63165667  0.5764250755  6.980981e-05
## Row26  0.27492596 -1.9651225880  2.535587e-05
## Row27  1.11595098 -1.3101547204  1.212816e-06
## Row28  1.01933307 -0.8266715470  7.850437e-06

E5. Include environmental variables to the GLLVM and explore the model fit.

Show the answers.

5. Environmental variables can be included with an argument X:

fitnbx <- gllvm(y = spider$abund, X = spider$x, family = "negative.binomial", seed = 123, num.lv = 2)
fitnbx
## Call: 
## gllvm(y = spider$abund, X = spider$x, family = "negative.binomial", 
##     num.lv = 2, seed = 123)
## family: 
## [1] "negative.binomial"
## method: 
## [1] "VA"
## 
## log-likelihood:  -593.6749 
## Residual degrees of freedom:  217 
## AIC:  1425.35 
## AICc:  1557.572 
## BIC:  1879.586
coef(fitnbx)
## $Species.scores
##                  LV1          LV2
## Alopacce  1.00000000 0.000000e+00
## Alopcune  0.65033064 1.000000e+00
## Alopfabr  4.60955070 5.839337e-01
## Arctlute -1.54308018 1.152119e+00
## Arctperi  1.57923376 3.724113e-07
## Auloalbi -1.24985864 6.094446e-01
## Pardlugu -8.27756341 1.960724e-01
## Pardmont  1.62553948 3.640396e-01
## Pardnigr -0.02217957 1.070667e+00
## Pardpull -0.31400009 7.281194e-01
## Trocterr -1.94940036 4.990269e-01
## Zoraspin  0.31162305 7.370960e-01
## 
## $sigma.lv
##          LV1          LV2 
## 4.198566e-09 9.499576e-01 
## 
## $Intercept
##    Alopacce    Alopcune    Alopfabr    Arctlute    Arctperi    Auloalbi 
##  -1.8118034  -4.4229772  -1.6430780 -14.7012613 -14.9127415 -15.7161077 
##    Pardlugu    Pardmont    Pardnigr    Pardpull    Trocterr    Zoraspin 
##   7.9349699  -6.3785000  -5.1520389 -13.0281981  -0.1999952  -3.8441590 
## 
## $Xcoef
##            soil.dry   bare.sand fallen.leaves        moss  herb.layer
## Alopacce -0.9580696 -0.09050833    -0.3242683  0.10124549  0.73708820
## Alopcune  1.3493055 -0.45012971     0.0171826 -0.19948113  0.41919734
## Alopfabr -0.8697778  0.69550223    -0.4033527  0.54014731  0.30180782
## Arctlute  5.8764638  0.16535494    -1.6723058  0.34396786 -0.12417544
## Arctperi -1.7802096  0.23859650    -1.8760391  0.49600665  0.02128078
## Auloalbi  0.2248309 -0.04627880     0.6286176  0.06258915  4.05162146
## Pardlugu -2.5240359 -0.71558231     0.3620669 -0.37442348  0.58627107
## Pardmont  1.5850692  0.13313869    -0.5143564  0.88718490  0.73395038
## Pardnigr  2.5563703 -0.02664628    -0.8483469 -0.45644924  0.72835939
## Pardpull  3.0008808 -0.35252699    -0.4703709  0.36475658  1.95127965
## Trocterr  1.2400373 -0.23016156    -0.2275185 -0.20328000  0.44569773
## Zoraspin  2.1000129  0.11996378    -0.5721528 -0.09000736  0.61975217
##           reflection
## Alopacce  0.86935167
## Alopcune  0.42105075
## Alopfabr  0.06149616
## Arctlute -0.64289561
## Arctperi  4.00723441
## Auloalbi -0.54358192
## Pardlugu -1.16980030
## Pardmont  0.07820141
## Pardnigr -0.53365350
## Pardpull -0.36801919
## Trocterr -0.29455636
## Zoraspin -0.93149392
## 
## $inv.phi
##     Alopacce     Alopcune     Alopfabr     Arctlute     Arctperi     Auloalbi 
## 9.146737e+00 2.937857e+00 7.757592e+00 2.022399e+00 4.385230e+06 1.022941e+01 
##     Pardlugu     Pardmont     Pardnigr     Pardpull     Trocterr     Zoraspin 
## 2.770437e+01 1.990873e+00 7.672767e+00 1.667735e+01 2.643112e+01 6.321633e+00 
## 
## $phi
##     Alopacce     Alopcune     Alopfabr     Arctlute     Arctperi     Auloalbi 
## 1.093286e-01 3.403842e-01 1.289060e-01 4.944622e-01 2.280382e-07 9.775736e-02 
##     Pardlugu     Pardmont     Pardnigr     Pardpull     Trocterr     Zoraspin 
## 3.609539e-02 5.022923e-01 1.303311e-01 5.996155e-02 3.783419e-02 1.581870e-01
# confidence intervals for parameters:
confint(fitnbx)
##                                      2.5 %        97.5 %
## sigma.lv.LV1                 -6.449473e-07  6.533444e-07
## sigma.lv.LV2                  4.339237e-01  1.465992e+00
## theta.LV1.1                   1.000000e+00  1.000000e+00
## theta.LV1.2                  -1.369205e+08  1.369205e+08
## theta.LV1.3                  -7.837880e+07  7.837881e+07
## theta.LV1.4                  -1.248100e+08  1.248100e+08
## theta.LV1.5                  -4.219775e+04  4.220090e+04
## theta.LV1.6                  -5.925460e+07  5.925459e+07
## theta.LV1.7                  -2.579623e+07  2.579621e+07
## theta.LV1.8                  -1.211036e+08  1.211036e+08
## theta.LV1.9                  -1.069053e+08  1.069053e+08
## theta.LV1.10                 -7.661456e+07  7.661456e+07
## theta.LV1.11                 -5.710665e+07  5.710664e+07
## theta.LV1.12                 -8.664399e+07  8.664399e+07
## theta.LV2.1                   0.000000e+00  0.000000e+00
## theta.LV2.2                   1.000000e+00  1.000000e+00
## theta.LV2.3                  -5.150183e-02  1.219369e+00
## theta.LV2.4                  -1.944572e-01  2.498696e+00
## theta.LV2.5                  -1.229696e-03  1.230441e-03
## theta.LV2.6                   5.422453e-02  1.164665e+00
## theta.LV2.7                  -1.285614e-01  5.207062e-01
## theta.LV2.8                  -1.510936e-01  8.791728e-01
## theta.LV2.9                   4.318875e-01  1.709446e+00
## theta.LV2.10                  2.702054e-01  1.186033e+00
## theta.LV2.11                  2.336750e-01  7.643787e-01
## theta.LV2.12                  2.325701e-01  1.241622e+00
## Intercept.Alopacce           -5.315546e+00  1.691939e+00
## Intercept.Alopcune           -9.576851e+00  7.308970e-01
## Intercept.Alopfabr           -7.967770e+00  4.681614e+00
## Intercept.Arctlute           -3.137398e+01  1.971456e+00
## Intercept.Arctperi           -2.630639e+01 -3.519095e+00
## Intercept.Auloalbi           -2.247640e+01 -8.955814e+00
## Intercept.Pardlugu            3.196537e+00  1.267340e+01
## Intercept.Pardmont           -1.042939e+01 -2.327611e+00
## Intercept.Pardnigr           -1.019784e+01 -1.062381e-01
## Intercept.Pardpull           -1.860810e+01 -7.448300e+00
## Intercept.Trocterr           -2.429291e+00  2.029301e+00
## Intercept.Zoraspin           -7.699380e+00  1.106180e-02
## Xcoef.soil.dry:Alopacce      -1.627819e+00 -2.883202e-01
## Xcoef.soil.dry:Alopcune      -1.659364e-01  2.864547e+00
## Xcoef.soil.dry:Alopfabr      -1.961645e+00  2.220892e-01
## Xcoef.soil.dry:Arctlute       4.213010e-01  1.133163e+01
## Xcoef.soil.dry:Arctperi      -3.435521e+00 -1.248979e-01
## Xcoef.soil.dry:Auloalbi      -9.613383e-01  1.411000e+00
## Xcoef.soil.dry:Pardlugu      -3.776895e+00 -1.271176e+00
## Xcoef.soil.dry:Pardmont       6.322576e-01  2.537881e+00
## Xcoef.soil.dry:Pardnigr       1.053284e+00  4.059457e+00
## Xcoef.soil.dry:Pardpull       1.556373e+00  4.445389e+00
## Xcoef.soil.dry:Trocterr       5.869626e-01  1.893112e+00
## Xcoef.soil.dry:Zoraspin       9.200349e-01  3.279991e+00
## Xcoef.bare.sand:Alopacce     -3.852030e-01  2.041863e-01
## Xcoef.bare.sand:Alopcune     -9.739425e-01  7.368305e-02
## Xcoef.bare.sand:Alopfabr      1.975735e-01  1.193431e+00
## Xcoef.bare.sand:Arctlute     -1.533905e+00  1.864615e+00
## Xcoef.bare.sand:Arctperi     -6.816265e-01  1.158820e+00
## Xcoef.bare.sand:Auloalbi     -4.622025e-01  3.696449e-01
## Xcoef.bare.sand:Pardlugu     -1.248497e+00 -1.826675e-01
## Xcoef.bare.sand:Pardmont     -1.853032e-01  4.515806e-01
## Xcoef.bare.sand:Pardnigr     -5.133315e-01  4.600389e-01
## Xcoef.bare.sand:Pardpull     -8.538039e-01  1.487499e-01
## Xcoef.bare.sand:Trocterr     -4.443042e-01 -1.601889e-02
## Xcoef.bare.sand:Zoraspin     -2.625610e-01  5.024886e-01
## Xcoef.fallen.leaves:Alopacce -9.896539e-01  3.411172e-01
## Xcoef.fallen.leaves:Alopcune -5.799276e-01  6.142928e-01
## Xcoef.fallen.leaves:Alopfabr -1.537152e+00  7.304470e-01
## Xcoef.fallen.leaves:Arctlute -3.798849e+00  4.542370e-01
## Xcoef.fallen.leaves:Arctperi -1.673561e+02  1.636040e+02
## Xcoef.fallen.leaves:Auloalbi  1.124858e-01  1.144749e+00
## Xcoef.fallen.leaves:Pardlugu  3.911008e-02  6.850237e-01
## Xcoef.fallen.leaves:Pardmont -1.026861e+00 -1.851484e-03
## Xcoef.fallen.leaves:Pardnigr -1.464693e+00 -2.320013e-01
## Xcoef.fallen.leaves:Pardpull -9.509773e-01  1.023561e-02
## Xcoef.fallen.leaves:Trocterr -4.819962e-01  2.695925e-02
## Xcoef.fallen.leaves:Zoraspin -1.030295e+00 -1.140110e-01
## Xcoef.moss:Alopacce          -2.226192e-01  4.251102e-01
## Xcoef.moss:Alopcune          -7.951878e-01  3.962256e-01
## Xcoef.moss:Alopfabr           1.287561e-02  1.067419e+00
## Xcoef.moss:Arctlute          -9.128146e-01  1.600750e+00
## Xcoef.moss:Arctperi          -1.220231e-01  1.114036e+00
## Xcoef.moss:Auloalbi          -4.179853e-01  5.431636e-01
## Xcoef.moss:Pardlugu          -8.457072e-01  9.686023e-02
## Xcoef.moss:Pardmont           4.272490e-01  1.347121e+00
## Xcoef.moss:Pardnigr          -1.039383e+00  1.264850e-01
## Xcoef.moss:Pardpull          -8.542468e-02  8.149378e-01
## Xcoef.moss:Trocterr          -4.720118e-01  6.545176e-02
## Xcoef.moss:Zoraspin          -5.685103e-01  3.884955e-01
## Xcoef.herb.layer:Alopacce     3.371456e-01  1.137031e+00
## Xcoef.herb.layer:Alopcune    -3.383310e-01  1.176726e+00
## Xcoef.herb.layer:Alopfabr    -2.708919e-01  8.745076e-01
## Xcoef.herb.layer:Arctlute    -3.062448e+00  2.814097e+00
## Xcoef.herb.layer:Arctperi    -4.106232e-01  4.531848e-01
## Xcoef.herb.layer:Auloalbi     2.457165e+00  5.646078e+00
## Xcoef.herb.layer:Pardlugu     2.739258e-01  8.986164e-01
## Xcoef.herb.layer:Pardmont     4.636978e-02  1.421531e+00
## Xcoef.herb.layer:Pardnigr    -1.339361e-01  1.590655e+00
## Xcoef.herb.layer:Pardpull     9.272378e-01  2.975321e+00
## Xcoef.herb.layer:Trocterr     1.164534e-01  7.749420e-01
## Xcoef.herb.layer:Zoraspin    -1.629915e-02  1.255804e+00
## Xcoef.reflection:Alopacce     3.390305e-01  1.399673e+00
## Xcoef.reflection:Alopcune    -3.763276e-01  1.218429e+00
## Xcoef.reflection:Alopfabr    -9.861328e-01  1.109125e+00
## Xcoef.reflection:Arctlute    -1.930076e+00  6.442852e-01
## Xcoef.reflection:Arctperi     1.461087e+00  6.553382e+00
## Xcoef.reflection:Auloalbi    -1.141760e+00  5.459662e-02
## Xcoef.reflection:Pardlugu    -1.807600e+00 -5.320006e-01
## Xcoef.reflection:Pardmont    -5.106481e-01  6.670509e-01
## Xcoef.reflection:Pardnigr    -1.302713e+00  2.354060e-01
## Xcoef.reflection:Pardpull    -8.994784e-01  1.634400e-01
## Xcoef.reflection:Trocterr    -6.348769e-01  4.576424e-02
## Xcoef.reflection:Zoraspin    -1.527771e+00 -3.352165e-01
## inv.phi.Alopacce             -1.056783e+01  2.886131e+01
## inv.phi.Alopcune             -7.217570e-02  5.947889e+00
## inv.phi.Alopfabr             -8.212985e+00  2.372817e+01
## inv.phi.Arctlute             -1.057543e+00  5.102341e+00
## inv.phi.Arctperi             -5.194026e+09  5.202797e+09
## inv.phi.Auloalbi             -3.755134e+00  2.421395e+01
## inv.phi.Pardlugu             -4.815644e+01  1.035652e+02
## inv.phi.Pardmont              5.020224e-01  3.479723e+00
## inv.phi.Pardnigr             -1.346396e+00  1.669193e+01
## inv.phi.Pardpull             -4.389429e+00  3.774414e+01
## inv.phi.Trocterr             -3.376966e+00  5.623921e+01
## inv.phi.Zoraspin             -1.191355e+00  1.383462e+01
Problems? See hints:

I have problems in model fitting. My model converges to infinity or local maxima: GLLVMs are complex models where starting values have a big role. Choosing a different starting value method (see argument starting.val) or use multiple runs and pick up the one giving highest log-likelihood value using argument n.init. More variation to the starting points can be added with jitter.var.

My results does not look the same as in answers: The results may not be exactly the same as in the answers, as the initial values for each model fit are slightly different, so the results may also differ slightly.

Ordination

GLLVM as a model based ordination method

Ordination plot

Biplot

ordiplot(fitnb, biplot = TRUE)
abline(h = 0, v = 0, lty=2)

Environmental gradients

# Arbitrary color palette, a vector length of 20. Can use, for example, colorRampPalette from package grDevices
rbPal <- c("#00FA9A", "#00EC9F", "#00DFA4", "#00D2A9", "#00C5AF", "#00B8B4", "#00ABB9", "#009DBF", "#0090C4", "#0083C9", "#0076CF", "#0069D4", "#005CD9", "#004EDF", "#0041E4", "#0034E9", "#0027EF", "#001AF4", "#000DF9", "#0000FF")
X <- spider$x
par(mfrow = c(3,2), mar=c(4,4,2,2))
for(i in 1:ncol(X)){
Col <- rbPal[as.numeric(cut(X[,i], breaks = 20))]
ordiplot(fitnb, symbols = T, s.colors = Col, main = colnames(X)[i], 
         biplot = TRUE)
}


  1. Niku, J., F.K.C. Hui, S. Taskinen, and D.I. Warton. 2019. Gllvm - Fast Analysis of Multivariate Abundance Data with Generalized Linear Latent Variable Models in R. 10. Methods in Ecology and Evolution: 2173–82↩︎

  2. Kasper Kristensen, Anders Nielsen, Casper W. Berg, Hans Skaug, Bradley M. Bell (2016). TMB: Automatic Differentiation and Laplace Approximation. Journal of Statistical Software, 70(5), 1-21↩︎

  3. Hui, F. K. C., Warton, D., Ormerod, J., Haapaniemi, V., and Taskinen, S. (2017). Variational approximations for generalized linear latent variable models. Journal of Computational and Graphical Statistics. Journal of Computational and Graphical Statistics, 26:35-43↩︎

  4. Korhonen, P., Hui, F. K. C., Niku, J., and Taskinen, S. (2021). Fast, universal estimation of latent variable models using extended variational approximations, arXiv:2107.02627 .↩︎

  5. Niku, J., Warton, D. I., Hui, F. K. C., and Taskinen, S. (2017). Generalized linear latent variable models for multivariate count and biomass data in ecology. Journal of Agricultural, Biological, and Environmental Statistics, 22:498-522.↩︎

  6. van der Aart, P. J. M., and Smeenk-Enserink, N. (1975) Correlations between distributions of hunting spiders (Lycosidae, Ctenidae) and environmental characteristics in a dune area. Netherlands Journal of Zoology 25, 1-45.↩︎

  7. Dunn, P. K., and Smyth, G. K. (1996). Randomized quantile residuals. Journal of Computational and Graphical Statistics, 5, 236-244.↩︎

  8. Gabriel, K. R. (1971). The biplot graphic display of matrices with application to principal component analysis. Biometrika, 58, 453-467↩︎

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.