library(tidyverse)
## Warning: replacing previous import 'lifecycle::last_warnings' by
## 'rlang::last_warnings' when loading 'tibble'
## Warning: replacing previous import 'ellipsis::check_dots_unnamed' by
## 'rlang::check_dots_unnamed' when loading 'tibble'
## Warning: replacing previous import 'ellipsis::check_dots_used' by
## 'rlang::check_dots_used' when loading 'tibble'
## Warning: replacing previous import 'ellipsis::check_dots_empty' by
## 'rlang::check_dots_empty' when loading 'tibble'
## Warning: replacing previous import 'lifecycle::last_warnings' by
## 'rlang::last_warnings' when loading 'pillar'
## Warning: replacing previous import 'ellipsis::check_dots_unnamed' by
## 'rlang::check_dots_unnamed' when loading 'pillar'
## Warning: replacing previous import 'ellipsis::check_dots_used' by
## 'rlang::check_dots_used' when loading 'pillar'
## Warning: replacing previous import 'ellipsis::check_dots_empty' by
## 'rlang::check_dots_empty' when loading 'pillar'
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2     ✓ purrr   0.3.4
## ✓ tibble  3.0.4     ✓ dplyr   1.0.2
## ✓ tidyr   1.1.2     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(readr)
library(dplyr)
install.packages('janitor')
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.0'
## (as 'lib' is unspecified)
# 2023
nca_fix_2023 <- read_csv("NEW2023 Nextech Stats Showdown - NCAABB Stats 2013-2023 - 2023.csv",
    col_types = cols(`Number of Tournament Wins` = col_number())) %>%
  janitor::clean_names() %>%
  mutate(year = 2023)

# 2022
nca_fix_2022 <- read_csv("NCAABB 2022.csv") %>%
  janitor::clean_names() %>%
  mutate(year = 2022)
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   .default = col_double(),
##   Team = col_character(),
##   Conference = col_character(),
##   Region = col_character()
## )
## ℹ Use `spec()` for the full column specifications.
total <- full_join(nca_fix_2023, nca_fix_2022) %>%
  mutate(wins / losses)
## Joining, by = c("team", "conference", "region", "cind",
## "conference_tournament_champion", "number_of_tournament_wins",
## "made_tournament_previous_year", "game_count", "wins", "losses",
## "x3_pointers_made", "x3_pointers_attempted", "x3_point_percentage",
## "free_throws_made", "free_throws_attempted", "free_throw_percentage",
## "rebounds", "opponents_rebounds", "rebound_differential", "offensive_rebounds",
## "assists", "turnovers", "assist_to_turnover_ratio",
## "espn_strength_of_schedule", "quad_1_wins", "quad_1_losses", "total_points",
## "average_ppg", "total_opp_points", "average_opp_ppg",
## "total_scoring_differential", "scoring_differential_per_game", "year")
total
## # A tibble: 136 x 34
##    team  conference region  cind conference_tour… number_of_tourn…
##    <chr> <chr>      <chr>  <dbl>            <dbl>            <dbl>
##  1 Alab… SEC        South      0                1               NA
##  2 Ariz… P12        South      0                1               NA
##  3 Ariz… P12        West       1                0               NA
##  4 Arka… SEC        West       0                0               NA
##  5 Aubu… SEC        Midwe…     1                0               NA
##  6 Bayl… B12        South      0                0               NA
##  7 Bois… MWC        West       1                0               NA
##  8 Col.… CAA        South      1                1               NA
##  9 Colg… Pat        Midwe…     1                1               NA
## 10 Crei… BE         South      0                0               NA
## # … with 126 more rows, and 28 more variables:
## #   made_tournament_previous_year <dbl>, game_count <dbl>, wins <dbl>,
## #   losses <dbl>, x3_pointers_made <dbl>, x3_pointers_attempted <dbl>,
## #   x3_point_percentage <dbl>, free_throws_made <dbl>,
## #   free_throws_attempted <dbl>, free_throw_percentage <dbl>, rebounds <dbl>,
## #   opponents_rebounds <dbl>, rebound_differential <dbl>,
## #   offensive_rebounds <dbl>, assists <dbl>, turnovers <dbl>,
## #   assist_to_turnover_ratio <dbl>, espn_strength_of_schedule <dbl>,
## #   quad_1_wins <dbl>, quad_1_losses <dbl>, total_points <dbl>,
## #   average_ppg <dbl>, total_opp_points <dbl>, average_opp_ppg <dbl>,
## #   total_scoring_differential <dbl>, scoring_differential_per_game <dbl>,
## #   year <dbl>, `wins/losses` <dbl>
# Algorithm
total %>%
  filter(x3_pointers_attempted >= 599, 
         free_throws_attempted >= 520,
         free_throw_percentage >= 0.7,
         conference_tournament_champion == 1,
         made_tournament_previous_year == 1,
         losses < 9,
         cind == 0,
         year == 2023
         ) %>%
  
  select(team,
         `wins/losses`,
         assist_to_turnover_ratio,
         offensive_rebounds,
         free_throw_percentage,
         assists,
         scoring_differential_per_game
         ) %>%
  
  arrange(desc(`wins/losses`))
## # A tibble: 10 x 7
##    team  `wins/losses` assist_to_turno… offensive_rebou… free_throw_perc…
##    <chr>         <dbl>            <dbl>            <dbl>            <dbl>
##  1 Hous…         10.3              1.55              403            0.719
##  2 Alab…          5.8              1.11              400            0.726
##  3 Purd…          5.8              1.46              387            0.743
##  4 Gonz…          5.6              1.60              313            0.701
##  5 Ariz…          4.67             1.45              316            0.708
##  6 Marq…          4.67             1.65              275            0.721
##  7 San …          4.5              1.21              322            0.732
##  8 Kans…          3.86             1.35              299            0.717
##  9 Duke           3.25             1.25              389            0.770
## 10 Texas          3.25             1.44              307            0.752
## # … with 2 more variables: assists <dbl>, scoring_differential_per_game <dbl>