Extracts multiplicative latent factor positions (U and V) from a fitted
ame, lame or ame_als model and returns them as a
tidy data frame suitable for plotting and analysis, with posterior standard
deviations when posterior draws of the positions are available.
Usage
latent_positions(object, ...)
# S3 method for class 'ame'
latent_positions(object, align = FALSE, ...)
# S3 method for class 'lame'
latent_positions(object, align = TRUE, ...)
# S3 method for class 'ame_als'
latent_positions(object, align = FALSE, ...)Arguments
- object
A fitted
ame,lameorame_alsmodel object with R > 0.- ...
Additional arguments (currently unused).
- align
Logical. For dynamic
ame_alsfits, apply Procrustes alignment across the time periods of the fit. It has no effect onamefits (a single period) or onlamefits, whose dynamic positions are aligned when the model is fitted (see Details).
Value
A data frame with columns:
- actor
Character. Actor name (from rownames of U or V).
- dimension
Integer. Latent dimension index (1 to R).
- time
Character. Time period label. Dynamic fits use the time labels from the input; static (cross-sectional) fits return
"1"for every row so downstream filtering bytimebehaves the same in both cases.- value
Numeric. The posterior mean latent position.
- posterior_sd
Numeric. Posterior standard deviation of the latent position, or
NAif posterior draws are not available. To enable, fit the model withposterior_opts = posterior_options(save_UV = TRUE)(static positions) orposterior_opts = list(save_UV_draws = TRUE)(dynamic positions). Aname_alsfit, or alame(method = "als")fit with static factors, reports the sd of each reported coordinate under its Laplace posterior (fit$U_sd,fit$V_sd), with the directions that leave the product unchanged left out.- type
Character.
"U"for sender/row positions,"V"for receiver/column positions. Symmetric models have only"U".
Returns a zero-row data frame with correct column names if R = 0.
For a fit with static positions (ame, lame without
dynamic_uv, and static ame_als fits) the data frame carries
an attribute "strength": a data frame with one row per dimension and
columns dimension, strength (the singular value of the
reported product for that dimension, or the absolute eigenvalue for
symmetric fits), share (its squared strength over the sum of the
squared strengths) and tied_with_next. Dimensions \(j\) and
\(j + 1\) are tied when the reported gap between their strengths is less
than twice the posterior sd of that gap over the saved draws (each draw's
own strengths): the two axes are then not well separated and are read
together as a plane, and a message says so. tied_with_next is NA for fits
without saved draws of the positions. Fits with dynamic_uv = TRUE
carry no strength attribute: their per-period positions are rotated to match
the period before, so a column is not one dimension of each period's product.
Details
The latent product of each period is identified, the positions only up to a
rotation or sign change that leaves the product unchanged. The positions of
a static ame or lame fit therefore factor the posterior mean
product at the fitted rank, with columns in decreasing order of its singular
values and the sign of each column set so that its positive entries carry
more of its squared length than its negative ones: \(U V'\) with the scale split evenly between \(U\) and
\(V\); \(U L U'\) for symmetric fits, with \(U\) orthonormal and
fit$L the eigenvalues largest in absolute value; and \(U G V'\)
for bipartite fits, with the scale split evenly and fit$G the
identity (when R_row and R_col differ, the product has rank
\(k\), the smaller of the two, the columns of fit$U or fit$V
past \(k\) are zero, and only the \(k\) dimensions are listed). The positions of
a lame fit with dynamic_uv = TRUE factor the
posterior mean product of every period at the fitted rank: \(U_t V_t'\)
with the scale split evenly between \(U_t\) and \(V_t\);
\(U_t L U_t'\) for symmetric fits, with fit$L fixed across periods;
and \(U_t G V_t'\) for bipartite fits, with a diagonal fit$G fixed
across periods. Each period is matched to the one before by moves that keep
its product. The posterior standard deviations come from the saved draws
(posterior_opts = posterior_options(save_UV = TRUE) for static
positions, posterior_opts = list(save_UV_draws = TRUE) for dynamic
ones), each draw factored the same way and matched onto the reported
positions by a move that leaves its product unchanged (a rotation, or a
relabelling and sign change of the columns when L or a dynamic
G is held fixed).
Alignment only ever happens across the periods of one fit. Nothing here aligns two
different fits (two chains, or the same model with and without a
covariate) to a common orientation, so their latent positions are not
directly comparable. To compare fits that way, stack their U
matrices into an [n, R, 2] array (same actors in the same order,
same R) and call procrustes_align(U = that_array) on it.
See also
procrustes_align for standalone Procrustes alignment,
uv_plot for visualizing latent positions,
posterior_options for enabling posterior sampling of U/V
Examples
# \donttest{
data(YX_nrm)
# chains = 1 keeps the example short; the default runs two chains and compares them
fit <- ame(YX_nrm$Y, Xdyad = YX_nrm$X, R = 2,
burn = 5, nscan = 5, odens = 1, verbose = FALSE, chains = 1)
lp <- latent_positions(fit)
head(lp)
#> actor dimension time value posterior_sd type
#> 1 node1 1 1 0.1820285 0.06411356 U
#> 2 node2 1 1 -0.6502813 0.12446819 U
#> 3 node3 1 1 -0.1695219 0.13456369 U
#> 4 node4 1 1 0.2035775 0.10322440 U
#> 5 node5 1 1 -0.2482276 0.07926787 U
#> 6 node6 1 1 -0.1786310 0.07715069 U
# }