# Lognormal model: reporting median or geometric mean

I have a bayesian lognormal model as follows (brms package):

m = brm(y ~ 1, data = df, family = lognormal)


Model was run with default priors.

This is model's posterior samples on lognormal scale

posterior_samples(m) Is exponentiated b_Intercept the median or geometric mean of y variable?

I have seen that some websites say that this is a geometric mean, some refer to this as a median. Or if this is something different, could you please provide a formula for calculating geometric mean or median from this posterior?

posterior_samples(m) %>%
mutate(transformed = exp(b_Intercept)) %>%
posterior_summary() %>% as.data.frame() Crude median, mean and geometric mean of Y for comparison Crude geometric mean was calculated as follows: exp(mean(log(df\$y)))

Data used

set.seed(0)
pi <- 0
mu_log <- 2
sigma_log <- 0.99
N = 1000
y = (1 - rbinom(N, 1, prob = pi)) * rlnorm(N, mu_log, sigma_log)
df = data.frame(y=y)


This is tricky. The link function for brms' lognormal is the identity link by default. This means that the underlying Stan model codes the likelihood as mu = Intercept; target += lognormal_lpdf(Y | mu, sigma);, which is leads to an estimate of the median on the log scale. Thus, exp(b_Intercept) should me the median. This is supported by a small example:

set.seed(0)
N = 10000
y = rlnorm(N, 0.5, 0.5)

d = tibble(y)

model = brm(y~1, family = lognormal(), data = d)

median(y)
>>>1.655619

model %>%
mutate(b_Intercept = exp(b_Intercept)) %>%
mean_qi

# A tibble: 1 x 6
b_Intercept .lower .upper .width .point .interval
<dbl>  <dbl>  <dbl>  <dbl> <chr>  <chr>
1        1.65   1.63   1.67   0.95 mean   qi


As for the difference between geometric mean and median, it seems that the geometric mean for the lognormal is $$\exp(\mu)$$ which is the median. The difference between your estimate and your model's estimate could be due to regularization by the priors, but I can't be sure Are you willing to post the data?

• Thank you so much Demetri! I used default priors and added the data used. Updated the original post accordingly. Oct 19, 2020 at 13:07
• @st4co4 Yes, exp(b_Intercept) in the model you've provided is an estimate of the median. The median of your distribution would be exp(2) = 7.38.... This seems to be the same as the geometric mean. Its all making sense now since the mean(log(y)) is an estimate of mu, so your geometric mean calculation is an estimate of exp(mu) i.e. the median. Oct 19, 2020 at 13:11
• Thank you so much! I own you many beers now! Oct 19, 2020 at 13:12