Exam 2 Review.

Consider the following vectors representing the number of field goals made and attempted by a basketball player in five games:

Field Goals Made: c(18,7,16,9,10) Field Goals Attempted: c(25,12,28,14,23)

Calculate the filed goal percentage for each game and select the correct average field goal percentage for the five games.

# Define the vectors representing field goals made and attempted
Field_Goals_Made <- c(18,7,16,9,10) 
Field_Goals_Attempted <- c(25,12,28,14,23)

#Calculate the field goal percentage for each game
Field_Goal_Percentage <- (Field_Goals_Made / Field_Goals_Attempted) * 100 
Field_Goal_Percentage
## [1] 72.00000 58.33333 57.14286 64.28571 43.47826
# Calculate the average field goal percentage 
Average_Field_Goal_Percentage <- mean(Field_Goal_Percentage) 

# Print the average field goal percentage 
Average_Field_Goal_Percentage 
## [1] 59.04803

Consider the following vectors representing the number of three-pointers made and attempted by a basketball player in five games:

Three-Pointers Made: c(7,5,9,8,7) Three-Pointers Attempted: c(13,10,18,14,16)

Calculate the three-point shooting percentage for each game and select the correct average three-point shooting percentage for the five games

# Define the vectors representing three-pointers made and attempted
Three_Pointers_Made <- c(7,5,9,8,7)
Three_Pointers_Attempted <- c(13,10,18,14,16) 

# Calculate the three-point shooting percentage for each game 
Three_Point_Shooting_Percentage <- (Three_Pointers_Made / Three_Pointers_Attempted) *100
Three_Point_Shooting_Percentage
## [1] 53.84615 50.00000 50.00000 57.14286 43.75000
# Calculate the average three-point shooting percentage
Average_Three_Point_Shooting_Percentage <- mean(Three_Point_Shooting_Percentage) 

# Print the average shooting percentage 
Average_Three_Point_Shooting_Percentage
## [1] 50.9478

Consider the following dataset representing the perfomance of baseball plaers in a season. It includes the following variables: PlayerID, Hits, At-Bats, Home Runs (HR), walks (BB) , and strikeouts(so)

Player ID Hits At-Bats HR BB SO 1 180 450 25 60 80 2 150 430 22 50 75 3 140 420 18 58 60 4 134 500 30 40 90 5 130 480 20 55 70

Compute the on-base percentage (OBP) for each player and select the player with the highest OBP

  1. Player 1 b)Player 2 c) Player 3 d) Player 4 e)Player 5

To calculate OBP, you can use the following formula:

OBP = (Hits + Walks) / (At-Bats + Walks)

# Create a data frame with the player statistics
data <- data.frame(
 PlayerID = 1:5,
 Hits = c(180,150,140,134,130),
 At_Bats = c(450,430,420,500,480),
 HR = c(25,22,18,30,20),
 BB = c(60,50,58,40,55),
 SO = c(80,75,60,90,70)
)
# Calculate the on-base percentage (OBP) for each player
data$OBP <- (data$Hits + data$BB) / (data$At_Bats + data$BB)
data$OBP
## [1] 0.4705882 0.4166667 0.4142259 0.3222222 0.3457944
# Find the player with the highest OBP 
player_with_highest_OBP <- data$PlayerID[which.max(data$OBP)]

# Print the player with the highest OBP
player_with_highest_OBP
## [1] 1

As we can see Player 1 has the highest OBP.

If a team scored 730 runs in a season and allowed 590 runs, what is their Runs Difference?

Runs_Difference <- 730 - 590
Runs_Difference
## [1] 140

In basketball, the plus-minus (+/-) of a player is a statistical metric that measures the point dofferential when a specific player is on the court. IF a player’s team scores 59 points while they are on the court and allows 46 points to the opponents, what is the player’s plus-minus (+/-) for that specific time on the court?

plus_minus <- 59-46
plus_minus
## [1] 13

If a quaterback completes 18 out of 30 pass attempts for 270 yards with 2 touchdowns and 1 interception, what would be their Quaterback Rating (QBR) for that specific game?

What is the completion percentage for the quaterback in the game? a) 50% b) 60% c) 70% d) 80%

Completed_Attempts <- 18
Total_Attempts <- 30
Completion_percentage <- (Completed_Attempts/Total_Attempts) 
Completion_percentage
## [1] 0.6

As we can see the option b is our right answer.

If a quaterback completes 21 out of 30 pass attempts for 240 yards with 3 touchdowns and 1 interception.

How many yards per attempt did the quaterback achieve in the game?

  1. 6.0
  2. 7.0
  3. 9.0
  4. 8.0
Total_Yards <- 270
Yards_per_Attempt <- Total_Yards / Total_Attempts
Yards_per_Attempt 
## [1] 9

Moneyball analytics in baseball revolutionized the way teams evaluate players and make decisions.

# Rely on advanced statistical analysis to identify undervalued player attributes

In Moneyball analytics, what is the purpose of using advanced metrics like on-base percentage (OBP) and slugging percentage (SLG)?

# To assess a player's overall offensive contribution accurately