Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand marginal model distribution support #488

Open
seabbs opened this issue Dec 3, 2024 · 3 comments
Open

Expand marginal model distribution support #488

seabbs opened this issue Dec 3, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@seabbs
Copy link
Contributor

seabbs commented Dec 3, 2024

In #426 support was added for Weibull, Lognormal, and Gamma. primarycensored supports many more distributions that this so we can extend this. This will be easier if we wait for epinowcast/primarycensored#175

Once this has been completed we can support everything that primarycensored supports but our posterior prediction and R side log lik will be limited to distributions where brms uses an internal log_lik_censor call. I think to close this issue we should document what those are and open a new issue for extending support.

@seabbs seabbs added the enhancement New feature or request label Dec 3, 2024
@athowes
Copy link
Collaborator

athowes commented Dec 3, 2024

limited to distributions where brms uses an internal log_lik_censor call

How easy would these be to implement and submit as PRs to brms?

@seabbs
Copy link
Contributor Author

seabbs commented Dec 3, 2024

they are all internal functions and I have no idea

@athowes
Copy link
Collaborator

athowes commented Dec 3, 2024

https://github.com/paul-buerkner/brms/blob/2e5177a7df2bbdf699ac71f04dbaab8fdb9ca3da/R/log_lik.R#L990 seems to look quite a generic solution?

# ----------- log_lik helper-functions -----------
# compute (possibly censored) log_lik values
# @param dist name of a distribution for which the functions
#   d<dist> (pdf) and p<dist> (cdf) are available
# @param args additional arguments passed to pdf and cdf
# @param prep a brmsprep object
# @return vector of log_lik values
log_lik_censor <- function(dist, args, i, prep) {
  pdf <- get(paste0("d", dist), mode = "function")
  cdf <- get(paste0("p", dist), mode = "function")
  y <- prep$data$Y[i]
  cens <- prep$data$cens[i]
  if (is.null(cens) || cens == 0) {
    x <- do_call(pdf, c(y, args, log = TRUE))
  } else if (cens == 1) {
    x <- do_call(cdf, c(y, args, lower.tail = FALSE, log.p = TRUE))
  } else if (cens == -1) {
    x <- do_call(cdf, c(y, args, log.p = TRUE))
  } else if (cens == 2) {
    rcens <- prep$data$rcens[i]
    x <- log(do_call(cdf, c(rcens, args)) - do_call(cdf, c(y, args)))
  }
  x
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants