Skip to contents

A panel is a list of matrices

A panel of networks is a named list with one matrix per period, and lame() takes this list as Y. Actors can enter and leave the panel. Each matrix holds the actors present in that period, and lame() matches them across periods by name.

The cosponsorship data follow the United States Senate through four Congresses, from 1997 to 2004. The rows are senators and the columns are 171 policy areas. A cell is 1 when the senator sponsored or cosponsored at least one bill in that area during that Congress. The last line of the chunk prints the number of senators and policy areas in each Congress.

library(lame)
library(ggplot2)
data(cosponsorship)
Y <- cosponsorship$Y
sapply(Y, dim)
#>      congress_105 congress_106 congress_107 congress_108
#> [1,]           92          102           98           89
#> [2,]          171          171          171          171

Positions that move

The model gives each senator an effect for how many areas they are active in, and each policy area an effect for how many senators it draws. Two latent dimensions on each side (R_row = 2, R_col = 2) then place the senators and the policy areas in a plane. A senator is more likely to put their name on bills in the areas that lie in the same direction as their own position, so senators who stand close together work on the same areas.

With dynamic_uv = TRUE each senator has a position in every Congress. The positions follow an AR(1) process: a senator stays near their last position unless their cosponsorships pull them elsewhere. method = "als" selects the fast route. The panel has about 65,000 cells and a position for every senator in every Congress, and the fit takes about two and a half minutes.

fit <- lame(
    Y, family = "binary", mode = "bipartite",
    R_row = 2, R_col = 2, dynamic_uv = TRUE,
    method = "als", seed = 6886, verbose = FALSE
)
summary(fit)
#> 
#> ── Dynamic ALS summary ──
#> 
#> Family: binary | Mode: bipartite | R = 2
#> Network: 111 x 171, 4 time slices
#> Dynamic UV: TRUE | Dynamic additive effects: FALSE | Dynamic beta: FALSE
#> Converged: TRUE (101 iterations); empirical-Bayes profile objective
#> (Laplace-marginal deviance, position KL, hyperprior) = 62817.5424
#> ────────────────────────────────────────────────────────────────────────────────
#> Coefficients
#>           Estimate Std.Error CI 2.5% CI 97.5%
#> intercept  -0.6875    0.0363 -0.7586  -0.6164
#> 
#> Variance summaries
#>    Estimate Std.Error CI 2.5% CI 97.5%
#> va   0.0539    0.0077  0.0408   0.0712
#> vb   0.1883    0.0211  0.1512   0.2345
#> Estimator: empirical Bayes (Gaussian prior on the actor effects, covariance by
#> EM, Laplace-marginal coefficients)
#> Additive effects: static levels (EM estimate of their covariance under the
#> `lame()` hyperprior in `fit$eb$sab`).
#> Moving latent positions (mean-field Gaussian posterior): Persistence 0.8551 and
#> innovation sd 0.4725 (stationary variance 0.8307) of the positions are
#> estimates under the lame() hyperprior (fit$eb$uv_dynamics); the data carry
#> enough signal to determine them (signal 3.31, from 2).
#> Standard errors and 95% intervals from the Laplace posterior given the
#> empirical-Bayes hyperparameters; those of the variance components by Louis'
#> identity (`fit$eb$vc_se`); effects in `fit$a_sd`, `fit$b_sd` and their paths,
#> product cells in `fit$UVPM_sd`.

The coefficient table gives the intercept on the probit scale. va and vb are the variances of the senator effects and the policy-area effects. The notes under the tables report the persistence of the positions from one Congress to the next and confirm that the panel carries enough signal to estimate it.

Where the senators stand

fit$U holds the positions as an array of senators by dimensions by Congresses. The chunk below collects the positions of the senators seated in each Congress and adds their party from the senators table.

pos <- do.call(rbind, lapply(names(Y), function(t) {
    seated <- rownames(Y[[t]])
    data.frame(
        name = seated,
        congress = paste0(sub("congress_", "", t), "th Congress"),
        d1 = fit$U[seated, 1, t],
        d2 = fit$U[seated, 2, t]
    )
}))
pos <- merge(pos, cosponsorship$senators)
two <- pos[pos$name %in% c("Jeffords, James M. [VT]", "Miller, Zell [GA]"), ]
two$label <- sub(",.*", "", two$name)
ggplot(pos, aes(d1, d2)) +
    geom_point(aes(shape = party), colour = "grey55", size = 2) +
    geom_point(data = two, size = 3) +
    geom_text(data = two, aes(label = label), vjust = -0.9, hjust = "inward", fontface = "bold") +
    scale_shape_manual(values = c(Democrat = 1, Republican = 16)) +
    facet_wrap(~congress) +
    labs(x = "Dimension 1", y = "Dimension 2", shape = NULL) +
    theme_bw() +
    theme(
        panel.border = element_blank(),
        legend.position = "top",
        strip.background = element_rect(fill = "black", colour = "black"),
        strip.text = element_text(colour = "white", hjust = 0)
    )

Positions of senators in the two latent dimensions, one panel per Congress, with Democrats as open circles and Republicans as filled circles. Jeffords and Miller are labelled in each panel.

The model was given no party labels, and the second dimension separates the two parties in every Congress.

Two senators are labelled. James Jeffords of Vermont was elected as a Republican, left the party in 2001 during the 107th Congress, and sided with the Democrats from then on. In the 105th Congress his position is between the two parties, and by the 108th it is among the Democrats. Zell Miller of Georgia, a Democrat who joined the Senate in 2000, endorsed the Republican president for re-election in 2004. In the 106th Congress, his first, his position is between the parties, and by the 108th it is among the Republicans.

Checking against hidden cells

Hide a tenth of the cells, fit without them, and score the fitted probabilities on the hidden cells by the mean log probability of what was observed. Higher is better. The first model gives each senator one position for all four Congresses, and the second lets the positions move.

set.seed(1)
hide <- lapply(Y, function(y) array(runif(length(y)) < 0.1, dim(y)))
Y_train <- Map(function(y, h) replace(y, h, NA), Y, hide)
fit_shared <- update(fit, Y = Y_train, dynamic_uv = FALSE)
fit_moving <- update(fit, Y = Y_train)
log_score <- function(f) {
    sapply(names(Y), function(t) {
        y <- Y[[t]]
        p <- fitted(f)[[t]][rownames(y), colnames(y)]
        mean(dbinom(y[hide[[t]]], 1, p[hide[[t]]], log = TRUE))
    })
}
knitr::kable(
    rbind(`Shared positions` = log_score(fit_shared), `Moving positions` = log_score(fit_moving)),
    col.names = paste0(105:108, "th"), digits = 3, align = "c"
)
105th 106th 107th 108th
Shared positions -0.563 -0.530 -0.533 -0.526
Moving positions -0.487 -0.448 -0.463 -0.456

The moving positions predict the hidden cosponsorships better in every Congress.

Where next

dynamic_ab = TRUE lets the sender and receiver effects move in the same way. Without method = "als", lame() runs the sampler with the same arguments. vignette("lame") introduces the model, and vignette("fast_estimation") covers the fast route.