Skip to contents

When two latent-variable fits use the same traits, the loading matrices are only identified up to rotation and sign. Procrustes alignment finds the orthogonal transform that brings one matrix as close as possible to the other, then reports the residual disagreement. This is mainly a validation helper for comparing gllvmTMB() with another implementation.

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, trait = "trait", unit = "site")
fit_t <- glmmTMB::glmmTMB(value ~ 0 + trait + rr(0 + trait | site, d = 2),
                         data = df, REML = FALSE)
L_g <- extract_ordination(fit_g, "unit")$loadings
L_t <- attr(glmmTMB::ranef(fit_t)$cond$site, "loadings")
compare_loadings(L_g, L_t)
} # }