GithubHelp home page GithubHelp logo

Using the bootstrap function about broom HOT 6 CLOSED

vnijs avatar vnijs commented on August 20, 2024
Using the bootstrap function

from broom.

Comments (6)

dgrtwo avatar dgrtwo commented on August 20, 2024 1

Unfortunately bootstrap hasn't worked with summarize in a while (it did when the function was originally written, but stopped being compatible after a dplyr update/improvement). It relies on a manipulation of the group indices that is consistent with do but not summarize.

My understanding is that bootstrapping in the future should probably be done with the lowliner package, which has some very slick solutions for this kind of problem; I just haven't investigated it yet. The main reason bootstrap is in the package is to cover the cases in the broom manuscript (and I'm certainly open to pull requests that would improve it).

In the meantime you could also work around it with do:

mtcars %>% bootstrap(10) %>% do(data.frame(mean = mean(.$mpg)))

from broom.

benmarwick avatar benmarwick commented on August 20, 2024 1

Thanks, that's great to know! I was wondering what you plan might be for broom::bootstrap. Thanks very much for making that PR to modelr, hopefully that'll make modelr::bootstrap a bit easier to use. Great to see resampling methods becoming easy to implement in the tidyverse, thanks again!

from broom.

vnijs avatar vnijs commented on August 20, 2024

Thanks for the workaround David. I will look into the lowliner package as well. Thanks for the tip.

Vincent


Sent from Mailbox

On Sun, Feb 1, 2015 at 8:37 PM, David Robinson [email protected]
wrote:

Unfortunately bootstrap hasn't worked with summarize in a while (it did when the function was originally written, but stopped being compatible after a dplyr update/improvement). It relies on a manipulation of the group indices that is consistent with do but not summarize.
My understanding is that bootstrapping in the future should probably be done with the lowliner package, which has some very slick solutions for this kind of problem; I just haven't investigated it yet. The main reason bootstrap is in the package is to cover the cases in the broom manuscript (and I'm certainly open to pull requests that would improve it).
In the meantime you could also work around it with do:

mtcars %>% bootstrap(10) %>% do(data.frame(mean = mean(.$mpg)))

Reply to this email directly or view it on GitHub:
https://github.com/dgrtwo/broom/issues/25#issuecomment-72405484

from broom.

benmarwick avatar benmarwick commented on August 20, 2024

I also stumbled into this recently. Fortunately we now also have a bootstrap in @hadley's modelr, as well as the excellent purrr package (formerly lowliner), and we can do something like this with the above example:

library(dplyr)
library(purrr)
library(modelr)

mtcars %>%
  modelr::bootstrap(10) %>%
  mutate(mean_mpg = map_dbl(strap, ~mean(data.frame(.)$mpg)))

# A tibble: 10 × 3
            strap   .id mean_mpg
           <list> <chr>    <dbl>
1  <S3: resample>    01 20.26875
2  <S3: resample>    02 19.89062
3  <S3: resample>    03 19.20000
4  <S3: resample>    04 19.79062
5  <S3: resample>    05 19.50625
6  <S3: resample>    06 19.19063
7  <S3: resample>    07 19.40625
8  <S3: resample>    08 21.53125
9  <S3: resample>    09 19.84375
10 <S3: resample>    10 20.97812

I was a little surprised about the need to coerce the resample object in the strap column to a data frame in order to access the mpg column. Is that intentional?

from broom.

dgrtwo avatar dgrtwo commented on August 20, 2024

Yes, I'm generally recommending people use modelr's bootstrap rather than broom's now. Once modelr is stable and on CRAN I will deprecate broom::bootstrap.

As for needing to do as.data.frame(): a resample object is more like a promise of a data frame than an actual one (though not technically a promise) and only creates the object when requested. It has recently occurred to me that we should really have $ or [[]] evaluate as well and I plan on submitting a modelr pull request to that effect soon!

from broom.

github-actions avatar github-actions commented on August 20, 2024

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

from broom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.