JenniNiku / gllvm

Generalized Linear Latent Variable Models
https://jenniniku.github.io/gllvm/
48 stars 19 forks source link

Roweffs and coleffs #145

Closed BertvanderVeen closed 5 months ago

BertvanderVeen commented 8 months ago

1) adds random effects to gllvm for environment predictors with typical lme4-type interface. Random effects can be correlated, and potentially structured with a Phylogeny (argument "colmat" and "colMat.rho.struc") - also the 4th corner model but that without the lme4-type interface (i.e., "just" randomX as previously). Various VA covariance structures possible; "diagonal" (recommended for independent effects. one VA variance per species & RE), "MNdiagonal", "MNunstructured" (usually recommended, matrix normal VA matrix with unstructured row and column matrices), "spblockdiagonal" (independent RE VA posteriors), "diagonalsp" and "blockdiagonalsp" (VA covariances per species for REs and a single correlation matrix for all species), or "unstructured" (across REs & species, almost never recommended but useful as reference"). The calculation for "cQ" is vectorized over the number of sites. This can be coded as a nested loop instead, which is slower, but draws somewhat less memory. 2) Allows for multiple random row effects, that are independent from each other (but can have dependent groups within the effects). I sacrificed the "dependent.row" option to do this - can potentially be added back but would require building the VA covariance matrix over REs and LVs simultaneously, which gets a bit big. VA covariances are over the levels of the random effect now, and independent from the VA covariances for the latent variables. This is in to facilitate extending functionality in the future for correlation between multiple random intercepts. 3) I have started to separate "n.init" functionality into "gllvm.iter.R" which calls "gllvm.TMB" or "TMBtrait" and is called by "gllvm". This way, models can be run outside the while loop for n.init, allowing for parallelisation.

BertvanderVeen commented 8 months ago

Added a new option for "randomB": "iid", and a new function "getEnvironCov" to extract correlations due to random covariate effects.