# Sum of medians or median of sums

I am estimating the total consumption of a community of species.

I have a dataset of total consumption for a given species based on population density and average energetic needs. This is related to body mass. I run a mixed effect MCMC model of logConsumption ~ logBodyMass, that includes phylogeny of the species as random effect. From this I have a posterior distribution of 1000 samples of consumption per species. Which I exponentiate to get the actual values and not the logged transformed values. Therefore the 1000 estimates for each species will be a right-skewed distribution.

From this dataset I want to calculate the total consumption for any given community of species. I have chosen to use the median instead of the mean since that is less affected by the skewed distributions. For any given community I get different results if I: Method 1: Estimate the median consumption per sample for the species list and then then sum them, or: Method 2: Calculate the median consumption per species first, and then take the sum of medians for the particular species community.

1. Is method 1 wrong?
2. Is one method better than the other?
3. What measure is the best to show uncertainty for the community. Standard deviation is not good when I use medians I assume?
4. Should I have used means instead? Since then the order doesn't matter?

Code example below. Method 2 is always larger.

# A simple simulation of 1 cell, 10 species, and 100 samples of consumption
# Code in R

set.seed(42)

# Number of species
species <- 1:10

# For one grid cell simulate 100 consumptions per species (log-distributed)
consumption <- sapply(species, function(.) rlnorm(100, meanlog = log(.), sdlog = 1))
# 10 columns (1 for each species)
# 100 rows (1 for each sample of the right skewed distributions)

# METHOD 1:
# Calculate median species consumption across simulations
species.medians <- apply(consumption, 2, median)
# Find median consumption in cell
(total.consumption.1 <- sum(species.medians))
[1] 55.3787

# METHOD 2:
# Calculate total species consumption per cell per simulation
cell.sums <- apply(consumption, 1, sum)
# Find median consumption across all simulations
(total.consumption.2 <- median(cell.sums))
[1] 78.89258

# Increase: (New method will always produce a larger number)
(total.consumption.2 - total.consumption.1)/total.consumption.1*100
[1] 42.46014

• They are not the same. Could you tell use more on what exactly are you trying to achieve? What is your data? What is the research question?
– Tim
Jan 9, 2023 at 13:33
• I read that. But I am still not sure what the correct method is. I am leaning towards method 2. I have data on animal biomass consumption per species (a posterior distribution with 1000 samples), and I have different species assemblages. I want to calculate the total community consumption. Jan 9, 2023 at 13:40
• For a more detailed answer, you'd need to give us more details about your research, as stated above. Please edit the question for the details.
– Tim
Jan 9, 2023 at 13:46
• I though I just did that? What kind of details do you need? Jan 9, 2023 at 13:50
• What do you know about the distribution of the data? How was it gathered? Is there any dependence between the species? ... etc. The more details you can give, the more relevant answer you can get.
– Tim
Jan 9, 2023 at 13:53

Sums and means are tied together by definition. The fact that a distribution is right-skewed does not undermine this.

The median is essentially useless for getting at totals unless a distribution is symmetric (and it might not be ideal even then). My monthly expenditure is skewed too, as every now and again there are spikes with large outgoings, but neither my bank manager nor my spouse would find the median informative for judging total flows.

There is a serious issue of resistance or robustness: estimates of totals are necessarily sensitive to outliers, just as are estimates of means, but medians don't solve this. It is more a matter of flagging sensitivity in your discussions, e.g. within a paper, report or thesis. You could show the effect of omitting a few large values, or indeed discuss how far you know which the largest values are and/or what difficulties arise in their measurement.

EDIT It would always be possible to report

1. Totals based on means and totals based on medians so that readers can see the difference. There are intermediate cases, notably that means and medians are limiting cases of trimmed means.

2. Bootstrap or jackknife indications of variability.

• So to understand you correctly. You think it is a mistake to use the median either before or after, and we should use the mean in this case. For clarification of the issue I have also added a bit more context in an edit of the question. Jan 9, 2023 at 15:23
• In short. yes. Consider your own results. I am guessing that your means are much bigger than your medians, which is common (not absolutely universal though) for right-skewed distributions. Jan 9, 2023 at 15:26
• Yes about 10-30 % higher. Jan 9, 2023 at 15:49
• The problem is that medians are not affected by the transformation from log scale to normal scale. While means are - therefore I think medians are a more fair option. Further if the medians of the distribution is not affected by the uncertainty of the estimate - while the mean certainly will increase with a larger spread on the log scale. Jan 11, 2023 at 12:55
• @RasmusØ.Pedersen Maybe you can think of it like this: If you have an empirical distribution of consumptions of unknown shape, the total consumption is the sum. The sum is n times the mean, but you can't reconstruct the sum from the median. The advantage of the median is its robustness to extreme values, however this is only an advantage if the extreme values are in fact wrong. If they are correct, they contribute to the sum in a way you should be interested in, and this is reflected by the mean, and ignored by the median. Jan 13, 2023 at 11:35