Explore data

Is there a relationship between the sex of the member and deaths on specific peaks?

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── 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
members <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-09-22/members.csv')
## Rows: 76519 Columns: 21
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (10): expedition_id, member_id, peak_id, peak_name, season, sex, citizen...
## dbl  (5): year, age, highpoint_metres, death_height_metres, injury_height_me...
## lgl  (6): hired, success, solo, oxygen_used, died, injured
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Calculate total deaths by sex and peaks
chr_mem <- members %>%
  group_by(peak_name, sex) %>%
  summarise(died = sum(died)) %>%
  ungroup()
## `summarise()` has grouped output by 'peak_name'. You can override using the
## `.groups` argument.
chr_mem
## # A tibble: 645 × 3
##    peak_name     sex    died
##    <chr>         <chr> <int>
##  1 Aichyn        F         0
##  2 Aichyn        M         0
##  3 Ama Dablam    F         2
##  4 Ama Dablam    M        30
##  5 Amotsang      F         0
##  6 Amotsang      M         0
##  7 Amphu Gyabjen F         0
##  8 Amphu Gyabjen M         0
##  9 Amphu I       F         0
## 10 Amphu I       M         0
## # ℹ 635 more rows
# Calculate total number of deaths
chr_mem %>%
  group_by(peak_name) %>%
  summarise(yr_death = sum(died)) %>%
  ungroup()
## # A tibble: 391 × 2
##    peak_name          yr_death
##    <chr>                 <int>
##  1 Aichyn                    0
##  2 Ama Dablam               32
##  3 Amotsang                  0
##  4 Amphu Gyabjen             0
##  5 Amphu I                   0
##  6 Amphu Middle              0
##  7 Anidesh Chuli             0
##  8 Annapurna I              72
##  9 Annapurna I East          1
## 10 Annapurna I Middle        3
## # ℹ 381 more rows
chr_demo <- chr_mem %>%
  filter(sex %in% c("F", "M"))%>%
  pivot_wider(names_from = sex, values_from = died, values_fill = 0) %>%
  left_join(chr_mem %>%
              group_by(peak_name) %>%
              summarise(yr_death = sum(died))%>%
              ungroup()) %>%
  
  filter(yr_death > 0, yr_death < 100) %>%
  
  mutate(across(c(F, M), ~. / yr_death),
         died = log(yr_death),
         across(where(is.numeric), ~ as.numeric(scale(.))))
## Joining with `by = join_by(peak_name)`
chr_demo
## # A tibble: 85 × 5
##    peak_name                F       M yr_death    died
##    <chr>                <dbl>   <dbl>    <dbl>   <dbl>
##  1 Ama Dablam          0.0951 -0.0951   1.29    1.72  
##  2 Annapurna I        -0.0295  0.0295   3.59    2.35  
##  3 Annapurna I East   -0.279   0.279   -0.482  -0.994 
##  4 Annapurna I Middle -0.279   0.279   -0.367  -0.134 
##  5 Annapurna II       -0.279   0.279   -0.195   0.409 
##  6 Annapurna III      -0.279   0.279   -0.0236  0.726 
##  7 Annapurna IV        0.918  -0.918   -0.253   0.266 
##  8 Annapurna South    -0.279   0.279   -0.0809  0.634 
##  9 Api Main           -0.279   0.279   -0.310   0.0913
## 10 Baruntse           -0.279   0.279    0.206   1.01  
## # ℹ 75 more rows

Implementing k-means clustering

chr_clust <- kmeans(select(chr_demo, - peak_name), centers = 3)
summary(chr_clust)
##              Length Class  Mode   
## cluster      85     -none- numeric
## centers      12     -none- numeric
## totss         1     -none- numeric
## withinss      3     -none- numeric
## tot.withinss  1     -none- numeric
## betweenss     1     -none- numeric
## size          3     -none- numeric
## iter          1     -none- numeric
## ifault        1     -none- numeric
library(broom)
tidy(chr_clust)
## # A tibble: 3 × 7
##         F       M yr_death   died  size withinss cluster
##     <dbl>   <dbl>    <dbl>  <dbl> <int>    <dbl> <fct>  
## 1  0.0220 -0.0220    2.81   2.15      8     10.0 1      
## 2  4.06   -4.06     -0.410 -0.543     4     23.1 2      
## 3 -0.225   0.225    -0.285 -0.206    73     52.9 3
augment(chr_clust, chr_demo) %>%
  ggplot(aes(yr_death, peak_name, color = .cluster)) +
  geom_point()

Choosing k

kclusts <-
  tibble(k = 1:9) %>%
  mutate(
    kclust = map(k, ~ kmeans(select(chr_demo, - peak_name), .x)),
    tidied = map(kclust, tidy),
    glanced = map(kclust, glance),
    augmented = map(kclust, augment, chr_demo)
  )

kclusts %>%
  unnest(glanced) %>%
  ggplot(aes(k, tot.withinss)) +
  geom_line(alpha = 0.8) +
  geom_point(size = 2)

library(plotly)
## Warning: package 'plotly' was built under R version 4.3.2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
chr_clust <- kmeans(select(chr_demo, - peak_name), centers = 3)

p <- augment(chr_clust, chr_demo) %>%
  ggplot(aes(yr_death, F, color = .cluster, name = peak_name)) +
  geom_point(alpha = 0.8)

ggplotly(p)

Questions

1.1 The goal of this analysis is to determine any correlations between the deaths of members in expetitions and their genders. Using the sex of the members who have died can help determine if there a certain sex has a better time of surviving.

1.2 The dataset is a compilation of records for all expeditions that have climbed in the Nepal Himalaya.

1.3 The key variables in this analysis are the peak_names, sex, and died; peak_names and sex are categorical and died is the numeric value of how many people have tied.

2.1 The data transformation was aggregating deaths by peak and sex, and normalizing values to reflect proportional death risks based on sex.

3.1 The analysis uses k-means clustering, a method that splits the data into k distinct clusters by minimizing within-cluster variances.

3.2 To determine the optimal k for clustering, the analysis uses the “elbow method,” plotting the total within-cluster sum of squares against a range of k values.

4.1 The analysis shows that there is minimal correlation between the deaths on specific peaks to the sex of the climber. However, there is data to show which peaks are more dangerous to climb.