0
$\begingroup$
my_diamonds <- diamonds %>% mutate(log_price = log(price))

my_diamonds %>% 
+   group_by(cut) %>% 
+   summarise(mean_log_exp = mean(log_price) %>% exp)
# A tibble: 5 x 2
  cut       mean_log_exp
  <ord>            <dbl>
1 Fair             3273.
2 Good             2547.
3 Very Good        2437.
4 Premium          2838.
5 Ideal            2079.
> my_diamonds %>% 
+   group_by(cut) %>% 
+   summarise(mean_price = mean(price))
# A tibble: 5 x 2
  cut       mean_price
  <ord>          <dbl>
1 Fair           4359.
2 Good           3929.
3 Very Good      3982.
4 Premium        4584.
5 Ideal          3458.

Why are these two outputs different? I expected both sets of numbers to be the same. In the first block I take the mean of the log of price for each cut then back transform to original scale with exp.

In the second block I skip the log transformation entirely. Since in the previous block I log and then unlog with exp, I expected the two sets of numbers to match.

Where have I misunderstood? Why don't the two sets of numbers match?

$\endgroup$
  • 2
    $\begingroup$ Does this answer your question? Which "mean" to use and when? Your log-transform-and-back approach is the geometric mean discussed there. The log of means is not the same as the mean of logs. $\endgroup$ – EdM Aug 3 at 17:53
  • $\begingroup$ @EdM thanks for the link. May I ask a follow up here... Suppose the variable in question is log normal. What is the 'right' mean to use if I would like a measure of centrality? Presumably the geo mean? $\endgroup$ – Doug Fir Aug 3 at 18:05
  • 2
    $\begingroup$ geo mean is typically what's used. It depends on which measure of centrality you want, as mean, median and mode all differ with a log-normal. See the Wikipedia page. $\endgroup$ – EdM Aug 3 at 21:05
  • 2
    $\begingroup$ You can do some sort of re-transformation to deal with this. I would try using Duan's methods separately for each cut. You can also use GLM model that avoids this entirely. Finally, the median might work somewhat better, but probably still suffers from the same problem as the mean. $\endgroup$ – Dimitriy V. Masterov Aug 3 at 23:18

Browse other questions tagged or ask your own question.