Question 1

This is the sixth season of outfielder Juan Soto in the majors. If during the first five seasons he received 79,108,41,145 and 135 walks, how many does he need on this season for his overall number of walks per season to be at least 100.

Soto_Walks<-c(79,108,41,145,135)
wanted_walks<-100
number_seasons<-6
#Needed walks on season 6
Walks_6<-number_seasons*wanted_walks-sum(Soto_Walks)
Walks_6
## [1] 92

Juan Soto could very likely exceed that amount of walks in this upcoming season. With the high power offense that the Mets could field this offseason with players such as Pete Alonso and Francisco Lindor, we can potentially see pitchers avoiding throwing the ball to Juan Soto with RISP

Case Scenario 2

n_1<-10
n_2<-4
y_1<-72000
y_2<-84000
#Mean Salary Overall
salary_ave<-(n_1*y_1+n_2*y_2)/(n_1+n_2)
salary_ave
## [1] 75428.57
bp_1<-7
fp_1<-9
w_1<-102000
w_2<-91000
#Mean Salary Overall
wsalary_ave<-(bp_1*w_1+fp_1*w_2)/(bp_1+fp_1)
wsalary_ave
## [1] 95812.5
getwd()
## [1] "/cloud/project"
contract_length<-read.csv("allcontracts.csv",header = TRUE,sep=",")
contract_years<-contract_length$years
contract_mean<-mean(contract_years)
contract_mean<-round(contract_mean,digits = 1)
contract_mean
## [1] 3.5
#median
contracts_median<-median(contract_years)
contracts_median
## [1] 3
#Find the number of observations
contracts_n<-length(contract_years)
#Find the standard deviation
contracts_sd<-sd(contract_years)
contract_w1sd<-sum((contract_years-contract_mean)/contracts_sd<1)/contracts_n
#Percentage of observations within one sd from the mean
contract_w1sd
## [1] 0.8416834
#Percentage of observations within one sd from the mean
contract_w1sd
## [1] 0.8416834
#Difference from empirical
contract_w1sd-0.68
## [1] 0.1616834
#within 2 sd
contracts_w2sd<-sum((contract_years-contract_mean)/contracts_sd<2)/contracts_n
contracts_w2sd
## [1] 1
#Difference from empirical
contracts_w2sd-0.95
## [1] 0.05
# Within 3sd
contracts_w3sd<-sum((contract_years-contract_mean)/contracts_sd<3)/contracts_n
contracts_w3sd
## [1] 1
#Difference from empirical
contracts_w3sd-0.9973
## [1] 0.0027

Case Scenario 3

Create a Histogram

hist(contract_years, 
     xlab = "Years Left in Contract", 
     col = "green", 
     border = "red", 
     xlim = c(0, 8), 
     ylim = c(0, 250), 
     breaks = 3)

There are more players with 2-4 years left in their contracts. It would be interesting to see how many are avoiding arbitration.

boxplot(contract_years,main="Years Left in Contract",ylab="Years")

boxplot(contract_years, 
        main = "Years Left in Contract", 
        ylab = "Years", 
        col = "lightblue", 
        border = "blue", 
        horizontal = FALSE)

Question 3

doubles<-read.table("doubles_hit.csv",header = TRUE,sep = ",")
doubles_hit<-doubles$doubles_hit
doubles_hit_mean<-mean(doubles_hit)
doubles_hit_mean
## [1] 23.55
doubles_hit_median<-median(doubles_hit)
doubles_hit_median
## [1] 23.5
doubles_hit_n<-length(doubles_hit)
doubles_hit_sd<-sd(doubles_hit)
doubles_hit_w1sd<-sum((doubles_hit-doubles_hit_mean)/doubles_hit_sd<1)/doubles_hit_n
doubles_hit_w1sd
## [1] 0.79
#Difference from empirical
doubles_hit_w1sd-0.68
## [1] 0.11
doubles_hit_w2sd<-sum((doubles_hit-doubles_hit_mean)/doubles_hit_sd<2)/doubles_hit_n
doubles_hit_w2sd
## [1] 1
#Difference from empirical 
doubles_hit_w2sd-0.95
## [1] 0.05
doubles_hit_w3sd<-sum((doubles_hit-doubles_hit_mean)/doubles_hit_sd<3)/doubles_hit_n
doubles_hit_w3sd
## [1] 1
#Difference from empirical
doubles_hit_w3sd-0.9973
## [1] 0.0027

Histogram

hist(doubles_hit,xlab = "Number of Doubles", col = "blue",border = "lightblue",
     xlim = c(0,60),ylim = c(0,30),breaks = 7)

In todays modern game of baseball, RBI’s are valued at an all time. A lot more players swing for the fences searching for the homerun rather tha attempting to make a contact hit.

boxplot(doubles_hit,main="Boxplot of Doubles Hit by Player",ylab="Doubles",
        col = "blue",border = "lightblue")