library(tidyr)
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ purrr 1.0.2
## ✔ forcats 1.0.0 ✔ readr 2.1.4
## ✔ ggplot2 3.4.4 ✔ stringr 1.5.0
## ✔ lubridate 1.9.2 ✔ tibble 3.2.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
library(ggplot2)
library(boot)
volley_data <- read.csv("C:\\Users\\brian\\Downloads\\bvb_matches_2022.csv")
hgt_test <- aov(w_p1_hgt ~ w_p1_country, data = volley_data)
summary(hgt_test)
## Df Sum Sq Mean Sq F value Pr(>F)
## w_p1_country 46 6544 142.25 12.28 <2e-16 ***
## Residuals 2964 34326 11.58
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 1195 observations deleted due to missingness
clean_data <- na.omit(volley_data[, c("w_p1_hgt", "w_p1_country")])
result <- pairwise.t.test(volley_data$w_p1_hgt, volley_data$w_p1_country, p.adjust.method = "bonferroni")
print(result)
##
## Pairwise comparisons using t tests with pooled SD
##
## data: volley_data$w_p1_hgt and volley_data$w_p1_country
##
## Argentina Australia Austria Belgium Brazil Canada Chile China
## Australia - - - - - - - -
## Austria - - - - - - - -
## Belgium - - - - - - - -
## Brazil - - - - - - - -
## Canada - - - - - - - -
## Chile - - - - - - - -
## China - - - - - - - -
## Cuba - - - - - - - -
## Czech Republic - - - - - - - -
## Denmark - - - - - - - -
## England - - - - - - - -
## Estonia - - - - - - - -
## Finland - - - - - - - -
## France - - - - - - - -
## Germany - - - - - - - -
## Greece - - - - - - - -
## Hungary - - - - - - - -
## Indonesia - - - - - - - -
## Israel - - - - - - - -
## Italy - - - - - - - -
## Japan - - - - - - - -
## Latvia - - - - - - - -
## Lithuania - - - - - - - -
## Mexico - - - - - - - -
## Morocco - - - - - - - -
## Netherlands - - - - - - - -
## New Zealand - - - - - - - -
## Norway - - - - - - - -
## Oman - - - - - - - -
## Paraguay - - - - - - - -
## Poland - - - - - - - -
## Portugal - - - - - - - -
## Qatar - - - - - - - -
## Scotland - - - - - - - -
## Serbia - - - - - - - -
## Singapore - - - - - - - -
## Slovakia - - - - - - - -
## Slovenia - - - - - - - -
## Spain - - - - - - - -
## Sweden - - - - - - - -
## Switzerland - - - - - - - -
## Thailand - - - - - - - -
## Turkey - - - - - - - -
## Ukraine - - - - - - - -
## United States - - - - - - - -
## Uruguay - - - - - - - -
## Vanuatu - - - - - - - -
## Venezuela - - - - - - - -
## Vietnam - - - - - - - -
## Virgin Islands - - - - - - - -
## Cuba Czech Republic Denmark England Estonia Finland France
## Australia - - - - - - -
## Austria - - - - - - -
## Belgium - - - - - - -
## Brazil - - - - - - -
## Canada - - - - - - -
## Chile - - - - - - -
## China - - - - - - -
## Cuba - - - - - - -
## Czech Republic - - - - - - -
## Denmark - - - - - - -
## England - - - - - - -
## Estonia - - - - - - -
## Finland - - - - - - -
## France - - - - - - -
## Germany - - - - - - -
## Greece - - - - - - -
## Hungary - - - - - - -
## Indonesia - - - - - - -
## Israel - - - - - - -
## Italy - - - - - - -
## Japan - - - - - - -
## Latvia - - - - - - -
## Lithuania - - - - - - -
## Mexico - - - - - - -
## Morocco - - - - - - -
## Netherlands - - - - - - -
## New Zealand - - - - - - -
## Norway - - - - - - -
## Oman - - - - - - -
## Paraguay - - - - - - -
## Poland - - - - - - -
## Portugal - - - - - - -
## Qatar - - - - - - -
## Scotland - - - - - - -
## Serbia - - - - - - -
## Singapore - - - - - - -
## Slovakia - - - - - - -
## Slovenia - - - - - - -
## Spain - - - - - - -
## Sweden - - - - - - -
## Switzerland - - - - - - -
## Thailand - - - - - - -
## Turkey - - - - - - -
## Ukraine - - - - - - -
## United States - - - - - - -
## Uruguay - - - - - - -
## Vanuatu - - - - - - -
## Venezuela - - - - - - -
## Vietnam - - - - - - -
## Virgin Islands - - - - - - -
## Germany Greece Hungary Indonesia Israel Italy Japan Latvia
## Australia - - - - - - - -
## Austria - - - - - - - -
## Belgium - - - - - - - -
## Brazil - - - - - - - -
## Canada - - - - - - - -
## Chile - - - - - - - -
## China - - - - - - - -
## Cuba - - - - - - - -
## Czech Republic - - - - - - - -
## Denmark - - - - - - - -
## England - - - - - - - -
## Estonia - - - - - - - -
## Finland - - - - - - - -
## France - - - - - - - -
## Germany - - - - - - - -
## Greece - - - - - - - -
## Hungary - - - - - - - -
## Indonesia - - - - - - - -
## Israel - - - - - - - -
## Italy - - - - - - - -
## Japan - - - - - - - -
## Latvia - - - - - - - -
## Lithuania - - - - - - - -
## Mexico - - - - - - - -
## Morocco - - - - - - - -
## Netherlands - - - - - - - -
## New Zealand - - - - - - - -
## Norway - - - - - - - -
## Oman - - - - - - - -
## Paraguay - - - - - - - -
## Poland - - - - - - - -
## Portugal - - - - - - - -
## Qatar - - - - - - - -
## Scotland - - - - - - - -
## Serbia - - - - - - - -
## Singapore - - - - - - - -
## Slovakia - - - - - - - -
## Slovenia - - - - - - - -
## Spain - - - - - - - -
## Sweden - - - - - - - -
## Switzerland - - - - - - - -
## Thailand - - - - - - - -
## Turkey - - - - - - - -
## Ukraine - - - - - - - -
## United States - - - - - - - -
## Uruguay - - - - - - - -
## Vanuatu - - - - - - - -
## Venezuela - - - - - - - -
## Vietnam - - - - - - - -
## Virgin Islands - - - - - - - -
## Lithuania Mexico Morocco Netherlands New Zealand Norway Oman
## Australia - - - - - - -
## Austria - - - - - - -
## Belgium - - - - - - -
## Brazil - - - - - - -
## Canada - - - - - - -
## Chile - - - - - - -
## China - - - - - - -
## Cuba - - - - - - -
## Czech Republic - - - - - - -
## Denmark - - - - - - -
## England - - - - - - -
## Estonia - - - - - - -
## Finland - - - - - - -
## France - - - - - - -
## Germany - - - - - - -
## Greece - - - - - - -
## Hungary - - - - - - -
## Indonesia - - - - - - -
## Israel - - - - - - -
## Italy - - - - - - -
## Japan - - - - - - -
## Latvia - - - - - - -
## Lithuania - - - - - - -
## Mexico - - - - - - -
## Morocco - - - - - - -
## Netherlands - - - - - - -
## New Zealand - - - - - - -
## Norway - - - - - - -
## Oman - - - - - - -
## Paraguay - - - - - - -
## Poland - - - - - - -
## Portugal - - - - - - -
## Qatar - - - - - - -
## Scotland - - - - - - -
## Serbia - - - - - - -
## Singapore - - - - - - -
## Slovakia - - - - - - -
## Slovenia - - - - - - -
## Spain - - - - - - -
## Sweden - - - - - - -
## Switzerland - - - - - - -
## Thailand - - - - - - -
## Turkey - - - - - - -
## Ukraine - - - - - - -
## United States - - - - - - -
## Uruguay - - - - - - -
## Vanuatu - - - - - - -
## Venezuela - - - - - - -
## Vietnam - - - - - - -
## Virgin Islands - - - - - - -
## Paraguay Poland Portugal Qatar Scotland Serbia Singapore
## Australia - - - - - - -
## Austria - - - - - - -
## Belgium - - - - - - -
## Brazil - - - - - - -
## Canada - - - - - - -
## Chile - - - - - - -
## China - - - - - - -
## Cuba - - - - - - -
## Czech Republic - - - - - - -
## Denmark - - - - - - -
## England - - - - - - -
## Estonia - - - - - - -
## Finland - - - - - - -
## France - - - - - - -
## Germany - - - - - - -
## Greece - - - - - - -
## Hungary - - - - - - -
## Indonesia - - - - - - -
## Israel - - - - - - -
## Italy - - - - - - -
## Japan - - - - - - -
## Latvia - - - - - - -
## Lithuania - - - - - - -
## Mexico - - - - - - -
## Morocco - - - - - - -
## Netherlands - - - - - - -
## New Zealand - - - - - - -
## Norway - - - - - - -
## Oman - - - - - - -
## Paraguay - - - - - - -
## Poland - - - - - - -
## Portugal - - - - - - -
## Qatar - - - - - - -
## Scotland - - - - - - -
## Serbia - - - - - - -
## Singapore - - - - - - -
## Slovakia - - - - - - -
## Slovenia - - - - - - -
## Spain - - - - - - -
## Sweden - - - - - - -
## Switzerland - - - - - - -
## Thailand - - - - - - -
## Turkey - - - - - - -
## Ukraine - - - - - - -
## United States - - - - - - -
## Uruguay - - - - - - -
## Vanuatu - - - - - - -
## Venezuela - - - - - - -
## Vietnam - - - - - - -
## Virgin Islands - - - - - - -
## Slovakia Slovenia Spain Sweden Switzerland Thailand Turkey
## Australia - - - - - - -
## Austria - - - - - - -
## Belgium - - - - - - -
## Brazil - - - - - - -
## Canada - - - - - - -
## Chile - - - - - - -
## China - - - - - - -
## Cuba - - - - - - -
## Czech Republic - - - - - - -
## Denmark - - - - - - -
## England - - - - - - -
## Estonia - - - - - - -
## Finland - - - - - - -
## France - - - - - - -
## Germany - - - - - - -
## Greece - - - - - - -
## Hungary - - - - - - -
## Indonesia - - - - - - -
## Israel - - - - - - -
## Italy - - - - - - -
## Japan - - - - - - -
## Latvia - - - - - - -
## Lithuania - - - - - - -
## Mexico - - - - - - -
## Morocco - - - - - - -
## Netherlands - - - - - - -
## New Zealand - - - - - - -
## Norway - - - - - - -
## Oman - - - - - - -
## Paraguay - - - - - - -
## Poland - - - - - - -
## Portugal - - - - - - -
## Qatar - - - - - - -
## Scotland - - - - - - -
## Serbia - - - - - - -
## Singapore - - - - - - -
## Slovakia - - - - - - -
## Slovenia - - - - - - -
## Spain - - - - - - -
## Sweden - - - - - - -
## Switzerland - - - - - - -
## Thailand - - - - - - -
## Turkey - - - - - - -
## Ukraine - - - - - - -
## United States - - - - - - -
## Uruguay - - - - - - -
## Vanuatu - - - - - - -
## Venezuela - - - - - - -
## Vietnam - - - - - - -
## Virgin Islands - - - - - - -
## Ukraine United States Uruguay Vanuatu Venezuela Vietnam
## Australia - - - - - -
## Austria - - - - - -
## Belgium - - - - - -
## Brazil - - - - - -
## Canada - - - - - -
## Chile - - - - - -
## China - - - - - -
## Cuba - - - - - -
## Czech Republic - - - - - -
## Denmark - - - - - -
## England - - - - - -
## Estonia - - - - - -
## Finland - - - - - -
## France - - - - - -
## Germany - - - - - -
## Greece - - - - - -
## Hungary - - - - - -
## Indonesia - - - - - -
## Israel - - - - - -
## Italy - - - - - -
## Japan - - - - - -
## Latvia - - - - - -
## Lithuania - - - - - -
## Mexico - - - - - -
## Morocco - - - - - -
## Netherlands - - - - - -
## New Zealand - - - - - -
## Norway - - - - - -
## Oman - - - - - -
## Paraguay - - - - - -
## Poland - - - - - -
## Portugal - - - - - -
## Qatar - - - - - -
## Scotland - - - - - -
## Serbia - - - - - -
## Singapore - - - - - -
## Slovakia - - - - - -
## Slovenia - - - - - -
## Spain - - - - - -
## Sweden - - - - - -
## Switzerland - - - - - -
## Thailand - - - - - -
## Turkey - - - - - -
## Ukraine - - - - - -
## United States - - - - - -
## Uruguay - - - - - -
## Vanuatu - - - - - -
## Venezuela - - - - - -
## Vietnam - - - - - -
## Virgin Islands - - - - - -
##
## P value adjustment method: bonferroni
boot_ci <- function (v, func = median, conf = 0.95, n_iter = 100) {
# the function we want to run on each iteration i
boot_func <- \(x, i) func(x[i])
# the boot instance, running the function on each iteration
b <- boot(v, boot_func, R = n_iter)
b <- boot.ci(b, conf = conf, type = "perc")
# return just the lower and upper values
return(c("lower" = b$percent[4],
"upper" = b$percent[5]))
}
df_ci <- clean_data |>
group_by(w_p1_country) |>
summarise(ci_lower = if(length(unique(w_p1_hgt)) > 1) {
boot_ci(w_p1_hgt, mean)['lower']
} else {
NA
},
mean_hgt = mean(w_p1_hgt, na.rm = TRUE),
ci_upper = if (length(unique(w_p1_hgt)) > 1) {
boot_ci(w_p1_hgt, mean)['upper']
} else {
NA
}
)
df_ci
## # A tibble: 47 × 4
## w_p1_country ci_lower mean_hgt ci_upper
## <chr> <dbl> <dbl> <dbl>
## 1 Argentina 72.4 73.4 75.0
## 2 Australia 73.0 73.7 74.5
## 3 Austria 73.8 74.4 74.8
## 4 Belgium 73.4 74.2 74.9
## 5 Brazil 72.7 73.2 73.8
## 6 Canada 72.6 73.3 74.0
## 7 Chile 73.1 74.3 74.8
## 8 China 74.4 75.2 75.9
## 9 Cuba 71 75.7 78
## 10 Czech Republic 74.0 75.0 75.8
## # ℹ 37 more rows
df_ci |>
ggplot() +
geom_errorbarh(mapping = aes(y = w_p1_country,
xmin=ci_lower, xmax=ci_upper,
color = '95% C.I.'), height = 0.5) +
geom_point(mapping = aes(x = mean_hgt, y = w_p1_country,
color = 'Group Mean'),
shape = '|',
size = 5) +
scale_color_manual(values=c('black', 'orange')) +
labs(title = "Player Height by Country",
x = "Player Height (in inches)",
y = "Player Country",
color = '')
## Warning: Removed 10 rows containing missing values (`geom_errorbarh()`).
Given such as small p-value for the large dataset, we can safely conclude that the null hypothesis is likely not true.
After testing the data, it would be safe to assume that player heights are not equal between countries.
clean_data2 <- na.omit(volley_data[, c("w_p1_hgt", "w_p1_age")])
clean_data2 |>
ggplot(mapping = aes(x = w_p1_age, y = w_p1_hgt)) +
geom_point(size = 2) +
geom_smooth(method = "lm", se = FALSE, color = 'darkblue')
## `geom_smooth()` using formula = 'y ~ x'
model <- lm(w_p1_hgt ~ w_p1_age, clean_data2)
model$coefficients
## (Intercept) w_p1_age
## 72.51366488 0.04216138