Skip to contents

What the fast route is

ame() and lame() fit additive and multiplicative effects models with a sampler. ame_als() and lame_als() fit the same model without sampling: they estimate it by alternating fits and give standard errors from the fitted model. A fit takes seconds where a chain takes minutes.

The examples use IR90s, log exports among the 30 countries with the largest GDP in 1990, with country and country-pair covariates.

data(IR90s)
top <- order(-IR90s$nodevars[, "gdp"])[1:30]
Y <- log(IR90s$dyadvars[top, top, "exports"] + 1)
diag(Y) <- NA
node <- IR90s$nodevars[top, ]
X_node <- cbind(`Log population` = log(node[, "pop"]),
    `Log GDP` = log(node[, "gdp"]), Polity = node[, "polity"])
dyad <- IR90s$dyadvars[top, top, ]
X_dyad <- array(NA, c(30, 30, 4), dimnames = list(rownames(Y), colnames(Y),
    c("Conflicts", "Log distance", "Shared IGOs", "Polity interaction (per 100)")))
X_dyad[, , 1] <- dyad[, , "conflicts"]
X_dyad[, , 2] <- log(dyad[, , "distance"])
X_dyad[, , 3] <- dyad[, , "shared_igos"]
X_dyad[, , 4] <- dyad[, , "polity_int"] / 100

A rank-2 fit

R = 2 gives each country two latent positions. The country covariates enter as Xrow for exporters and Xcol for importers.

t_fast <- system.time(
    fit <- ame_als(Y, Xdyad = X_dyad, Xrow = X_node, Xcol = X_node, R = 2,
        family = "normal", verbose = FALSE, seed = 1)
)[["elapsed"]]
summary(fit)
#> 
#> ── AME exploration summary ──
#> 
#> Algorithm: iterative block coordinate descent (Hoff & Minhas SIR estimator)
#> Family: normal | Mode: unipartite | R = 2
#> Network: 30 x 30, 1 time slice, 10 covariates
#> Converged: TRUE (27 iterations); deviance = 19.6319 (optimiser objective
#> 278.1799)
#> • Latent dimensions: 86%, 14% of the latent product
#> Estimator: empirical Bayes (exact Gaussian cell with the variance of the noise
#> by EM, Gaussian prior on the actor effects, covariance by EM, variational
#> posterior of the effects and factors, coefficients and scales by empirical
#> Bayes)
#> ────────────────────────────────────────────────────────────────────────────────
#> Regression coefficients
#>                                   Estimate Std.Error CI 2.5% CI 97.5%
#> intercept                          -4.1625    0.7203 -5.5742  -2.7507
#> Conflicts_dyad                     -0.0315    0.0374 -0.1049   0.0418
#> Log distance_dyad                  -0.2828    0.0293 -0.3402  -0.2253
#> Shared IGOs_dyad                    0.0151    0.0021  0.0109   0.0193
#> Polity interaction (per 100)_dyad  -0.1318    0.0413 -0.2128  -0.0507
#> Log population_row                 -0.2632    0.0751 -0.4104  -0.1160
#> Log GDP_row                         0.5624    0.0894  0.3873   0.7376
#> Polity_row                         -0.0081    0.0117 -0.0309   0.0148
#> Log population_col                 -0.2300    0.0711 -0.3694  -0.0906
#> Log GDP_col                         0.5243    0.0857  0.3564   0.6922
#> Polity_col                          0.0007    0.0110 -0.0208   0.0222
#> 
#> Variance components
#>     Estimate Std.Error CI 2.5% CI 97.5%
#> va    0.0880    0.0247  0.0488   0.1467
#> cab   0.0689    0.0214  0.0340   0.0829
#> vb    0.0780    0.0220  0.0431   0.1304
#> rho   0.7025    0.0241  0.6521   0.7467
#> ve    0.0612    0.0035  0.0546   0.0685
#> va/vb: variances of the sender/receiver effects | cab: their covariance | rho:
#> dyadic residual reciprocity | ve: residual variance.
#> va, cab and vb are the fitted covariance of the actor effects (the model's
#> random-effect variances). The intercept, a and b carry the grand, row and
#> column means of the latent product, as ame() reports them; fit$eb$population
#> keeps the population intercept.
#> ────────────────────────────────────────────────────────────────────────────────
#> Empirical-Bayes estimate (normal family): the posterior means of the actor
#> effects and the latent factors (a Gaussian variational posterior), the
#> coefficients, the variance of the noise and the variance components by
#> empirical Bayes; the two cells of a dyad are a bivariate normal pair with the
#> dyadic correlation rho. For posterior summaries use ame()/lame() (MCMC).
#> Standard errors: Laplace approximation (penalised Fisher information),
#> conditional on the variance components; intervals are Wald +/- 1.96 se.
#> Variance components: the inverse Fisher information of the marginal likelihood
#> with the effects integrated out for va, cab and vb, the inverse-gamma posterior
#> less the effective number of mean parameters (normal) or the
#> marginal-likelihood profile (counts) for ve, the pair likelihood for rho;
#> intervals on the log scale for variances (va and vb centred at the lognormal
#> median of their posterior mean), the Fisher z scale for rho and score-type,
#> inside its bound, for cab.
#> Posterior sds of the reported actor effects, positions and product cells (delta
#> method under the joint Laplace covariance): `fit$a_sd`, `fit$b_sd`, `fit$U_sd`,
#> `fit$V_sd`, `fit$UVPM_sd`; `latent_positions()` reports them as `posterior_sd`.

