epiverse-trace / epichains

[Under active development] Methods for simulating and analysing the sizes and lengths of infectious disease transmission chains from branching process models
https://epiverse-trace.github.io/epichains/
Other
5 stars 1 forks source link

Make `likelihood()` an S3 generic #244

Open jamesmbaazam opened 2 months ago

jamesmbaazam commented 2 months ago

The broader question is whether it would not be clearer to define S3 methods for numeric, epichains and epichains_summary where

likelihood.epichains <- function(chains, ...) {
  likelihood(summary(chains, ...))
}

likelihood.epichains_summary <- function(chains, stat_max = Inf, ...) {
  stat_max_from_sim <- attr(chains, "stat_max")
  if (missing(stat_max)) {
    stat_max <- stat_max_from_sim
  } else if (stat_max != stat_max_from_sim) {
    warning(`stat_max` is different from the one used in the simulations given in `chains`")
  }
  likelihood(as.numeric(chains, stat_max, ...))
}

and the current likelihood() becomes likelihood.numeric()

_Originally posted by @sbfnk in https://github.com/epiverse-trace/epichains/pull/213#discussion_r1588871470_

jamesmbaazam commented 1 month ago

This blog post by Hugo is relevant to this issue: https://epiverse-trace.github.io/posts/s3-generic/.