Skip to content

generic elpd function #158

@bnicenboim

Description

@bnicenboim

I think I wrote about this some time back. But I find myself using this quite often, when I have my own likelihood values either from k-fold cross validation, or from a validation dataset.

print_dims.default <- function(x){}
## ll is the loglikelihood
elpd <- function(ll) {
  elpd_pointwise <- colLogSumExps(ll) - log(nrow(ll))
  elpd_sum <- sum(elpd_pointwise)
  se_elpd <- sqrt(ncol(ll) * var(elpd_pointwise))
  estimates <- matrix(c(elpd_sum, se_elpd), nrow = 1)
  colnames(estimates) <- c("Estimate", "SE")
  rownames(estimates) <- "elpd"
  pointwise <- matrix(elpd_pointwise, ncol = 1)
  colnames(pointwise) <- "elpd"
  out <- list(estimates = estimates, pointwise = pointwise,
              se_elpd_loo = se_elpd)
  return(structure(out, class = c( "loo")))
}

If it's not wrong, maybe consider adding it? (I could do a pull request and add proper documentation, if this is useful).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions