Loo with only partial log likelihood data

Hi, I was wondering if loo could be used by specifying only a part of the log likelihoods returned by the generated quantities of a stan program, for example a stan program may define:

vector[N] log_lik;

for (n in 1:N) log_lik[n] = normal_lpdf(y[n] | X[n, ] * beta, sigma);

However, I would like to ignore the first 10 observations when using the loo package (without changing the stan code). I wonder if the following code makes sense;

# y is the data, while fit_1 and fit_2 are two models that I want to compare
a <- extract_log_lik(fit_1, merge_chains = FALSE)[,,10:(length(y))]
b <- extract_log_lik(fit_2, merge_chains = FALSE)[,,10:(length(y))]
r_eff_a <- relative_eff(exp(a))
r_eff_b <- relative_eff(exp(b))
loo_compare(loo(a, r_eff = r_eff_a, moment_match = TRUE), loo(b, r_eff = r_eff_b, moment_match = TRUE))

Is this correct?

thank you

1 Like

Looks correct.

2 Likes