forked from bambooforest/salos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoxplots_solutions.Rmd
More file actions
229 lines (195 loc) · 8.29 KB
/
Copy pathBoxplots_solutions.Rmd
File metadata and controls
229 lines (195 loc) · 8.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
---
title: "R Notebook"
output:
html_document:
df_print: paged
pdf_document: default
---
```{r, message = FALSE, echo = FALSE}
phoible <- read.csv("/Users/alena2/Library/CloudStorage/Dropbox/Teaching_Students/Classes_Courses/2023-2024/HUJI2024_Quant/Class5-6/phoible.csv")
```
```{r, message = FALSE, echo = FALSE}
library(tidyverse)
library(readxl)
require(forcats)
library(cowplot)
library(knitr)
library(kableExtra)
```
```{r, message = FALSE}
head(phoible)
```
# Task 1: Indo-European (ieur) vs. Nilo-Saharan (nsah)
* Consider the parallel boxplots of the Indo-European (ieur) and Nilo-Saharan (nsah) language families.
```{r, message = FALSE, echo = FALSE, out.width="60%"}
phoible %>%
filter(fam %in% c("nsah", "ieur")) %>%
ggplot(aes(y = phonemes, x = fam, fill = fam)) +
geom_boxplot()+
labs(title="Number of phonemes in Indo-European and Nilo-Saharan languages",
x ="family", y = "number of phonemes") +
theme_light()+
theme(axis.text.y = element_text(size = 12), axis.text.x = element_text(size = 12))
```
* Answer the following questions:
1. Which distribution has outliers? How many?
2. Which distribution is more compact?
3. Which distribution has the largest range (with and without the outliers)?
4. What is the range of Nilo-Saharan phoneme inventories?
5. Which distribution is negatively skewed?
6. How many languages are in each boxplot?
## Solutions
6. How many languages are in each boxplot?
One cannot say ont he basis of the boxplot, but one can always add individual datapoints:
```{r, message = FALSE, echo = FALSE, out.width="60%"}
phoible %>%
filter(fam %in% c("nsah", "ieur")) %>%
ggplot(aes(y = phonemes, x = fam, fill = fam)) +
geom_boxplot()+
labs(title="Number of phonemes in Indo-European and Nilo-Saharan languages",
x ="family", y = "number of phonemes") +
theme_light()+
theme(axis.text.y = element_text(size = 12), axis.text.x = element_text(size = 12))
```
# Task 2
* Consider the parallel boxplots of four language families:
```{r, message = FALSE, echo = FALSE, out.width="60%"}
phoible %>%
filter(genus %in% c("Mayan", "Germanic", "Semitic", "Indic")) %>%
ggplot(aes(y = con, x = genus, fill = genus)) +
geom_boxplot()+
labs(title="Number of consonants in four families",
x ="family", y = "number of consonants") +
theme_light()+
theme(axis.text.y = element_text(size = 12), axis.text.x = element_text(size = 12))
```
* The data set (number of consonants) for one of the four languages families is this:
```{r, message = FALSE, echo = FALSE}
phoible %>% filter(genus == "Germanic") %>% select(con) -> con
kable(con) %>%
kable_minimal(full_width = F)
```
* Which boxplot corresponds to this dataset? Discuss, the various aspects of the boxplot which make the identification possible.
## Solutions
* Germanic
```{r, message = FALSE, echo = FALSE}
phoible %>% filter(genus == "Germanic") %>% select(language, con) -> con
kable(con) %>%
kable_minimal(full_width = F)
```
# Task 3: boxplot vs. density plot
* Consider the parallel boxplots of the number of phonemes in four language families.
* One of the language families is visualized with a density plot. Which one is it?
```{r, message = FALSE, echo = FALSE, out.width="60%"}
phoible %>%
filter(fam %in% c("nsah", "sitb", "ieur", "drav")) %>%
ggplot(aes(y = phonemes, x = fam, fill = fam)) +
geom_boxplot()+
labs(title="Number of phonemes in four families") +
theme_light()+
theme(axis.text.y = element_text(size = 12), axis.text.x = element_text(size = 12))
```
```{r, message = FALSE, echo = FALSE, out.width="60%"}
phoible %>% filter(fam %in% c("nsah")) %>%
ggplot(aes(x = phonemes)) +
geom_density(fill = "red", alpha = 0.3) +
labs(title="Number of phonemes in a language family") +
theme_light()+
theme(axis.text.y = element_text(size = 12), axis.text.x = element_text(size = 12))
```
## Solutions
* Nilo-Saharan
```{r, message = FALSE, echo = FALSE, out.width="60%"}
phoible %>% filter(fam %in% c("nsah")) %>%
ggplot(aes(x = phonemes)) +
geom_density(fill = "red", alpha = 0.3) +
labs(title="Number of phonemes in the Nilo-Saharan languages") +
theme_light()+
theme(axis.text.y = element_text(size = 12), axis.text.x = element_text(size = 12))
```
# Task 4: boxplot vs. density plot
* Consider the parallel boxplots of the number of phonemes in four language families.
* Two of the language families are visualized with the density plots. Which oness are they?
* Explain how you can figure it out.
```{r, message = FALSE, echo = FALSE, out.width="60%"}
phoible %>%
filter(fam %in% c("ausa", "anes", "aust", "ieur")) %>%
ggplot(aes(y = phonemes, x = fam, fill = fam)) +
geom_boxplot()+
labs(title="Number of phonemes in four families",
x ="family", y = "number of phonemes") +
theme_light()+
theme(axis.text.y = element_text(size = 12), axis.text.x = element_text(size = 12))
```
```{r, message = FALSE, echo = FALSE, out.width="60%"}
phoible %>% filter(fam %in% c("aust", "anes")) %>%
ggplot(aes(x = phonemes, fill = fam)) +
geom_density(alpha = 0.3) +
labs(title="Number of phonemes in two language families") +
theme_light()+
theme(axis.text.y = element_text(size = 14), axis.text.x = element_text(size = 14)) +
theme(legend.position="none")
```
## Solutions
Australian (`aust`) and Austronesian (`anes`)
```{r, message = FALSE, echo = FALSE, out.width="60%"}
phoible %>% filter(fam %in% c("aust", "anes")) %>%
ggplot(aes(x = phonemes, fill = fam)) +
geom_density(alpha = 0.3) +
labs(title="Number of phonemes in two language families") +
theme_light()+
theme(axis.text.y = element_text(size = 14), axis.text.x = element_text(size = 14))
```
# Task 5: boxplot vs. histogram
* Consider the parallel boxplots of the number of phonemes in four language families.
* Three of the language families are visualized with the histograms. Which one is missing?
* Explain how you can figure it out.
```{r, message = FALSE, echo = FALSE, out.width="60%"}
phoible %>%
filter(fam %in% c("ausa", "altc", "trng", "anes")) %>%
ggplot(aes(y = phonemes, x = fam, fill = fam)) +
geom_boxplot()+
labs(title="Number of phonemes in four language families",
x ="family", y = "number of phonemes") +
theme_light()+
theme(axis.text.y = element_text(size = 12), axis.text.x = element_text(size = 12))
```
```{r, message = FALSE, echo = FALSE, out.width="60%"}
phoible %>% filter(fam %in% c("ausa", "altc", "trng")) %>%
# change order of factor by the family size
mutate(fam = fct_infreq(fam)) %>%
ggplot(aes(x = phonemes, fill = fam)) +
geom_histogram(binwidth = 5) +
labs(title="Number of phonemes in three language families",
x ="family", y = "number of phonemes") +
theme_light()+
theme(axis.text.y = element_text(size = 14), axis.text.x = element_text(size = 14)) +
theme(legend.position="none") +
facet_grid(. ~ fam ) +
theme(strip.text.x = element_text(size=0))
```
## Solutions
* The missing family is Austronesian (`anes`)
```{r, message = FALSE, echo = FALSE, out.width="60%"}
phoible %>% filter(fam %in% c("ausa", "altc", "trng")) %>%
# change order of factor by the family size
mutate(fam = fct_infreq(fam)) %>%
ggplot(aes(x = phonemes, fill = fam)) +
geom_histogram(binwidth = 5) +
labs(title="Number of phonemes in three language families",
x ="family", y = "number of phonemes") +
theme_light()+
theme(axis.text.y = element_text(size = 14), axis.text.x = element_text(size = 14)) +
theme(legend.position="none") +
facet_grid(. ~ fam )
```
```{r, message = FALSE, echo = FALSE, out.width="60%"}
phoible %>% filter(fam %in% c("ausa", "altc", "trng", "anes")) %>%
ggplot(aes(x = phonemes, fill = fam)) +
geom_histogram(binwidth = 5) +
labs(title="Number of phonemes in four language families") +
theme_light()+
theme(axis.text.y = element_text(size = 14), axis.text.x = element_text(size = 14)) +
theme(legend.position="none") +
facet_grid(. ~ fam)
```