Learn R Programming

lame (version 1.3.4)

lfo: Exact rolling-origin leave-future-out cross-validation

Description

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, ...)

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).

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, uses the original posterior means (a much rougher approximation).

...

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

Examples

Run this code
# \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)
lfo_res <- lfo(fit, periods = 4L, refit = TRUE,
               nscan = 50, burn = 10, odens = 5, verbose = FALSE)
print(lfo_res)
# }

Run the code above in your browser using DataLab