+ - 0:00:00
Notes for current slide
Notes for next slide

I want to talk a bit about where I've started from, because I think it might be useful to understand my perspective, and why I'm interested in doing these things.

Exploring and understanding the individual experience from longitudinal data, or…

How to make better spaghetti (plots)

Nicholas Tierney, Monash University

1 / 125

(My) Background

2 / 125

I want to talk a bit about where I've started from, because I think it might be useful to understand my perspective, and why I'm interested in doing these things.

Background: Undergraduate

Undergraduate in Psychology

  • Statistics
  • Experiment Design
  • Cognitive Theory
  • Neurology
  • Humans

3 / 125

Background: Honours

Psychophysics: illusory contours in 3D

Phil Grove

4 / 125

Background: Undergraduate

Christina Lee

If every psychologist in the world delivered gold standard smoking cessation therapy, the rate of smoking would still increase. You need to change policy to make change. To make effective policy, you need to have good data, and do good statistics.

5 / 125

I discovered an interest in public health and statistics.

Background: PhD

  • "Ah, statistics, everything is black and white!
  • "There's always an answer"
  • "data in, answer out"

6 / 125

I started a PhD in statistics at QUT, under (now distinguished) Professor Kerrie Mengersen, Looking at people's health over time.

  • There were several things that I noticed:
    • There were equations, but not as many clear-cut, black and white answers

Background: PhD

  • Data is really messy
  • Missing values are frustrating
  • How to Explore data?

7 / 125

Background: PhD - But in psych

  • Focus on experiment design
  • No focus on exploring data
  • Exploring data felt...wrong?
  • But it was so critical.

8 / 125

(My personal) motivation

  • A lot of research in new statistical methods - imputation, inference, prediction
  • Not much research on how we explore our data, and the methods that we use to do this.
9 / 125

(My personal) motivation

Focus on building a bridge across a river. Less focus on how it is built, and the tools used.

10 / 125
  • I became very interested in how we explore our data - exploratory data analysis.

My research:

Design and improve tools for (exploratory) data analysis

11 / 125

EDA: Exploratory Data Analysis

...EDA is an approach to analyzing data sets to summarize their main characteristics, often with visual methods. (Wikipedia)

John Tukey, Frederick Mosteller, Bill Cleveland, Dianne Cook, Heike Hoffman, Rob Hyndman, Hadley Wickham

12 / 125

EDA: Why it's worth it

13 / 125

14 / 125

visdat

rOpenSci BadgeJOSS statusDOI

published under "visdat: Visualising Whole Data Frames" in the Journal of Open Source Software

15 / 125

visdat::vis_dat(airquality)

16 / 125

visdat::vis_miss(airquality)

17 / 125

naniar

Tierney, NJ. Cook, D. "Expanding tidy data principles to facilitate missing data exploration, visualization and assessment of imputations." [Pre-print]

18 / 125

naniar::gg_miss_var(airquality)

19 / 125

naniar::gg_miss_upset(airquality)

20 / 125

Current work:

How to explore longitudinal data effectively

21 / 125

What is longitudinal data?

Something observed sequentially over time

22 / 125

What is longitudinal data?

## # A tsibble: 1 x 4 [!]
## # Key: country [1]
## country year height_cm continent
## <chr> <dbl> <dbl> <chr>
## 1 Australia 1910 173. Oceania
23 / 125

What is longitudinal data?

## # A tsibble: 2 x 4 [!]
## # Key: country [1]
## country year height_cm continent
## <chr> <dbl> <dbl> <chr>
## 1 Australia 1910 173. Oceania
## 2 Australia 1920 173. Oceania
24 / 125

What is longitudinal data?

## # A tsibble: 3 x 4 [!]
## # Key: country [1]
## country year height_cm continent
## <chr> <dbl> <dbl> <chr>
## 1 Australia 1910 173. Oceania
## 2 Australia 1920 173. Oceania
## 3 Australia 1960 176. Oceania
25 / 125

What is longitudinal data?

