Interpretation of “stat_summary = mean_cl_boot” at ggplot2?

◇◆丶佛笑我妖孽 提交于 2019-12-03 02:43:55
Metrics

Here is what the ggplot2 book on page 83 says about mean_cl_boot()

Function          Hmisc original        Middle Range
mean_cl_boot() smean.cl.boot() Mean Standard error from bootstrap

I think that it is the smean.cl.boot() from Hmisc package but renamed as mean.cl.boot() in ggplot2.

and here is the definition of original function from Hmisc package :

smean.cl.boot is a very fast implementation of the basic nonparametric bootstrap for obtaining confidence limits for the population mean without assuming normality

I reproduced the graph using your code and I get essentially the same graph shown in Field's book, Discovering Statistics Using R, figure 12.12, page 532, except for the ordering of the variables on the x axis. The y axis displays the continuous variable, Mean Attractiveness of Date (%). The 95% confidence intervals, created--as you point out--with the stat_summary() function and the mean_cl_boot argument are bootstrap confidence intervals using the smean.cl.boot() function in Hmisc, as pointed out by another commenter above. This function is described on page 262 of the Hmisc documentation. The ggplot2 documentation on mean_cl_boot is sparse and defers to the description in the Hmisc package.

Note that the arguments to mean_cl_boot in ggplot2 are the same as those in the smean.cl.boot function in the Hmisc package. You can change the desired confidence level from the default of .95 by using the conf.int argument and the number of bootstrap samples by using the B argument. Here, for example, is the code for creating the same plot with a 99% confidence interval and 5000 bootstrap samples:

line <- ggplot(gogglesData, aes(alcohol, attractiveness, colour = gender))
line + stat_summary(fun.y = mean, geom = "point") + 
stat_summary(fun.y = mean, geom = "line", aes(group= gender)) + 
stat_summary(fun.data = mean_cl_boot, conf.int = .99, B = 5000, geom = "errorbar", width = 0.2) + 
labs(x = "Alcohol Consumption", y = "Mean Attractiveness of Date (%)", colour = "Gender") 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!