Skip to contents

When fitting two models with latent() on the same dataset (e.g. a gllvmTMB fit and a glmmTMB or gllvm fit) the loadings are only identified up to rotation/sign. Procrustes alignment finds the orthogonal transform that brings one as close to the other as possible, then reports the residual disagreement. Useful as a diagnostic when validating against another package.

Usage

compare_loadings(Lambda_a, Lambda_b)

Arguments

Lambda_a, Lambda_b

Two n_traits × d loading matrices.

Value

A list with the optimal rotation R, the rotated Lambda_a_rot, and the Frobenius distance after alignment.

Examples

if (FALSE) { # \dontrun{
fit_g <- gllvmTMB(value ~ 0 + trait + latent(0+trait|site, d=2), data = df)
fit_t <- glmmTMB::glmmTMB(value ~ 0 + trait + rr(0+trait|site, d=2),
                         data = df, REML = FALSE)
L_g <- extract_ordination(fit_g, "B")$loadings
L_t <- attr(glmmTMB::ranef(fit_t)$cond$site, "loadings")
compare_loadings(L_g, L_t)
} # }