## # A tsibble: 4 x 4 [!]
## # Key: country [1]
## country year height_cm continent
## <chr> <dbl> <dbl> <chr>
## 1 Australia 1910 173. Oceania
## 2 Australia 1920 173. Oceania
## 3 Australia 1960 176. Oceania
## 4 Australia 1970 178. Oceania
26 / 125

27 / 125

28 / 125

All of Australia

29 / 125

...And New Zealand

30 / 125

... And Afghanistan and Albania

31 / 125

And the rest?

32 / 125

And the rest?

33 / 125

34 / 125

Problems:

  • Overplotting
  • We don't see the individuals
  • We could look at 153 individual plots, but this doesn't help.

35 / 125

Does transparency help?

36 / 125

Does transparency + a model help?

37 / 125
  • This helps reduce the overplotting
  • We only get the overall average. We dont get the rest of the information

This is still useful

38 / 125
  • We get information on what the average is, and how that behaves
  • But we don't get the full story
  • So, it depends on your need. If you have a designed experiment, where you stated that you would run some analysis, then you are doing this.
  • ... But even then, wouldn't you rather explore the data?
  • Who fits the models well / worst / best?

But we forget about the individuals

39 / 125
  • The model might make some good overall predictions
  • But it can be really ill suited for some individual
  • Exploring this is somewhat clumsy - we need another way to explore

How do we get the most out of this plot?

40 / 125

Problem #1: How do I look at some of the data?

41 / 125

Problem #1: How do I look at some of the data?

Problem #2: How do I find interesting observations?

41 / 125

Problem #1: How do I look at some of the data?

Problem #2: How do I find interesting observations?

Problem #3: How do I understand my statistical model

41 / 125

Introducing brolgar: brolgar.njtierney.com

  • browsing
  • over
  • longitudinal data
  • graphically, and
  • analytically, in
  • r

42 / 125
  • It's a crane, it fishes, and it's a native Australian bird

43 / 125

What is longitudinal data?

Something observed sequentially over time

44 / 125

What is longitudinal data?

Something Anything that is observed sequentially over time is a time series

45 / 125

What is longitudinal data? Longitudinal data is a time series.

Something Anything that is observed sequentially over time is a time series

46 / 125

Longitudinal data as a time series

heights <- as_tsibble(heights,
index = year,
key = country,
regular = FALSE)
  1. index: Your time variable
  2. key: Variable(s) defining individual groups (or series)

1. + 2. determine distinct rows in a tsibble.