The fit took 2 seconds. The coefficient table gives each estimate with its standard error and 95% interval. Exports fall with distance and rise with the GDP of the exporter and of the importer. coef(), vcov() and confint() return the estimates, their covariance matrix and the intervals.

Choosing the rank

Hide a tenth of the observed cells, fit without them, and score the fitted values on them by the mean log density. Higher is better. Rank 0 has no latent term. The table averages five random masks.

ranks <- 0:3
score <- sapply(ranks, function(R) {
    mean(sapply(1:5, function(s) {
        set.seed(s)
        obs <- which(!is.na(Y))
        mask <- matrix(FALSE, nrow(Y), ncol(Y))
        mask[sample(obs, round(0.1 * length(obs)))] <- TRUE
        Y_hide <- Y
        Y_hide[mask] <- NA
        f <- ame_als(Y_hide, Xdyad = X_dyad, Xrow = X_node, Xcol = X_node, R = R,
            family = "normal", verbose = FALSE, seed = 1)
        evaluate_heldout(Y, f$YPM, mask, family = "normal", fit = f)$mean_logdens
    }))
})
knitr::kable(data.frame(Rank = ranks, `Held-out score` = score, check.names = FALSE),
    digits = 3, align = "lc")
Rank Held-out score
0 -0.401
1 -0.308
2 -0.233
3 -0.261

Rank 2 has the highest average score.

Bootstrap standard errors

bootstrap = refits the model to networks simulated from the fit and reports the spread of the coefficients. Two hundred refits take about a minute and a half. The bootstrap standard deviations are close to the default standard errors.

boot <- ame_als(Y, Xdyad = X_dyad, Xrow = X_node, Xcol = X_node, R = 2,
    family = "normal", verbose = FALSE, seed = 1, bootstrap = 200,
    bootstrap_type = "parametric", bootstrap_seed = 1)
se <- sqrt(diag(vcov(fit)))
boot_sd <- apply(boot$bootstrap$coefs, 2, sd)
labels <- c("Intercept", dimnames(X_dyad)[[3]], paste(colnames(X_node), "(exporter)"),
    paste(colnames(X_node), "(importer)"))
knitr::kable(
    data.frame(Coefficient = labels, `Default SE` = se, `Bootstrap SD` = boot_sd,
        check.names = FALSE),
    digits = 3, row.names = FALSE, align = c("l", "c", "c"))
Coefficient Default SE Bootstrap SD
Intercept 0.720 0.670
Conflicts 0.037 0.036
Log distance 0.029 0.029
Shared IGOs 0.002 0.002
Polity interaction (per 100) 0.041 0.041
Log population (exporter) 0.075 0.074
Log GDP (exporter) 0.089 0.086
Polity (exporter) 0.012 0.011
Log population (importer) 0.071 0.070
Log GDP (importer) 0.086 0.083
Polity (importer) 0.011 0.011

Panels and outcome types

lame_als() takes a list of matrices, one per period, and a list of dyadic covariate arrays, in the same way. lame() with method = "als" adds effects and positions that move over time, as in vignette("dynamic").

The fast route fits normal, binary and count outcomes.