# Is it acceptable to take the mean of a bunch of median values?

I use a Bayesian latent variable model to construct a time series cross-sectional measure of corruption for all countries in the world from 1960 to 2010. For each country-year observation, I obtain a latent estimate $$\theta$$. To illustrate, here is the code for the model:

# run the Stan model
mod.dyn <- stan(file="DynamicLVMminfinal.stan",
data=stan.data, seed=570175513, thin = 5,
iter=8000)


Next, I calculate the median values for each column in the out$thetas object and then adding those median values as a new column named dyn.estimates to the data frame df. out <- extract(mod.dyn) df <- df[order(df$count.year.id),]
df$dyn.estimates <- apply(out$thetas, 2, median)
df$dyn.up <- apply(out$thetas, 2, quantile, 0.975)
df$dyn.lo <- apply(out$thetas, 2, quantile, 0.025)


I want to plot the average level of corruption for each year over time. To do so, I group the observations by year, and then calculate the average of dyn.estimates for that year. Here is my question. Is this mathematically/analytically defensible? That is, is it fine to take the mean of what are median values? Thanks.

• This question could be easier to answer if you explain what the latent estimate θ represents, and over what variable you are calculating median and mean. E.g. do you calculate a median of multiple observations of a single country in a single year?
– jpa
Commented Aug 27, 2023 at 9:11
• @jpa, good point. Maybe my answer is too generic, just addressing the last question, and the outcome is not the what is intended. W5698, could you outline your model in "DynamicLVMminfinal.stan"?
– Ute
Commented Aug 27, 2023 at 11:15