Giter Site home page Giter Site logo

Comments (1)

simonpcouch avatar simonpcouch commented on August 28, 2024

I appreciate you bringing this up, @AmeliaMN!

For now, fit.infer just applies tidy() to the output of each glm() fit. We could maybe open up an interface here for passing an arbitrary model summary function? For the output you mention, folks could pass glance, but I could also imagine folks passing augment, summary, or identity. With glance, that interface could feel something like:

library(tidymodels)

null_dist <- 
   gss %>%
   specify(hours ~ age + college) %>%
   hypothesize(null = "independence") %>%
   generate(reps = 2, type = "permute")

# continue to `tidy() %>% select()` by default
null_dist %>%
   fit()
#> # A tibble: 6 × 3
#> # Groups:   replicate [2]
#>   replicate term          estimate
#>       <int> <chr>            <dbl>
#> 1         1 intercept     41.7    
#> 2         1 age            0.00508
#> 3         1 collegedegree -1.43   
#> 4         2 intercept     40.4    
#> 5         2 age            0.0214 
#> 6         2 collegedegree  0.328

# optional `summary` (or otherwise named) argument
null_dist %>%
   fit(summary = glance)
#> # A tibble: 2 × 13
#> # Groups:   replicate [2]
#>   replicate r.squared adj.r.squ…¹ sigma stati…² p.value    df logLik   AIC   BIC
#>       <int>     <dbl>       <dbl> <dbl>   <dbl>   <dbl> <dbl>  <dbl> <dbl> <dbl>
#> 1         1   0.00121    -0.00281  14.8   0.302   0.740     2 -2057. 4121. 4138.
#> 2         2   0.00275    -0.00126  14.8   0.686   0.504     2 -2056. 4121. 4137.
#> # … with 3 more variables: deviance <dbl>, df.residual <int>, nobs <int>, and
#> #   abbreviated variable names ¹​adj.r.squared, ²​statistic

Actual code for this output:

null_dist %>% 
   nest() %>% 
   rowwise() %>% 
   mutate(mod = list(lm(hours ~ age + college, data = data)), 
          sum = list(glance(mod))) %>% 
   select(-data, -mod) %>% 
   unnest(cols = sum)

Any thoughts on this interface? This feels like a nice way of integrating broom and functions-as-arguments into teaching these pipelines, though I'm not sure if that's Astronaut Stuff Too Early.

One technical hiccup here is that glance() doesn't output $R^2$ for glm() output, though glm() is what's used under the hood in fit.infer() right now.

Also, looping in @mine-cetinkaya-rundel. :)

from infer.

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.