10:00
10:00

theme_set()
Default theme

theme_bw(base_size = 20)

RQ: Do people bike more when the weather is nice?

Let’s build a model to predict bike usage based on weather.

EDA is an iterative process to help you
understand your data and ask better questions

Subdivide things into groups
Measure things with numbers
e.g. country in TB case data:
#> # A tibble: 6 × 4
#> country year cases population
#> <chr> <dbl> <dbl> <dbl>
#> 1 Afghanistan 1999 745 19987071
#> 2 Afghanistan 2000 2666 20595360
#> 3 Brazil 1999 37737 172006362
#> 4 Brazil 2000 80488 174504898
#> 5 China 1999 212258 1272915272
#> 6 China 2000 213766 1280428583
e.g.: Placement 2017 Boston marathon:
#> # A tibble: 6 × 3
#> Placement `Official Time` Name
#> <dbl> <time> <chr>
#> 1 1 02:09:37 Kirui, Geoffrey
#> 2 2 02:09:58 Rupp, Galen
#> 3 3 02:10:28 Osako, Suguru
#> 4 4 02:12:08 Biwott, Shadrack
#> 5 5 02:12:35 Chebet, Wilson
#> 6 6 02:12:45 Abdirahman, Abdi
e.g.: temp in Beaver data
#> day time temp activ
#> 1 346 840 36.33 0
#> 2 346 850 36.34 0
#> 3 346 900 36.35 0
#> 4 346 910 36.42 0
#> 5 346 920 36.55 0
#> 6 346 930 36.69 0
e.g.: height & speed in wildlife impacts
#> # A tibble: 6 × 3
#> incident_date height speed
#> <dttm> <dbl> <dbl>
#> 1 2018-12-31 00:00:00 700 200
#> 2 2018-12-27 00:00:00 600 145
#> 3 2018-12-23 00:00:00 0 130
#> 4 2018-12-22 00:00:00 500 160
#> 5 2018-12-21 00:00:00 100 150
#> 6 2018-12-18 00:00:00 4500 250
Yes: Ordinal
No: Nominal
Yes: Ratio
No: Interval
passedTest = 1 or 0)1, 2, 3, 4
Complaints are coming in about orders shipped from warehouse B, so you collect some data:
Complaints are coming in about orders shipped from warehouse B, so you collect some data:
Variability reveals difference in days to ship:
#> # A tibble: 2 × 5
#> warehouse mean median range sd
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 warehouseA 4.25 4.5 2 0.866
#> 2 warehouseB 4.25 4.5 9 2.70



Outliers: \(Q_1 - 1.5 IQR\) or \(Q_3 + 1.5 IQR\)
Extreme values: \(Q_1 - 3 IQR\) or \(Q_3 + 3 IQR\)
10:00
milk_production.csvlotr_words.csv
Stephen Few (2009, pg. 6)

Stephen Few (2009, pg. 6)


Measures:
Charts:
Measures:
Charts:
Measures:
Charts:
Summarize with counts / percentages
Summarize: Counts / percentages
#> # A tibble: 12 × 3
#> incident_month n p
#> <dbl> <int> <dbl>
#> 1 9 7980 0.140
#> 2 10 7754 0.136
#> 3 8 7104 0.125
#> 4 5 6161 0.108
#> 5 7 6133 0.108
#> 6 6 4541 0.0797
#> 7 4 4490 0.0788
#> 8 11 4191 0.0736
#> 9 3 2678 0.0470
#> 10 12 2303 0.0404
#> 11 1 1951 0.0342
#> 12 2 1692 0.0297
Histograms:
Boxplots:

Summarise:
Mean, median, sd, range, & IQR:


15:00
faithful.csvmarathon.csveruptionswaitingAgeStateCountry`Official Time`05:00


Galton, F. (1886). “Regression towards mediocrity in hereditary stature”. The Journal of the Anthropological Institute of Great Britain and Ireland 15: 246-263.
Galton’s question: Does marriage selection indicate a relationship between the heights of husbands and wives?
(He called this “assortative mating”)
“midparent height” is just a scaled mean:
Assumptions:




Percent of variance in one variable that is explained by the other variable

| \(r\) | \(r^2\) |
|---|---|
| 0.1 | 0.01 |
| 0.2 | 0.04 |
| 0.3 | 0.09 |
| 0.4 | 0.16 |
| 0.5 | 0.25 |
| 0.6 | 0.36 |
| 0.7 | 0.49 |
| 0.8 | 0.64 |
| 0.9 | 0.81 |
| 1.0 | 1.00 |
Dual axes

Single axis






Assumptions:


| Pearson | Spearman |
|---|---|
| -0.56 | 0.53 |
| 0.39 | 0.69 |
| 0.94 | 0.81 |
| 0.38 | 0.76 |
| 0.81 | 0.79 |
| 0.31 | 0.70 |
| 0.95 | 0.81 |
| 0.51 | 0.75 |
| -0.56 | 0.53 |


ggcorr()ggcorr()ggcorr()ggpairs()ggpairs()15:00
Using the penguins data frame:
Find the two variables with the largest correlation in absolute value (i.e. closest to -1 or 1).
Create a scatter plot of those two variables.
Add an annotation for the Pearson correlation coefficient.
Body mass vs. Bill depth

Body mass vs. Bill depth

Ask yourself:
Check out these guides

Summarize with a table of counts
#> # A tibble: 20 × 3
#> operator time_of_day n
#> <chr> <chr> <int>
#> 1 AMERICAN AIRLINES Dawn 458
#> 2 AMERICAN AIRLINES Day 7809
#> 3 AMERICAN AIRLINES Dusk 584
#> 4 AMERICAN AIRLINES Night 3710
#> 5 AMERICAN AIRLINES <NA> 2326
#> 6 DELTA AIR LINES Dawn 267
#> 7 DELTA AIR LINES Day 4846
#> 8 DELTA AIR LINES Dusk 353
#> 9 DELTA AIR LINES Night 2090
#> 10 DELTA AIR LINES <NA> 1449
#> 11 SOUTHWEST AIRLINES Dawn 394
#> 12 SOUTHWEST AIRLINES Day 9109
#> 13 SOUTHWEST AIRLINES Dusk 599
#> 14 SOUTHWEST AIRLINES Night 5425
#> 15 SOUTHWEST AIRLINES <NA> 2443
#> 16 UNITED AIRLINES Dawn 151
#> 17 UNITED AIRLINES Day 3359
#> 18 UNITED AIRLINES Dusk 181
#> 19 UNITED AIRLINES Night 1510
#> 20 UNITED AIRLINES <NA> 9915
Convert to “wide” format with pivot_wider() to make it easier to compare values
#> # A tibble: 4 × 6
#> operator Dawn Day Dusk Night `NA`
#> <chr> <int> <int> <int> <int> <int>
#> 1 AMERICAN AIRLINES 458 7809 584 3710 2326
#> 2 DELTA AIR LINES 267 4846 353 2090 1449
#> 3 SOUTHWEST AIRLINES 394 9109 599 5425 2443
#> 4 UNITED AIRLINES 151 3359 181 1510 9915
Visualize with bars:
map fill to denote 2nd categorical var

Visualize with scatterplot - looking for clustering and/or correlational relationship
Visualize with boxplot
15:00
Read in the candy_rankings.csv data sets
Preview the data, note the data types and what each variable is.
Visualize (at least) three relationships between two variables (guided by a question) using an appropriate chart: