0

I have a dataset for which I want to calculate the geometric mean and the bootstrapped confidence interval. The data has "status" and and "index" ranging from 0 to 1.

I want to know: (a) Is there an option where the fun.y = mean can be replaced by a specific geometric mean function in ggplot2?

(b)How to plot appropriate confidence intervals given this mean using ggplot?

Here is the code that I have attempted to calculate.

status <- c("low","low","low","low","high","high","high","high")
 index <- c(0.6,0.1,0.6,0.1,0.35,0.35,0.35, 0.35)
df <- data.frame(status, index)


pd <- position_dodge(0.82)
ggplot(df, aes(x=status, y=index, color = status)) + ylim(0,1) + theme_bw() +  geom_point(position = pd, size = 1.5)+   stat_summary(aes(color = status),geom="errorbar", fun.data=mean_cl_boot, width = 0.2, size = 0.8, position = pd)+
   stat_summary(aes(group = status),fun.y=mean, position = pd, geom = "point", size = 4 )
Rspacer
  • 2,369
  • 1
  • 14
  • 40
  • 1
    Just perform a log transformation on your data. It's mathematically equivalent to the geometric mean. – thc May 09 '19 at 21:58
  • gm_mean function given here: https://stackoverflow.com/a/25555105/6851825 . But what would you like to do with 0 or negative numbers? – Jon Spring May 09 '19 at 22:00
  • Thanks. I have edited the question to remove the negative numbers. I can accomodate 0s in the data by using (b) – Rspacer May 09 '19 at 22:05
  • This link is useful, however the bootstrapped confidence intervals don't work. – Rspacer May 09 '19 at 22:06
  • *"Since these data have 0s, how can I replace the fun.y with an geometric mean approximation"* That sounds like a statistically very questionable thing to do. Can you elaborate on what the bigger goal is here? Generally I'd be very suspicious of any justification to change/modify original data. – Maurits Evers May 09 '19 at 22:09
  • @MauritsEvers It has too much backstory. So for simplicity, I have edited the question to ask what I'm primarily interested in. – Rspacer May 09 '19 at 22:27
  • using `fun.data = "mean_cl_boot"` gives a mean and a bootstrapped confidence interval. [More infor here](https://stackoverflow.com/questions/17414565/interpretation-of-stat-summary-mean-cl-boot-at-ggplot2) – Croote May 09 '19 at 23:10

0 Answers0