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
week3_dataset <- read.csv("baseball.csv",header = TRUE)
In this case, I think the tenth index is very low. Since the 50 percentile of this column is 711. That means that the random variable that is picked mostly under 50%
df_sample_rs <- list()
num_iterations <- 10
for (i in 1:num_iterations) {
sample_mean <- week3_dataset %>%
sample_frac(0.5, replace = TRUE) %>%
pluck("RS") %>%
mean(na.rm = TRUE)
df_sample_rs[[i]] <- sample_mean
}
df_sample_rs
## [[1]]
## [1] 719.5763
##
## [[2]]
## [1] 723.1055
##
## [[3]]
## [1] 719.336
##
## [[4]]
## [1] 716.3458
##
## [[5]]
## [1] 716.2549
##
## [[6]]
## [1] 720.1981
##
## [[7]]
## [1] 722.3003
##
## [[8]]
## [1] 721.3864
##
## [[9]]
## [1] 714.9578
##
## [[10]]
## [1] 708.6315
I think every random sample is very close to the mean of this column. I don’t think their is any anomaly in it.
df_sample_OOBP <- list()
for (i in 1:num_iterations) {
sample_mean <- week3_dataset %>%
sample_frac(0.5, replace = TRUE) %>%
pluck("OOBP") %>%
mean(na.rm = TRUE)
df_sample_OOBP[[i]] <- sample_mean
}
df_sample_OOBP
## [[1]]
## [1] 0.3307489
##
## [[2]]
## [1] 0.3340443
##
## [[3]]
## [1] 0.3328515
##
## [[4]]
## [1] 0.3312212
##
## [[5]]
## [1] 0.3330188
##
## [[6]]
## [1] 0.3327309
##
## [[7]]
## [1] 0.3321549
##
## [[8]]
## [1] 0.3333316
##
## [[9]]
## [1] 0.332724
##
## [[10]]
## [1] 0.3317095
I think their is not a single season that has very low W and the mean of this column is also 80. So their is not a anomaly.
df_sample_w <- list()
for (i in 1:num_iterations) {
sample_mean <- week3_dataset %>%
sample_frac(0.5, replace = TRUE) %>%
pluck("W") %>%
mean(na.rm = TRUE)
df_sample_w[[i]] <- sample_mean
}
df_sample_w
## [[1]]
## [1] 81.30195
##
## [[2]]
## [1] 81.31981
##
## [[3]]
## [1] 81.125
##
## [[4]]
## [1] 81.44805
##
## [[5]]
## [1] 81.26948
##
## [[6]]
## [1] 80.3263
##
## [[7]]
## [1] 80.39935
##
## [[8]]
## [1] 81.40097
##
## [[9]]
## [1] 81.61364
##
## [[10]]
## [1] 81.5
I think this one is very awkward. A lot of the random sample is below the mean of this column. But, it is not very significant, so I won’t count is as anomaly.
df_sample_OBP <- list()
for (i in 1:num_iterations) {
sample_mean <- week3_dataset %>%
sample_frac(0.5, replace = TRUE) %>%
pluck("OBP") %>%
mean(na.rm = TRUE)
df_sample_OBP[[i]] <- sample_mean
}
df_sample_OBP
## [[1]]
## [1] 0.3269399
##
## [[2]]
## [1] 0.3268036
##
## [[3]]
## [1] 0.3257565
##
## [[4]]
## [1] 0.3257776
##
## [[5]]
## [1] 0.3258295
##
## [[6]]
## [1] 0.3261558
##
## [[7]]
## [1] 0.3265016
##
## [[8]]
## [1] 0.3258523
##
## [[9]]
## [1] 0.3264529
##
## [[10]]
## [1] 0.3255162
I think every random sample is very close to the mean of this column. I don’t think their is any anomaly in it.
df_sample_SLG <- list()
for (i in 1:num_iterations) {
sample_mean <- week3_dataset %>%
sample_frac(0.5, replace = TRUE) %>%
pluck("SLG") %>%
mean(na.rm = TRUE)
df_sample_SLG[[i]] <- sample_mean
}
df_sample_SLG
## [[1]]
## [1] 0.3975097
##
## [[2]]
## [1] 0.397237
##
## [[3]]
## [1] 0.3968458
##
## [[4]]
## [1] 0.3959334
##
## [[5]]
## [1] 0.3970244
##
## [[6]]
## [1] 0.3968295
##
## [[7]]
## [1] 0.3962159
##
## [[8]]
## [1] 0.3960081
##
## [[9]]
## [1] 0.3965244
##
## [[10]]
## [1] 0.3981218
I think every random sample is basically the same as the mean of this column. I don’t think their is any anomaly in it.
df_sample_BA <- list()
for (i in 1:num_iterations) {
sample_mean <- week3_dataset %>%
sample_frac(0.5, replace = TRUE) %>%
pluck("BA") %>%
mean(na.rm = TRUE)
df_sample_BA[[i]] <- sample_mean
}
df_sample_BA
## [[1]]
## [1] 0.2590487
##
## [[2]]
## [1] 0.2597305
##
## [[3]]
## [1] 0.2595617
##
## [[4]]
## [1] 0.2585341
##
## [[5]]
## [1] 0.2597646
##
## [[6]]
## [1] 0.2598718
##
## [[7]]
## [1] 0.2583263
##
## [[8]]
## [1] 0.2587873
##
## [[9]]
## [1] 0.2598718
##
## [[10]]
## [1] 0.2597419