Skip to contents

For a fitted lame object with \(T\) periods, refits the model on the first \(t - 1\) periods (for each \(t\) in periods) and computes the expected log predictive density (elpd) of period \(t\) under the refit. Returns the summed elpd across all leave-out periods, along with per-period contributions.

Usage

lfo(fit, periods = NULL, refit = TRUE, ...)

Arguments

fit

A fitted lame object.

periods

Integer vector of leave-out periods to evaluate. Default is the last 3 periods (tail(seq_len(T), 3L)). Each period \(t\) must satisfy \(t \ge 2\).

refit

Logical; if TRUE (default), refits on the training window. If FALSE, scores each period under the original fit, which was estimated on every period including the one being scored, so the elpd is optimistic.

...

Passed to the refit lame() call (typically nscan, burn, odens, verbose).

Value

A list with elpd_lfo (total summed elpd), pointwise (per-dyad log-density at each leave-out period; a list of numeric vectors, one per period – unlist(pointwise) gives a flat vector suitable for loo::loo_compare()-style stacking), p_lfo (NA; an effective parameter count is not estimated by this rolling-origin calculation), per_period (data frame with period, elpd, n_obs), and periods (the periods evaluated).

Details

The one-step forecast is taken with the leave-out period's own dyadic covariates supplied as newdata. This matters because predict(fit, h = 1) called without newdata reuses the last fitted period's covariate array, which scores the held-out period against the wrong covariates whenever they vary over time.

Each dyad is scored by its posterior predictive log density, \(\log \frac{1}{S} \sum_s p(y \mid \eta_s)\), averaging the family density over the posterior draws of the forecast linear predictor rather than evaluating it once at the posterior-mean predictor. For normal and Poisson models, each predictor uses its matching residual variance draw. Poisson scoring integrates the lognormal observation effect and uses held-out exposure. Supported families are normal, binary and Poisson; symmetric networks score each unordered dyad once. Refits retain the original covariate roles, selected dynamic coefficients and user priors, recomputing empirical defaults on training data only.

Examples

# \donttest{
data(YX_bin_list)
# chains = 1 keeps the example short; the default runs two chains and compares them
fit <- lame(lapply(YX_bin_list$Y, function(y) 1 * (y > 0)), YX_bin_list$X, family = "binary", R = 0,
            dynamic_beta = "dyad", dynamic_beta_kind = "rw1",
            nscan = 60, burn = 15, odens = 5, verbose = FALSE, chains = 1)
lfo_res <- lfo(fit, periods = 4L, refit = TRUE,
               nscan = 50, burn = 10, odens = 5, verbose = FALSE)
print(lfo_res)
#> 
#> ── Exact rolling-origin LFO ──
#> 
#> Periods evaluated: 4
#> Refit per leave-out: TRUE
#> Total elpd_lfo: -370.25
#>  period      elpd n_obs
#>       4 -370.2466  2450
# }