Skip to contents

Generate predictions from a fitted longitudinal AME model. Returns a list of matrices (one per time point) on the requested scale.

Usage

# S3 method for class 'lame'
predict(
  object,
  newdata = NULL,
  type = c("response", "link"),
  h = 0L,
  by_draw = FALSE,
  interval = c("none", "credible", "prediction"),
  probs = c(0.025, 0.975),
  newexposure = NULL,
  n_draws = NULL,
  seed = NULL,
  ...
)

Arguments

object

Fitted LAME model object.

newdata

Optional dyadic covariate arrays. With h = 0, a list of T arrays ([n_row, n_col, p] each, same actors as the fit) for counterfactual in-sample predictions; NULL returns the training-data predictions. With h > 0, a list of h arrays for the future periods; NULL reuses the last fitted period's covariates, which scores the forecast against stale covariates whenever they vary over time.

type

Character; "response" (default) or "link".

h

Integer >= 0: forecast horizon. When h = 0 (default), returns in-sample predictions as before. When h > 0, propagates the AR(1) (or RW1) state-space model forward by h periods and returns a list of h matrices (one per future period). Requires at least one dynamic component on the fit. Warns when posterior \(\rho_\beta\) is near 1. Coefficient innovations retain the fitted design-based scale. An AR(1) coefficient reverts to its long-run mean and an RW1 coefficient keeps its last level; an RW2 or Matern 3/2 coefficient is drawn from the Gaussian conditional of its prior over the fitted and future periods (an RW2 path extends its last slope, a Matern path returns toward zero over its length scale), each at the draw's innovation scale. Dynamic coefficient forecasts require equally spaced periods; actor-specific coefficient laws are refused.

by_draw

When TRUE and h > 0, returns an n x n x h x n_draws array of per-draw forecasts instead of per-period means.

interval

One of "none" (default), "credible" or "prediction". When h > 0, the per-period output is a list of length-3 lists with $lower, $median, $upper matrices computed at the probs quantiles across posterior draws. "credible" is the interval of the conditional mean \(E[Y_{T+h} \mid \theta_{T+h}]\) given each propagated parameter state: it carries the posterior uncertainty in that state and adds no observation noise, so it is narrower than the spread of realised outcomes and under-covers them (on simulated 30-actor normal panels its nominal 95 percent interval covered 51 to 61 percent of held-out cells). "prediction" adds the outcome noise on top of that mean: a draw from \(N(\eta, ve)\) per posterior draw and cell for "normal", a count from \(Poisson(e^{z})\) with \(z \sim N(\eta, ve)\) for "poisson". For explicit ordinal models, credible intervals summarize numeric category expectations using matched saved cutpoints; prediction intervals summarize category draws including unit Gaussian observation noise. For "binary" and data-induced ordinal models, this option retains the existing credible interval convention and reports that choice. Ignored for in-sample (h = 0) predictions. Outcome forecasts preserve symmetric and within-dyad observation dependence. Their unipartite diagonals are missing; bipartite diagonal cells are retained. They are refused for dynamic_rho = TRUE, which supplies no law for future reciprocity; conditional-mean forecasts remain available.

probs

Length-2 vector of lower / upper quantiles for the interval when interval is "credible" or "prediction". Default c(0.025, 0.975).

newexposure

Optional length-h non-negative numeric vector of future-period exposures (Poisson only). When omitted and the fit has period_exposure stored, defaults to the last observed exposure; when both are absent, defaults to 1.

n_draws

Number of posterior draws to use when h > 0. Default NULL uses all stored draws. Ignored for in-sample (h = 0) predictions.

seed

Optional RNG seed for the h > 0 forecast draws, making forecasts reproducible. Ignored when h = 0.

...

Additional arguments (not used).

Value

With interval = "none" and by_draw = FALSE, a list of prediction matrices (one per period, or per horizon when h > 0). With by_draw = TRUE, an [n_row, n_col, h, n_draws] array. With interval = "credible" or "prediction", a list of h lists holding $lower, $median and $upper matrices.

Details

For h > 0 only \(U_t V_t'\) is identified, so each posterior draw of the coordinates carries its own rotation and sign and the product of the posterior-mean coordinates falls well short of the posterior mean of the product (UVPM, or ULUPM on symmetric fits). Under the element-wise AR(1), \(E[u_{T+h} v_{T+h}'] = \rho_{uv}^{2h} E[u_T v_T']\) off the diagonal, so the forecast carries UVPM at period \(T\) forward by \(\rho_{uv}^{2h}\) and each draw's propagated coordinates enter only as the deviation around that mean. Static positions are carried forward unchanged. Dynamic additive effects are propagated as their actor level plus an AR(1) deviation.

For MCMC Poisson models the response is the mean count of a cell in a period, \(e_t \exp(\eta + \sigma^2 / 2)\), with \(e_t\) the exposure of the period (period_exposure; one without), \(\eta\) the posterior mean of the linear predictor and \(\sigma^2\) the posterior mean of the residual variance. The stored YPM holds it in sample, newdata predictions use the same form at the new linear predictor, and a forecast point (h > 0) uses the means of the forecast linear predictor and of the variance over the forecast draws, and the exposure newexposure. With by_draw = TRUE the draws' own conditional means, \(e \exp(\eta_s + \sigma_s^2 / 2)\), are returned and interval = "credible" summarizes them; with interval = "prediction" the summaries are of simulated counts.