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.
Arguments
- fit
A fitted
lameobject.- 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. IfFALSE, uses the original posterior means (a much rougher approximation).- ...
Passed to the refit
lame()call (typicallynscan,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 (effective number of parameters), per_period
(data frame with period, elpd, n_obs), and
periods (the periods evaluated).
Examples
# \donttest{
data(YX_bin_list)
fit <- lame(YX_bin_list$Y, YX_bin_list$X, family = "binary", R = 0,
dynamic_beta = "dyad",
nscan = 60, burn = 15, odens = 5, verbose = FALSE)
#> Warning: `family` = "binary" but `Y` contains values other than 0/1.
#> ℹ `Y` will be thresholded to `1 * (Y > 0)`; if you meant counts, use "poisson",
#> or "ordinal"/"normal" as appropriate.
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: -3686.3
#> period elpd n_obs
#> 4 -3686.346 2450
# }