Exam II Review

STA602 at Duke University

Baseball at-bats and hits

Data: 2026 season

Up-to-date as of April 5, 2026:

baseball <- read_csv("https://sta602-sp26.github.io/data/baseball_4_5_26.csv")
glimpse(baseball)
Rows: 26
Columns: 3
$ Player <chr> "Yordan Alvarez", "Andy Pages", "Liam Hicks", "Yandy Diaz", "Be…
$ at_bat <dbl> 26, 30, 20, 37, 25, 30, 28, 17, 32, 35, 33, 27, 29, 32, 28, 30,…
$ hit    <dbl> 11, 15, 8, 15, 9, 14, 9, 10, 11, 9, 10, 11, 9, 11, 8, 11, 11, 1…

Data sourced from https://www.espn.com/mlb/stats/player

Exercise

  • Write code to approximate the posterior (1d from exam 2, posted on Canvas).

  • Also, write a function probHit(m, j) that gives the probability of at least 1 hit in \(m\) at-bats for player \(j\), where player \(j\) is identified by the row number in the baseball data frame.