Debian Codegraph @

inst/other_docs/blog.Rmd

raw
1 ---
2 title: "`skimr` for useful and tidy summary statistics"
3 authors:
4 - name: Eduardo Arino de la Rubia
5 url: http://github.com/earino
6 - name: Shannon Ellis
7 url: http://github.com/ShanEllis
8 - name: Julia Stewart Lowndes
9 url: http://github.com/jules32
10 - name: Hope McLeod
11 url: http://github.com/homcl
12 - name: Amelia McNamara
13 url: http://github.com/AmeliaMN
14 - name: Michael Quinn
15 url: https://github.com/michaelquinn32
16 - name: Elin Waring
17 url: https://github.com/elinw
18 - name: Hao Zhu
19 url: https://github.com/haozhu233
20 date: "07/11/2017"
21 output:
22 md_document:
23 variant: markdown_github
24 categories:
25 - blog
26 tags:
27 - unconf
28 - testing
29 - review
30 - packages
31 - software
32 - community
33 - meetings
34 ---
35
36 ```{r setup, include=FALSE}
37 knitr::opts_chunk$set(echo = TRUE)
38 ```
39
40 Like every R user who uses summary statistics (so, everyone), our team has to rely on some combination of summary functions beyond `summary()` and `str()`. But we found them all lacking in some way because they can be generic, they don't always provide easy-to-operate-on data structures, and they are not pipeable. What we wanted was a frictionless approach for quickly skimming useful and tidy summary statistics as part of a pipeline. And so at [rOpenSci #unconf17](http://unconf17.ropensci.org/), we developed [`skimr`](https://github.com/ropenscilabs/skimr#skimr).
41
42 In a nutshell, `skimr` will create a `skim_df` object that can be further operated upon or that provides a human-readable printout in the console. It presents reasonable default summary statistics for numerics, factors, etc, and lists counts, and missing and unique values. And the momentum is still going, thanks to our awesome team (see below)!
43
44 ## Backstory
45
46 The idea for skimr as a project for the #unconf17 [was proposed by Amelia McNamara](https://github.com/ropensci/unconf17/issues/50) following [discussions on Twitter](https://twitter.com/AmeliaMN/status/774348524653834241) and an [initial package Hadley Wickham](https://github.com/hadley/precis).
47
48 Once we were together in Los Angeles, we formed a solid team, set up a Google Doc, a Slack channel, the `ropensci/skimr` repo, and grabbed a whiteboard.
49
50 We started off by brainstorming what we liked about existing summary packages and what other features we wanted. We started looking at example data, `mtcars`.
51
52 Here's what we liked and disliked, in Amelia's words:
53
54 ```{r summary, eval=FALSE}
55 ### "I like what we get here because mpg is numeric so these stats make sense:"
56 summary(mtcars$mpg)
57 # Min. 1st Qu. Median Mean 3rd Qu. Max.
58 # 10.40 15.42 19.20 20.09 22.80 33.90
59
60
61 ### "But I don’t like this because cyl should really be a factor and shouldn't
62 ### have these stats:"
63 summary(mtcars$cyl)
64 # Min. 1st Qu. Median Mean 3rd Qu. Max.
65 # 4.000 4.000 6.000 6.188 8.000 8.000
66
67
68 ### "This is OK, but not descriptive enough. It could be clearer what I'm
69 ### looking at."
70 mosaic::tally(~cyl, data = mtcars) # install.packages('mosaic')
71 # cyl
72 # 4 6 8
73 # 11 7 14
74
75
76 ### "But this output isn't labeled, not ideal."
77 table(mtcars$cyl, mtcars$vs)
78 #
79 # 0 1
80 # 4 1 10
81 # 6 3 4
82 # 8 14 0
83
84
85 ### "I like this because it returns 'sd', 'n' and 'missing'":
86 mosaic::favstats(~mpg, data = mtcars)
87 # min Q1 median Q3 max mean sd n missing
88 # 10.4 15.425 19.2 22.8 33.9 20.09062 6.026948 32 0
89 ```
90
91 Once we had an idea of what we thought would be useful, we did a bit of market research (i.e. we made a short [presentation](https://docs.google.com/presentation/d/13Ky3-Y70STzufLJtCm6GXN8SMj2Y11riDef8b9cBgAQ/edit#slide=id.p) and ran it by other unconfers at lunch.
92
93 ## Introducing `skimr`
94
95 So what does `skimr` actually do? It allows you to skim useful summary statistics in the console, or use those statistics in a pipeable workflow.
96
97 Some features of output in the console:
98
99 - reports missing, complete, n, sd, and quantiles
100 - reports numeric/int/double separately from factor/chr, and identifies class
101 - handles dates, logicals
102 - uses [Hadley's pillars](https://github.com/hadley/pillar), specifically `pillar::spark-bar()`
103
104 Here are examples of `skimr` in action:
105
106 ### Quick skim in the console:
107
108 **Nicely separates numeric and factor variables:**
109
110 ![](https://github.com/ropenscilabs/skimr/blob/24c733d7e4752c37e46e4c36693da107f42f3f55/man/figures/skim_iris.png)
111 <br>
112
113 **Clearly displays many numeric variables:**
114
115 ![](https://github.com/ropenscilabs/skimr/blob/ecb90e22047d4a1b228bcf471650eb79b733e52e/man/figures/skim_mtcars.png)
116 <br>
117
118 **Also works with strings:**
119
120 ![](https://github.com/ropenscilabs/skimr/blob/ecb90e22047d4a1b228bcf471650eb79b733e52e/man/figures/skim_babynames.png) <br>
121
122 ### Exploring a skim\_df object
123
124 By default `skim` prints beautifully in the console, but it also produces a long, tidy-format `skim_df` object that can be computed on.
125
126 ```{r, eval = FALSE}
127 a <- skim(chickwts)
128 dim(a)
129 # [1] 22 5
130 View(a)
131 ```
132
133 <img src="https://github.com/ropenscilabs/skimr/blob/ecb90e22047d4a1b228bcf471650eb79b733e52e/man/figures/skim_chickwts_df.png" width="450px">
134
135
136 ### Computing with the skim_df object
137
138 Maybe you just want to skim a specific portion of your data frame. Use skimr with a pipe!
139
140 ```{r, eval = FALSE}
141 skim(mtcars) |> filter(stat == "hist")
142 # A tibble: 11 × 5
143 # var type stat level value
144 # <chr> <chr> <chr> <chr> <dbl>
145 # 1 mpg numeric hist ▂▅▇▇▇▃▁▁▂▂ 0
146 # 2 cyl numeric hist ▆▁▁▁▃▁▁▁▁▇ 0
147 # 3 disp numeric hist ▇▇▅▁▁▇▃▂▁▃ 0
148 # 4 hp numeric hist ▆▆▇▂▇▂▃▁▁▁ 0
149 # 5 drat numeric hist ▃▇▂▂▃▆▅▁▁▁ 0
150 # 6 wt numeric hist ▂▂▂▂▇▆▁▁▁▂ 0
151 # 7 qsec numeric hist ▂▃▇▇▇▅▅▁▁▁ 0
152 # 8 vs numeric hist ▇▁▁▁▁▁▁▁▁▆ 0
153 # 9 am numeric hist ▇▁▁▁▁▁▁▁▁▆ 0
154 # 10 gear numeric hist ▇▁▁▁▆▁▁▁▁▂ 0
155 # 11 carb numeric hist ▆▇▂▁▇▁▁▁▁▁ 0
156 ```
157
158
159
160 ### Specifying your own statistics
161
162 Another possibility is specifying your own statistics to display with `skimr`:
163
164 ```{r, eval = FALSE}
165 funs <- list(
166 iqr = IQR,
167 quantile = purrr::partial(quantile, probs = .99)
168 )
169 skim_with(numeric = funs, append = FALSE)
170 skim_v(iris$Sepal.Length)
171
172 # A tibble: 2 × 4
173 # type stat level value
174 # <chr> <chr> <chr> <dbl>
175 # 1 numeric iqr .all 1.3
176 # 2 numeric quantile 99% 7.7
177 ```
178
179 ## Our awesome team
180
181 We had a really fantastic team with diverse backgrounds, and it was really cool how organically everyone found a role for themselves during the development of `skimr`. Between brainstorming sessions, experienced coders began to iteratively develop the code while others worked on documentation and tests, and got more involved. Everyone asked questions and brainstormed together; it was a really welcoming environment. We knew that by the end of the second day of the unconf, we would present our work using only the repo's [README](https://github.com/ropenscilabs/skimr#skimr) file. So we focused on communication throughout the entire development process.
182
183 A lot of the heavy lifting at the unconf was done by Michael, Elin, and Eduardo, and Elin has continued leading development in the month since!
184
185 This was the original team in alphabetical order. We have also had many virtual contributors as well: see the full list of contributors [here](https://github.com/ropenscilabs/skimr/graphs/contributors).
186
187 **Eduardo Arino de la Rubia**
188 Job Title: Chief Data Scientist at Domino Data Lab
189 Project Contributions: Coder
190
191 **Shannon Ellis**
192 Job Title: Postdoctoral fellow in the Biostatistics Department at the Johns Hopkins Bloomberg School of Public Health
193 Project Contributions: Test Scripts
194
195 **Julia Stewart Lowndes**
196 Job Title: Marine Data Scientist at the National Center for Ecological Analysis and Synthesis
197 Project Contributions: Documentation and test scripts
198
199 **Hope McLeod**
200 Job Title: Data Engineer at Kobalt Music
201 Project Contributions: Documentation
202
203 **Amelia McNamara**
204 Job Title: Visiting Assistant Professor of Statistical & Data Sciences at Smith College
205 Project Contributions: Coder
206
207 **Michael Quinn**
208 Job Title: Quantitative Analyst at Google
209 Project Contributions: Coder
210
211 **Elin Waring**
212 Job Title: Professor at Lehman College Sociology Department, City University of New York
213 Project Contributions: Coder
214
215 **Hao Zhu**
216 Job Title: Programmer Analyst at the Institute for Aging Research
217 Project Contributions: Coder
218
219 ## In summary (ha...)
220
221 The work we did together was only possible because of rOpenSci's incredible community and culture. For us to be able to dream up something we wanted to build and have the time and space to actually do it together was really exciting. So thank you rOpenSci and everyone in the greater community!
222
223 There is more work to be done on `skimr`, so please check out the [`skimr`](https://github.com/ropenscilabs/skimr) repo for the latest features and improvements!
224
225 Updated to use the base pipe.