paul-buerkner/brms

Lognormal distribution with natural scale parameters

Open

#1.027 geöffnet am 28. Okt. 2020

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)R (220 Forks)batch import
familyfeaturegood first issue

Repository-Metriken

Stars
 (1.402 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 7T 21h) (1 gemergte PR in 30 T)

Beschreibung

To be more in line with the rest of the regression families I think it would be a good idea to support lognormal distribution reparameterized with mean and standard deviation on the natural scale.

Here is the reparametrization (from ProbOnto, https://sites.google.com/site/probonto/download):

image

image

I did this manually:

custom_family(name = "lognormal7", dpars = c("mu", "sigma"), 
              links = c("log", "log"), 
              lb = c(0, 0), type = "real") ->
  lognormal7


stan_funs <- "
  real lognormal7_lpdf(real y, real mu, real sigma) {
    return lognormal_lpdf(y | log(mu/sqrt(1+sigma^2/mu^2)), sqrt(log(1+sigma^2/mu^2)));
  }
  real lognormal7_rng(real mu, real sigma) {
    return lognormal_rng(log(mu/sqrt(1+sigma^2/mu^2)), sqrt(log(1+sigma^2/mu^2)));
  }
"


stanvars <- stanvar(scode = stan_funs, block = "functions")

log_lik_lognormal7 <- function(i, prep) {
  mu <- prep$dpars$mu[, i]
  sigma <- prep$dpars$sigma
  y <- prep$data$Y[i]
  lognormal7_lpdf(y, mu, sigma)
}


posterior_predict_lognormal7 <- function(i, prep, ...) {
  mu <- prep$dpars$mu[, i]
  sigma <- prep$dpars$sigma
  lognormal7_rng(mu, sigma)
}

posterior_epred_lognormal7 <- function(prep) {
  mu <- prep$dpars$mu
  return(mu)
}

I haven't tried any complex model, but a standard mtcars example works fine! (mpg ~ hp) Some initialization warnings though.

Contributor Guide