Chapter 9 Simulation

Learning objectives:

  • Simulate a half-inning
  • Simulate many half-innings
  • Simulate a baseball season
  • Simulate many baseball seasons
library("abdwr3edata")
library("ggtext")
library("gt")
library("Lahman")
library("tidyverse")

#https://beanumber.github.io/sds192/lab-import.html#Data_in_other_formats
load("data/retro2016.rda") #has retro2016 data frame
Session Info
sessionInfo()
## R version 4.5.1 (2025-06-13)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.2 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
## 
## locale:
##  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
##  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
##  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
## [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
## 
## time zone: UTC
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] ggtext_0.1.2      broom_1.0.9       gt_1.0.0          ggrepel_0.9.6    
##  [5] abdwr3edata_0.0.3 lubridate_1.9.4   forcats_1.0.0     stringr_1.5.1    
##  [9] dplyr_1.1.4       purrr_1.1.0       readr_2.1.5       tidyr_1.3.1      
## [13] tibble_3.3.0      ggplot2_3.5.2     tidyverse_2.0.0   Lahman_12.0-0    
## 
## loaded via a namespace (and not attached):
##  [1] gtable_0.3.6       xfun_0.52          bslib_0.9.0        lattice_0.22-7    
##  [5] tzdb_0.5.0         vctrs_0.6.5        tools_4.5.1        generics_0.1.4    
##  [9] pkgconfig_2.0.3    Matrix_1.7-3       RColorBrewer_1.1-3 lifecycle_1.0.4   
## [13] compiler_4.5.1     farver_2.1.2       httpuv_1.6.16      htmltools_0.5.8.1 
## [17] sass_0.4.10        yaml_2.3.10        later_1.4.2        pillar_1.11.0     
## [21] jquerylib_0.1.4    cachem_1.1.0       nlme_3.1-168       mime_0.13         
## [25] tidyselect_1.2.1   digest_0.6.37      stringi_1.8.7      bookdown_0.43     
## [29] labeling_0.4.3     splines_4.5.1      rprojroot_2.1.0    fastmap_1.2.0     
## [33] grid_4.5.1         here_1.0.1         cli_3.6.5          magrittr_2.0.3    
## [37] utf8_1.2.6         withr_3.0.2        scales_1.4.0       promises_1.3.3    
## [41] backports_1.5.0    timechange_0.3.0   rmarkdown_2.29     hms_1.1.3         
## [45] shiny_1.11.1       evaluate_1.0.4     knitr_1.50         viridisLite_0.4.2 
## [49] mgcv_1.9-3         rlang_1.1.6        gridtext_0.1.5     Rcpp_1.1.0        
## [53] xtable_1.8-4       glue_1.8.0         xml2_1.3.8         rstudioapi_0.17.1 
## [57] jsonlite_2.0.0     R6_2.6.1