Getting started with lame
Cassy Dorff, Shahryar Minhas, and Tosin Salau
2026-12-02
Source:vignettes/lame.Rmd
lame.RmdWhat the model is
lame fits additive and multiplicative effects models for
network data. Each actor has a tendency to send ties and a tendency to
receive them. A dyadic correlation captures reciprocity when ties within
a pair move together. A product of latent positions,
,
captures who goes with whom beyond what covariates and actor tendencies
explain. The same function, ame(), fits binary, count,
ordinal, and continuous ties.
The data
lazegalaw holds three networks among the 71 lawyers of a
law firm, with each lawyer’s office, practice, and status. The example
uses the advice network, in which a tie from one lawyer to another means
that the first goes to the second for advice. Two dyadic covariates
record whether a pair works in the same office and in the same
practice.
library(lame)
library(ggplot2)
data(lazegalaw)
lawyers <- sprintf("L%02d", 1:71)
Y <- lazegalaw$Y[, , "advice"]
X <- lazegalaw$X
dimnames(Y) <- list(lawyers, lawyers)
rownames(X) <- lawyers
xdyad <- array(NA, c(71, 71, 2), dimnames = list(lawyers, lawyers,
c("same_office", "same_practice")))
xdyad[, , 1] <- outer(X[, "office"], X[, "office"], "==")
xdyad[, , 2] <- outer(X[, "practice"], X[, "practice"], "==")The fit
The call below fits a binary model with sender and receiver effects, reciprocity, two dyadic covariates, and two latent dimensions. It runs two chains of 40,000 iterations each, which takes about four and a half minutes.
fit <- ame(Y, Xdyad = xdyad, family = "binary", R = 2,
gof = TRUE, burn = 1000, nscan = 40000, odens = 40, seed = 6886,
chains = 2, verbose = FALSE)The coefficients
summary(fit)
#>
#> ── AME model summary ───────────────────────────────────────────────────────────
#>
#> ── Call
#> Y ~ intercept + dyad(same_office, same_practice) + a[i] + b[j] + rho*e[ji] + U[i,1:2] %*% V[j,1:2], family = 'binary'
#>
#> ── Regression coefficients
#> Estimate StdError z_value p_value CI_lower CI_upper Rhat
#> intercept -2.199 0.152 -14.494 0 -2.498 -1.916 1.001
#> same_office_dyad 0.303 0.113 2.674 0.007 0.085 0.524 1.001
#> same_practice_dyad 0.223 0.072 3.099 0.002 0.081 0.36 1.001
#> Threshold ESS
#> intercept 1.05 1870.268 ***
#> same_office_dyad 1.05 1707.036 **
#> same_practice_dyad 1.05 1796.087 **
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> ℹ Stars are a visual hint from the posterior mean / SD only; for inference use
#> the credible intervals.
#>
#> ── Variance components
#> Estimate StdError Rhat Threshold ESS
#> va 0.373 0.094 1 1.05 1772.819
#> cab 0.019 0.062 1 1.05 1801.702
#> vb 0.382 0.106 1 1.05 1257.350
#> rho 0.116 0.091 1 1.05 1681.355
#> va = sender variance, cab = sender-receiver covariance, vb = receiver
#> variance, rho = dyadic correlation
#> • Latent dimensions: 64%, 36% of the latent product
#> ℹ Threshold is the R-hat the between-chain gate held each monitored quantity
#> to: 1.05, or the R-hat that settled chains with the same effective draws
#> reach by chance, if larger.
#> ✔ The chains agree on every monitored quantity (R-hat at most its threshold, with enough effective draws to compare).The table gives the posterior mean, standard error, and 95% credible
interval on the probit scale. Lawyers in the same office and in the same
practice are more likely to go to each other for advice. The variances
va and vb show that lawyers differ both in how
much advice they seek and in how often they are asked. The Rhat and ESS
columns are the convergence check: the two chains agree on every
row.
Does the model reproduce the network
gof_plot() compares five statistics of the observed
network with the same statistics in networks simulated from the fit. The
second plot is the same model with no latent term
(R = 0).
gof_plot(fit)

With two dimensions, all five observed statistics fall inside the simulated ranges. Without the latent term, the observed transitivity lies far above every simulated value. The latent positions are what lets the model reproduce the clustering of advice ties.
The latent positions
fit$U holds the position of each lawyer as a sender of
ties, and fit$V the position as a receiver. The plot shows
the sender positions, with partners and associates marked.
pos <- data.frame(
d1 = fit$U[, 1],
d2 = fit$U[, 2],
status = ifelse(X[rownames(fit$U), "status"] == 1, "Partner", "Associate")
)
ggplot(pos, aes(d1, d2, shape = status)) +
geom_point(colour = "grey30", size = 2.5) +
scale_shape_manual(values = c(Associate = 1, Partner = 16)) +
labs(x = "Dimension 1", y = "Dimension 2", shape = NULL) +
theme_bw() +
theme(panel.border = element_blank(), legend.position = "top")
The model was not told who is a partner, and the second dimension
separates most partners from most associates.
latent_positions(fit) returns the positions of senders and
receivers as a data frame, and uv_plot(fit) draws both
together.
Where next
- For a two-mode network, such as people and the events they attend,
set
mode = "bipartite"and give a rank for each side withR_rowandR_col.vignette("dynamic")fits a two-mode network observed over time. -
vignette("fast_estimation")gives a fast estimate without sampling.