Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding bootstrap customization for stat_summary(fun.data="mean_cl_boot") #5885

Closed
erinnacland opened this issue May 8, 2024 · 1 comment
Closed

Comments

@erinnacland
Copy link

When using stat_summary(fun.data = "mean_cl_boot"), bootstrapped means and confidence intervals are produced. The bootstraps are set to 1000, this leads to the means and CIs slightly changing between runs. Below are two runs of the same code, each has slightly different estimates:


Rplot05
Rplot06

Reproducible code:

ggplot(iris, aes(x=Species, y=Sepal.Length, fill=Species,)) +
  stat_summary(fun.data="mean_cl_boot") 

This can lead to meaningful changes in estimates depending on the data used and how large the changes are between iterations.

Is it possible to add a feature where you can edit the number of bootstraps so they can be increased, making results more stable?

@teunbrand
Copy link
Collaborator

You can already pass additional arguments to the summary function by passing a list to the fun.args argument.
As mean_cl_boot() is just a wrapper for Hmisc::smean.cl.boot(), you can increase B to get a more stable estimate like this:

library(ggplot2)
ggplot(iris, aes(x=Species, y=Sepal.Length, fill=Species,)) +
  stat_summary(fun.data = "mean_cl_boot", fun.args = list(B = 10e3)) 

Alternatively, you can use fun.data = ~mean_cl_boot(.x, B = 10e3) to achieve the same outcome.
In addition, you can use set.seed() to fix the effects of the random number generator.

As there are already methods to change the number of bootstraps, I'll close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants