library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ 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
library(ggplot2)
library(dbplyr)
##
## Attaching package: 'dbplyr'
##
## The following objects are masked from 'package:dplyr':
##
## ident, sql
library(ggthemes)
library(ggrepel)
library(ggrepel)
library(broom)
library(lindia)
week3_dataset <- read.csv("baseball.csv",header = TRUE)
The Binary Data I choose is whether a team made the playoffs or not
week3_dataset <- week3_dataset %>%
mutate(win_square = sqrt(W))
sigmoid <- \(x) 1 / (1 + exp(-(-5 + 0.15 * x)))
week3_dataset %>%
ggplot(mapping = aes(x = W, y = Playoffs)) +
geom_jitter(width = 0, height = 0.1, shape = 'O', size = 3) +
geom_function(fun = sigmoid, color = 'blue', linewidth = 1)+
labs(title = "Modeling a Binary Response with Playsoff teams and Wins") +
scale_y_continuous(breaks = c(0, 1)) +
theme_minimal()
model <- glm(Playoffs ~ W, data = week3_dataset,
family = binomial(link = 'logit'))
model$coefficients
## (Intercept) W
## -34.206104 0.372348
a <- exp(1)
b <- a ^ 0.372348
b
## [1] 1.451138
Each win will increase 45% chance of going to the postseason
model <- lm(Playoffs ~ W,
data = week3_dataset)
plots <- gg_diagnose(model, plot.all = FALSE)
plot_all(plots[c('res_fitted', 'qqplot')], max.per.page = 1)
#I don't need transformation, since the residuals is very consistent.