Skip to content

armgin version 0.2

Latest
Compare
Choose a tag to compare
@nacnudus nacnudus released this 24 Apr 13:53

Summarise by individual grouping variables one at a time with method = "individual". The argument hierarchy is deprecated and replaced by method, which can be one of "hierarchy", "combination" or "individual".

library(armgin)
example(margins)
#> 
#> margns> mtcars %>%
#> margns+   dplyr::group_by(cyl, gear, am) %>%
#> margns+   margins(mpg = mean(mpg, na.rm = TRUE),
#> margns+           hp = min(hp),
#> margns+           bind = FALSE,
#> margns+           method = "hierarchy")
#> [[1]]
#> # A tibble: 3 x 3
#> # Groups:   cyl [3]
#>     cyl   mpg    hp
#>   <dbl> <dbl> <dbl>
#> 1     4  26.7    52
#> 2     6  19.7   105
#> 3     8  15.1   150
#> 
#> [[2]]
#> # A tibble: 8 x 4
#> # Groups:   cyl, gear [8]
#>     cyl  gear   mpg    hp
#>   <dbl> <dbl> <dbl> <dbl>
#> 1     4     3  21.5    97
#> 2     4     4  26.9    52
#> 3     4     5  28.2    91
#> 4     6     3  19.8   105
#> 5     6     4  19.8   110
#> 6     6     5  19.7   175
#> 7     8     3  15.0   150
#> 8     8     5  15.4   264
#> 
#> [[3]]
#> # A tibble: 10 x 5
#> # Groups:   cyl, gear, am [10]
#>      cyl  gear    am   mpg    hp
#>    <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1     4     3     0  21.5    97
#>  2     4     4     0  23.6    62
#>  3     4     4     1  28.0    52
#>  4     4     5     1  28.2    91
#>  5     6     3     0  19.8   105
#>  6     6     4     0  18.5   123
#>  7     6     4     1  21     110
#>  8     6     5     1  19.7   175
#>  9     8     3     0  15.0   150
#> 10     8     5     1  15.4   264
#> 
#> 
#> margns> mtcars %>%
#> margns+   dplyr::group_by(cyl, gear, am) %>%
#> margns+   margins(mpg = mean(mpg, na.rm = TRUE),
#> margns+           hp = min(hp),
#> margns+           bind = TRUE,
#> margns+           method = "hierarchy") %>%
#> margns+   print(n = Inf)
#> # A tibble: 21 x 5
#> # Groups:   cyl [3]
#>      cyl  gear    am   mpg    hp
#>    <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1     4    NA    NA  26.7    52
#>  2     6    NA    NA  19.7   105
#>  3     8    NA    NA  15.1   150
#>  4     4     3    NA  21.5    97
#>  5     4     4    NA  26.9    52
#>  6     4     5    NA  28.2    91
#>  7     6     3    NA  19.8   105
#>  8     6     4    NA  19.8   110
#>  9     6     5    NA  19.7   175
#> 10     8     3    NA  15.0   150
#> 11     8     5    NA  15.4   264
#> 12     4     3     0  21.5    97
#> 13     4     4     0  23.6    62
#> 14     4     4     1  28.0    52
#> 15     4     5     1  28.2    91
#> 16     6     3     0  19.8   105
#> 17     6     4     0  18.5   123
#> 18     6     4     1  21     110
#> 19     6     5     1  19.7   175
#> 20     8     3     0  15.0   150
#> 21     8     5     1  15.4   264
#> 
#> margns> mtcars %>%
#> margns+   dplyr::group_by(cyl, gear, am) %>%
#> margns+   margins(mpg = mean(mpg, na.rm = TRUE),
#> margns+           hp = min(hp),
#> margns+           bind = FALSE,
#> margns+           method = "combination")
#> [[1]]
#> # A tibble: 3 x 3
#> # Groups:   cyl [3]
#>     cyl   mpg    hp
#>   <dbl> <dbl> <dbl>
#> 1     4  26.7    52
#> 2     6  19.7   105
#> 3     8  15.1   150
#> 
#> [[2]]
#> # A tibble: 3 x 3
#> # Groups:   gear [3]
#>    gear   mpg    hp
#>   <dbl> <dbl> <dbl>
#> 1     3  16.1    97
#> 2     4  24.5    52
#> 3     5  21.4    91
#> 
#> [[3]]
#> # A tibble: 2 x 3
#> # Groups:   am [2]
#>      am   mpg    hp
#>   <dbl> <dbl> <dbl>
#> 1     0  17.1    62
#> 2     1  24.4    52
#> 
#> [[4]]
#> # A tibble: 8 x 4
#> # Groups:   cyl, gear [8]
#>     cyl  gear   mpg    hp
#>   <dbl> <dbl> <dbl> <dbl>
#> 1     4     3  21.5    97
#> 2     4     4  26.9    52
#> 3     4     5  28.2    91
#> 4     6     3  19.8   105
#> 5     6     4  19.8   110
#> 6     6     5  19.7   175
#> 7     8     3  15.0   150
#> 8     8     5  15.4   264
#> 
#> [[5]]
#> # A tibble: 6 x 4
#> # Groups:   cyl, am [6]
#>     cyl    am   mpg    hp
#>   <dbl> <dbl> <dbl> <dbl>
#> 1     4     0  22.9    62
#> 2     4     1  28.1    52
#> 3     6     0  19.1   105
#> 4     6     1  20.6   110
#> 5     8     0  15.0   150
#> 6     8     1  15.4   264
#> 
#> [[6]]
#> # A tibble: 4 x 4
#> # Groups:   gear, am [4]
#>    gear    am   mpg    hp
#>   <dbl> <dbl> <dbl> <dbl>
#> 1     3     0  16.1    97
#> 2     4     0  21.0    62
#> 3     4     1  26.3    52
#> 4     5     1  21.4    91
#> 
#> [[7]]
#> # A tibble: 10 x 5
#> # Groups:   cyl, gear, am [10]
#>      cyl  gear    am   mpg    hp
#>    <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1     4     3     0  21.5    97
#>  2     4     4     0  23.6    62
#>  3     4     4     1  28.0    52
#>  4     4     5     1  28.2    91
#>  5     6     3     0  19.8   105
#>  6     6     4     0  18.5   123
#>  7     6     4     1  21     110
#>  8     6     5     1  19.7   175
#>  9     8     3     0  15.0   150
#> 10     8     5     1  15.4   264
#> 
#> 
#> margns> mtcars %>%
#> margns+   dplyr::group_by(cyl, gear, am) %>%
#> margns+   margins(mpg = mean(mpg, na.rm = TRUE),
#> margns+           hp = min(hp),
#> margns+           bind = FALSE,
#> margns+           method = "individual")
#> [[1]]
#> # A tibble: 3 x 3
#> # Groups:   cyl [3]
#>     cyl   mpg    hp
#>   <dbl> <dbl> <dbl>
#> 1     4  26.7    52
#> 2     6  19.7   105
#> 3     8  15.1   150
#> 
#> [[2]]
#> # A tibble: 3 x 3
#> # Groups:   gear [3]
#>    gear   mpg    hp
#>   <dbl> <dbl> <dbl>
#> 1     3  16.1    97
#> 2     4  24.5    52
#> 3     5  21.4    91
#> 
#> [[3]]
#> # A tibble: 2 x 3
#> # Groups:   am [2]
#>      am   mpg    hp
#>   <dbl> <dbl> <dbl>
#> 1     0  17.1    62
#> 2     1  24.4    52