-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
112 lines (74 loc) · 4.53 KB
/
README.Rmd
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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# bracketpredictr
<!-- badges: start -->
[![R-CMD-check](https://github.com/sethbeckett/bracketpredictr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/sethbeckett/bracketpredictr/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
```{r load_package, include=FALSE}
devtools::load_all()
```
## Introduction
The `` bracketpredictr `` package offers a comprehensive set of functions for analyzing Division I college basketball stats, from 2013 to 2019. The package allows users to easily retrieve team and game stats for a given season or multiple seasons and predict the winners of upcoming games. This can be particularly helpful for those interested in performing in-depth analysis on college basketball performance and making informed predictions for tournaments such as the NCAA March Madness. You can find the Github repository for this package **[here](https://github.com/sethbeckett/bracketpredictr)**[https://github.com/sethbeckett/bracketpredictr].
## Installation
To install `bracketpredictr`, use the following commands for installing from github or locally:
```{r, label="install", eval=FALSE}
# For installing from GitHub
# install.packages("remotes")
# remotes::install_github("sethbeckett/bracketpredictr")
```
## Data - `cbb.csv` (College Basketball Dataset)
This is a combined dataset of Division I basketball teams, across 6 seasons, and 22 variable stats (such as ORB, ADJOE, and SEED). It includes the years 2013-2019, with 2020 specifically not included in the dataset because of a lack of a postseason due to COVID-19. 2013-2019 was manipulate (cleaned) with the intent of just those years being analyzed together, so for the sake of consistency, the year 2021 was omitted from being added.
### Source of Data
*Andrew Sundberg. (3/15/2021). College Basketball Dataset, Version 4. Retrieved 3/31/2023 from https://www.kaggle.com/datasets/andrewsundberg/college-basketball-dataset*
## Example Usage
Here are some examples of how to use the functions provided by the `bracketpredictr` package:
### Retrieving Team Stats
To retrieve the names of all available team stats, you can use the `get_stats_names()` function:
```{r}
library(bracketpredictr)
get_stats_names()
```
This will output a list of all available teams, sorted alphabetically.
To retrieve team stats for one or more teams, use the `get_team_stats()` function:
```{r}
teams <- c("Duke", "North Carolina", "Kentucky")
stats <- c("TEAM", "W", "ADJOE", "ADJDE")
years <- seq(2013, 2019)
get_team_stats(teams, stats, years)
```
This will output a table showing the requested stats for the specified teams and years. If only wanting one team, stat, or year, you can input just that individual item instead of a vector.
### Predicting Game Winners
To predict the winner of a game between two teams, use the `predict_winner()` function:
```{r}
team1 <- "Utah"
team2 <- "BYU"
stats <- c("ADJOE", "ADJDE")
year <- 2019
predict_winner(team1, team2, stats, year)
```
This will output the predicted winner of the game based on the specified team stats, and year.
### Plotting Team Stats
One convenient way our package can be used is to plot two teams' statistics over time, using our `plot_stats()` function. In this example, we'll use the the variables defined in the previous example to plot ADJOE and ADJDE of Utah vs BYU over time. This plot fucntion also correctly maps teams names to their corresponding colors, as can be seen below.
```{r, fig.width=7, fig.height=5}
plot_stats(team1, team2, stats)
```
Alternatively, one could use ggplot to do something similar if plotting the statistics of more teams is desired. For example, let's compare Utah, BYU, and Utah St. ADJOE.
```{r, fig.width=7, fig.height=5}
library(ggplot2)
ut_adjoe <- get_team_stats(c("Utah", "BYU", "Utah St."), "ADJOE")
ggplot(ut_adjoe, aes(x = YEAR, y = ADJOE, color = TEAM)) +
geom_line() +
theme_bw()
```
## Conclusion
The `bracketpredictr` package offers a efficient and convenient set of functions for analyzing college basketball stats. This can be done by getting team stats, making predictions on tournaments based on previous games, and more applicable functions. By providing easy access to past data and predictive capabilities, it enables users to conduct in-depth analyses and make well-informed predictions for college basketball tournaments in the future.