(From Earo Wang's talk: Melt the clock)

47 / 125

Longitudinal data as a time series

Key Concepts:

Record important time series information once, and use it many times in other places

  • We add information about index + key
    • Index = Year
    • Key = Country
48 / 125
## # A tsibble: 1,499 x 4 [!]
## # Key: country [153]
## country year height_cm continent
## <chr> <dbl> <dbl> <chr>
## 1 Afghanistan 1870 168. Asia
## 2 Afghanistan 1880 166. Asia
## 3 Afghanistan 1930 167. Asia
## 4 Afghanistan 1990 167. Asia
## 5 Afghanistan 2000 161. Asia
## 6 Albania 1880 170. Europe
## # … with 1,493 more rows
49 / 125

Remember:

key = variable(s) defining individual groups (or series)

50 / 125

Problem #1: How do I look at some of the data?

51 / 125

Problem #1: How do I look at some of the data?

Look at only a sample of the data:

51 / 125

Sample n rows with sample_n()

52 / 125

Sample n rows with sample_n()

heights %>% sample_n(5)
## # A tsibble: 5 x 4 [!]
## # Key: country [5]
## country year height_cm continent
## <chr> <dbl> <dbl> <chr>
## 1 Cote d'Ivoire 1890 169. Africa
## 2 Argentina 1810 169. Americas
## 3 United States 1920 173. Americas
## 4 Netherlands 1810 166 Europe
## 5 Nigeria 1870 166. Africa
52 / 125

Sample n rows with sample_n()

53 / 125

Sample n rows with sample_n()

## # A tsibble: 5 x 4 [!]
## # Key: country [5]
## country year height_cm continent
## <chr> <dbl> <dbl> <chr>
## 1 Malawi 1940 166. Africa
## 2 Italy 1960 173 Europe
## 3 Kazakhstan 1850 165. Asia
## 4 Colombia 1980 171. Americas
## 5 Switzerland 1910 172. Europe
54 / 125

Sample n rows with sample_n()

## # A tsibble: 5 x 4 [!]
## # Key: country [5]
## country year height_cm continent
## <chr> <dbl> <dbl> <chr>
## 1 Malawi 1940 166. Africa
## 2 Italy 1960 173 Europe
## 3 Kazakhstan 1850 165. Asia
## 4 Colombia 1980 171. Americas
## 5 Switzerland 1910 172. Europe

... sampling needs to select not random rows of the data, but the keys - the countries.

54 / 125

sample_n_keys() to sample ... keys

sample_n_keys(heights, 5)
## # A tsibble: 35 x 4 [!]
## # Key: country [5]
## country year height_cm continent
## <chr> <dbl> <dbl> <chr>
## 1 Azerbaijan 1850 170. Asia
## 2 Azerbaijan 1860 171. Asia
## 3 Azerbaijan 1950 171. Asia
## 4 Azerbaijan 1960 172. Asia
## 5 Azerbaijan 1970 172. Asia
## 6 Azerbaijan 1980 172. Asia
## # … with 29 more rows
55 / 125

sample_n_keys() to sample ... keys

56 / 125

Problem #1: How do I look at some of the data?

Look at subsamples

57 / 125

Problem #1: How do I look at some of the data?

Look at subsamples

Look at many subsamples

57 / 125

Look at many subsamples

58 / 125

Look at many subsamples

59 / 125

Look at many subsamples

60 / 125

How to look at many subsamples

  • How many facets to look at? (2, 4, ... 16?)
  • How many keys per facets?
    • 153 keys into 16 facets = 9 each
  • Randomly pick 16 groups of size 9.
61 / 125

How to look at many subsamples

  • How many facets to look at? (2, 4, ... 16?)
  • How many keys per facets?
    • 153 keys into 16 facets = 9 each
  • Randomly pick 16 groups of size 9.
  • This might not look like much extra work, but it hits the distraction threshold quite quickly.
61 / 125

Distraction threshold (time to rabbit hole)

62 / 125

Distraction threshold (time to rabbit hole)

(Something I made up)

62 / 125

Distraction threshold (time to rabbit hole)

(Something I made up)

If you have to solve 3+ substantial smaller problems in order to solve a larger problem, your focus shifts from the current goal to something else. You are distracted.

62 / 125

Distraction threshold (time to rabbit hole)

I want to look at many subsamples of the data

63 / 125

Distraction threshold (time to rabbit hole)

I want to look at many subsamples of the data

How many keys are there?

63 / 125

Distraction threshold (time to rabbit hole)

I want to look at many subsamples of the data

How many keys are there?

How many facets do I want to look at

63 / 125

Distraction threshold (time to rabbit hole)

I want to look at many subsamples of the data

How many keys are there?

How many facets do I want to look at

How many keys per facet should I look at

63 / 125

Distraction threshold (time to rabbit hole)

I want to look at many subsamples of the data

How many keys are there?

How many facets do I want to look at

How many keys per facet should I look at

How do I ensure there are the same number of keys per plot

63 / 125

Distraction threshold (time to rabbit hole)

I want to look at many subsamples of the data

How many keys are there?

How many facets do I want to look at

How many keys per facet should I look at

How do I ensure there are the same number of keys per plot

What is rep, rep.int, and rep_len?

63 / 125

Distraction threshold (time to rabbit hole)

I want to look at many subsamples of the data

How many keys are there?

How many facets do I want to look at

How many keys per facet should I look at

How do I ensure there are the same number of keys per plot

What is rep, rep.int, and rep_len?

Do I want length.out or times?

63 / 125

Avoiding the rabbit hole

64 / 125

Avoiding the rabbit hole

We can blame ourselves when we are distracted for not being better.

64 / 125

Avoiding the rabbit hole

We can blame ourselves when we are distracted for not being better.

It's not that we should be better, rather with better tools we could be more efficient.

64 / 125

Avoiding the rabbit hole

We can blame ourselves when we are distracted for not being better.

It's not that we should be better, rather with better tools we could be more efficient.

We need to make things as easy as reasonable, with the least amount of distraction.

64 / 125

Removing the distraction threshold means asking the most relevant question

65 / 125

Removing the distraction threshold means asking the most relevant question

How many plots do I want to look at?

65 / 125

Removing the distraction threshold means asking the most relevant question

How many plots do I want to look at?

gg_heights(heights) +
facet_sample(
n_per_facet = 3,
n_facets = 9
)
65 / 125

66 / 125

facet_sample(): See more individuals

ggplot(heights, aes(x = year,
y = height_cm,
group = country)) +
geom_line()

67 / 125

facet_sample(): See more individuals

ggplot(heights,
aes(x = year,
y = height_cm,
group = country)) +
geom_line() +
facet_sample()
68 / 125

facet_sample(): See more individuals

69 / 125

facet_strata(): See all individuals

ggplot(heights,
aes(x = year,
y = height_cm,
group = country)) +
geom_line() +
facet_strata()
70 / 125

facet_strata(): See all individuals

71 / 125

Focus on answering relevant questions instead of the minutae:

"How many lines per facet"

"How many facets?"

ggplot +
facet_sample(
n_per_facet = 10,
n_facets = 12
)
72 / 125

Focus on answering relevant questions instead of the minutae:

"How many lines per facet"

"How many facets?"

ggplot +
facet_sample(
n_per_facet = 10,
n_facets = 12
)

"How many facets to shove all the data in?"

ggplot +
facet_strata(
n_strata = 10,
)
72 / 125

Can we re-order these facets in a meaningful way?

73 / 125

In asking these questions we can solve something else interesting

facet_strata(along = -year): see all individuals along some variable

ggplot(heights,
aes(x = year,
y = height_cm,
group = country)) +
geom_line() +
facet_strata(along = -year)
74 / 125

facet_strata(along = -year): see all individuals along some variable

75 / 125

facet_strata() & facet_sample() Under the hood

  • using sample_n_keys() and stratify_keys()
76 / 125

facet_strata() & facet_sample() Under the hood

  • using sample_n_keys() and stratify_keys()
  • So you can still get at the data and do more manipulations
76 / 125

Problem #1: How do I look at some of the data?

77 / 125

Problem #1: How do I look at some of the data?

as_tsibble()

sample_n_keys()

facet_sample()

facet_strata()

77 / 125

Problem #1: How do I look at some of the data?

as_tsibble()

sample_n_keys()

facet_sample()

facet_strata()

Store useful information

View subsamples of data

View many subsamples

View all subsamples

77 / 125

Problem #1: How do I look at some of the data?

as_tsibble()

sample_n_keys()

facet_sample()

facet_strata()

Store useful information

View subsamples of data

View many subsamples

View all subsamples

78 / 125

Problem #2: How do I find interesting observations?

79 / 125

Problem #2: How do I find interesting observations?

80 / 125

Define interesting?

81 / 125

Identify features: summarise down to one observation

82 / 125

Identify features: summarise down to one observation

83 / 125

Identify features: summarise down to one observation

84 / 125

Identify important features and decide how to filter

85 / 125

Identify important features and decide how to filter

86 / 125

Join this feature back to the data

87 / 125

Join this feature back to the data

88 / 125

🎉 Countries with smallest and largest max height

89 / 125

Let's see that one more time, but with the data

90 / 125

Identify features: summarise down to one observation

## # A tsibble: 1,499 x 4 [!]
## # Key: country [153]
## country year height_cm continent
## <chr> <dbl> <dbl> <chr>
## 1 Afghanistan 1870 168. Asia
## 2 Afghanistan 1880 166. Asia
## 3 Afghanistan 1930 167. Asia
## 4 Afghanistan 1990 167. Asia
## 5 Afghanistan 2000 161. Asia
## 6 Albania 1880 170. Europe
## 7 Albania 1890 170. Europe
## 8 Albania 1900 169. Europe
## 9 Albania 2000 168. Europe
## 10 Algeria 1910 169. Africa
## # … with 1,489 more rows
91 / 125

Identify features: summarise down to one observation

## # A tibble: 153 x 6
## country min q25 med q75 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Afghanistan 161. 164. 167. 168. 168.
## 2 Albania 168. 168. 170. 170. 170.
## 3 Algeria 166. 168. 169 170. 171.
## 4 Angola 159. 160. 167. 168. 169.
## 5 Argentina 167. 168. 168. 170. 174.
## 6 Armenia 164. 166. 169. 172. 172.
## 7 Australia 170 171. 172. 173. 178.
## 8 Austria 162. 164. 167. 169. 179.
## 9 Azerbaijan 170. 171. 172. 172. 172.
## 10 Bahrain 161. 161. 164. 164. 164
## # … with 143 more rows
92 / 125

Identify important features and decide how to filter

heights_five %>%
filter(max == max(max) | max == min(max))
## # A tibble: 2 x 6
## country min q25 med q75 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Denmark 165. 168. 170. 178. 183.
## 2 Papua New Guinea 152. 152. 156. 160. 161.
93 / 125

Join summaries back to data

heights_five %>%
filter(max == max(max) | max == min(max)) %>%
left_join(heights, by = "country")
## # A tibble: 21 x 9
## country min q25 med q75 max year height_cm continent
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
## 1 Denmark 165. 168. 170. 178. 183. 1820 167. Europe
## 2 Denmark 165. 168. 170. 178. 183. 1830 165. Europe
## 3 Denmark 165. 168. 170. 178. 183. 1850 167. Europe
## 4 Denmark 165. 168. 170. 178. 183. 1860 168. Europe
## 5 Denmark 165. 168. 170. 178. 183. 1870 168. Europe
## 6 Denmark 165. 168. 170. 178. 183. 1880 170. Europe
## 7 Denmark 165. 168. 170. 178. 183. 1890 169. Europe
## 8 Denmark 165. 168. 170. 178. 183. 1900 170. Europe
## 9 Denmark 165. 168. 170. 178. 183. 1910 170 Europe
## 10 Denmark 165. 168. 170. 178. 183. 1920 174. Europe
## # … with 11 more rows
94 / 125

95 / 125

Identify features: one per key

heights %>%
features(height_cm,
feat_five_num)
## # A tibble: 153 x 6
## country min q25 med q75 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Afghanistan 161. 164. 167. 168. 168.
## 2 Albania 168. 168. 170. 170. 170.
## 3 Algeria 166. 168. 169 170. 171.
## 4 Angola 159. 160. 167. 168. 169.
## 5 Argentina 167. 168. 168. 170. 174.
## 6 Armenia 164. 166. 169. 172. 172.
## # … with 147 more rows
96 / 125

features: Summaries that are aware of data structure

97 / 125

features: Summaries that are aware of data structure

heights %>%
features(height_cm, #<< # variable we want to summarise
feat_five_num) #<< # feature to calculate
97 / 125

features: Summaries that are aware of data structure

heights %>%
features(height_cm, #<< # variable we want to summarise
feat_five_num) #<< # feature to calculate
## # A tibble: 153 x 6
## country min q25 med q75 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Afghanistan 161. 164. 167. 168. 168.
## 2 Albania 168. 168. 170. 170. 170.
## 3 Algeria 166. 168. 169 170. 171.
## 4 Angola 159. 160. 167. 168. 169.
## 5 Argentina 167. 168. 168. 170. 174.
## 6 Armenia 164. 166. 169. 172. 172.
## # … with 147 more rows
97 / 125

features: what is feat_five_num?

98 / 125

features: what is feat_five_num?

feat_five_num
## function(x, ...) {
## list(
## min = b_min(x, ...),
## q25 = b_q25(x, ...),
## med = b_median(x, ...),
## q75 = b_q75(x, ...),
## max = b_max(x, ...)
## )
## }
## <bytecode: 0x7fb6bc8fcba0>
## <environment: namespace:brolgar>
98 / 125

features: what is feat_five_num?

99 / 125

Other available features() in brolgar

100 / 125

What is the range of the data? feat_ranges

heights %>%
features(height_cm, feat_ranges)
## # A tibble: 153 x 5
## country min max range_diff iqr
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Afghanistan 161. 168. 7 3.27
## 2 Albania 168. 170. 2.20 1.53
## 3 Algeria 166. 171. 5.06 2.15
## 4 Angola 159. 169. 10.5 7.87
## 5 Argentina 167. 174. 7 2.21
## 6 Armenia 164. 172. 8.82 5.30
## 7 Australia 170 178. 8.4 2.58
## 8 Austria 162. 179. 17.2 5.35
## 9 Azerbaijan 170. 172. 1.97 1.12
## 10 Bahrain 161. 164 3.3 2.75
## # … with 143 more rows
101 / 125

Does my data only increase or decrease? feat_monotonic

heights %>%
features(height_cm, feat_monotonic)
## # A tibble: 153 x 5
## country increase decrease unvary monotonic
## <chr> <lgl> <lgl> <lgl> <lgl>
## 1 Afghanistan FALSE FALSE FALSE FALSE
## 2 Albania FALSE TRUE FALSE TRUE
## 3 Algeria FALSE FALSE FALSE FALSE
## 4 Angola FALSE FALSE FALSE FALSE
## 5 Argentina FALSE FALSE FALSE FALSE
## 6 Armenia FALSE FALSE FALSE FALSE
## 7 Australia FALSE FALSE FALSE FALSE
## 8 Austria FALSE FALSE FALSE FALSE
## 9 Azerbaijan FALSE FALSE FALSE FALSE
## 10 Bahrain TRUE FALSE FALSE TRUE
## # … with 143 more rows
102 / 125

What is the spread of my data? feat_spread

heights %>%
features(height_cm, feat_spread)
## # A tibble: 153 x 5
## country var sd mad iqr
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Afghanistan 7.20 2.68 1.65 3.27
## 2 Albania 0.950 0.975 0.667 1.53
## 3 Algeria 3.30 1.82 0.741 2.15
## 4 Angola 16.9 4.12 3.11 7.87
## 5 Argentina 2.89 1.70 1.36 2.21
## 6 Armenia 10.6 3.26 3.60 5.30
## 7 Australia 7.63 2.76 1.66 2.58
## 8 Austria 26.6 5.16 3.93 5.35
## 9 Azerbaijan 0.516 0.718 0.621 1.12
## 10 Bahrain 3.42 1.85 0.297 2.75
## # … with 143 more rows
103 / 125

features: MANY more features in feasts

Such as:

  • feat_acf: autocorrelation-based features
  • feat_stl: STL (Seasonal, Trend, and Remainder by LOESS) decomposition
104 / 125

Problem #1: How do I look at some of the data?

105 / 125

Problem #1: How do I look at some of the data?

Problem #2: How do I find interesting observations?

105 / 125

Problem #1: How do I look at some of the data?

Problem #2: How do I find interesting observations?

  • Decide what features are interesting
  • Summarise down to one observation
  • Decide how to filter
  • Join this feature back to the data
105 / 125

Problem #1: How do I look at some of the data?

Problem #2: How do I find interesting observations?

106 / 125

Problem #1: How do I look at some of the data?

Problem #2: How do I find interesting observations?

Problem #3: How do I understand my statistical model

106 / 125

Problem #3: How do I understand my statistical model

Let's fit a simple mixed effects model to the data

Fixed effect of year + Random intercept for country

heights_fit <- lmer(height_cm ~ year + (1|country), heights)
heights_aug <- heights %>%
add_predictions(heights_fit, var = "pred") %>%
add_residuals(heights_fit, var = "res")
107 / 125

Problem #3: How do I understand my statistical model

## # A tsibble: 1,499 x 6 [!]
## # Key: country [153]
## country year height_cm continent pred res
## <chr> <dbl> <dbl> <chr> <dbl> <dbl>
## 1 Afghanistan 1870 168. Asia 164. 4.58
## 2 Afghanistan 1880 166. Asia 164. 1.51
## 3 Afghanistan 1930 167. Asia 166. 0.815
## 4 Afghanistan 1990 167. Asia 168. -1.05
## 5 Afghanistan 2000 161. Asia 169. -7.11
## 6 Albania 1880 170. Europe 168. 2.40
## 7 Albania 1890 170. Europe 168. 1.74
## 8 Albania 1900 169. Europe 168. 0.775
## 9 Albania 2000 168. Europe 172. -4.13
## 10 Algeria 1910 169. Africa 168. 1.28
## # … with 1,489 more rows
108 / 125

Problem #3: How do I understand my statistical model

109 / 125

Look at some subsamples?

gg_heights_fit + facet_sample()

110 / 125

Look at all subsamples?

gg_heights_fit + facet_strata()

111 / 125

Look at all subsamples arranged by residuals?

gg_heights_fit + facet_strata(along = -res)

112 / 125

Look at the predictions with the data?

set.seed(2019-11-13)
heights_sample <-
heights_aug %>%
sample_n_keys(size = 9) %>% #<< sample the data
ggplot(aes(
x = year,
y = pred,
group = country)) +
geom_line() +
facet_wrap(~country)
heights_sample

113 / 125

Look at the predictions with the data?

heights_sample +
geom_point(
aes(
y = height_cm #<< add the original data
))

114 / 125

What if we grabbed a sample of those who have the best, middle, and worst residuals?

115 / 125

What if we grabbed a sample of those who have the best, middle, and worst residuals?

summary(heights_aug$res)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -8.167 -1.614 -0.157 0.000 1.352 12.174
115 / 125

What if we grabbed a sample of those who have the best, middle, and worst residuals?

summary(heights_aug$res)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -8.167 -1.614 -0.157 0.000 1.352 12.174

Which countries are nearest to these statistics?

115 / 125

use keys_near()

heights_aug %>%
keys_near(key = country,
var = res)
## # A tibble: 5 x 5
## country res stat stat_value stat_diff
## <chr> <dbl> <fct> <dbl> <dbl>
## 1 Ireland -8.17 min -8.17 0
## 2 Vietnam -1.61 q_25 -1.61 0.00000278
## 3 Mauritania -0.157 med -0.157 0
## 4 Sudan 1.35 q_75 1.35 0.000174
## 5 Poland 12.2 max 12.2 0

This shows us the keys that closely match the five number summary.

116 / 125

Show data by joining it with predictions, to explore the spread of predictions.

left_join(heights_near,
heights_aug,
by = "country") %>%
ggplot(aes(x = year,
y = pred,
group = country,
colour = stat)) +
geom_line() +
geom_point(aes(y = height_cm)) +
facet_wrap(~country)

117 / 125

Take homes

Problem #1: How do I look at some of the data?

  1. Longitudinal data is a time series
  2. Specify structure once, get a free lunch.
  3. Look at as much of the raw data as possible
  4. Use facet_sample() / facet_strata() to look at data
118 / 125

Take homes

Problem #2: How do I find interesting observations?

  1. Summarise with features to find interesting observations
  2. Reconnect summaries to data with a left join
119 / 125

Take homes

Problem #3: How do I understand my statistical model

  1. Look at (one, more or all!) subsamples
  2. Arrange subsamples
  3. Find keys near some summary
  4. Join keys to data to explore representatives
120 / 125

Thanks

  • Di Cook
  • Tania Prvan
  • Stuart Lee
  • Mitchell O'Hara Wild
  • Earo Wang
  • Rob Hyndman
  • Miles McBain
  • Monash University
121 / 125

Resources

122 / 125

Colophon

123 / 125

Learning more

brolgar.njtierney.com

bit.ly/njt-anu

nj_tierney

njtierney

nicholas.tierney@gmail.com

124 / 125

End.

125 / 125
  • now let's go through these same principles:

    • Sample the fits
    • Many samples of the fits
    • Explore the residuals
    • Find the best, worst, middle of the ground residuals
    • follow the "gliding" process again.
  • Which are most similar to which stats?

    • "who is similar to me?"
    • "who is the most average?"
    • "who is the most extreme?"
    • "Who is the most different to me?"

EDA: Why it's worth it

Anscombe's quartet

(My) Background

2 / 125

I want to talk a bit about where I've started from, because I think it might be useful to understand my perspective, and why I'm interested in doing these things.

Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow