0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

STATCAST

 STATCAST(スタットキャスト) は 2015年に、MLB の全球場で導入されているレーダーシステムと高精細光学カメラという構成で始まった、ボールと人の動きを追跡記録するシステムです。
 2020年からは「Hawk-Eye(ホークアイ)」と呼ばれるシステムに置き換わり、追跡能力が向上、さらに選手の生体力学的追跡や打者のスイングスピードや軌道を追跡するバットトラッキングが加わりました。
 2025年1月現在、で、以下のデータをトラッキングできます。

  • ピッチング(速度、スピンレートとスピン方向、ピッチの動き)
  • ヒット(打球初速、発射角度、飛距離)
  • ランニング(スプリント速度、ベース間移動に掛かった時間)
  • フィールド(腕の強さ(肩の強さ)、キャッチ確率、キャッチャーポップタイム(捕手のミットにボールが収まってから、セカンドベースカバーに入った選手のグラブに要した時間)

 以上の測定値及び、測定値から有用な数値に組み合わせた(メトリック)指標データを誰でも自由に利用できます。

Baseball Savant

 STATCAST のデータは、BaseballSavant.MLB.com で、CSV 形式でダウンロードすることが出来ます。

 検索によるデータ生成 [Statcast Search]や、(https://baseballsavant.mlb.com/statcast_search)
スクリーンショット 2025-01-24 15.43.30.png

 フィルタによるデータ選択 Leaderboards や、あらかじめフィルタリングされたデータから必要なカラムを選ぶ Statistics が用意されており、好きな方法でデータダウンロードが可能になっています。

R で使う STATCAST - tidyverse + baseballr

 R では、baseballr パッケージが利用できます。tidyverse パッケージをインストールしていない場合は、予めインストールします。

install.packages("tidyverse")
also installing the dependencies ‘fastmap’, ‘colorspace’, ‘sys’, ‘bit’, ‘ps’, ‘base64enc’, ‘sass’, ‘digest’, ‘cachem’, ‘farver’, ‘labeling’, ‘munsell’, ‘RColorBrewer’, ‘viridisLite’, ‘rappdirs’, ‘rematch’, ‘askpass’, ‘bit64’, ‘prettyunits’, ‘processx’, ‘evaluate’, ‘highr’, ‘xfun’, ‘yaml’, ‘bslib’, ‘fontawesome’, ‘htmltools’, ‘jquerylib’, ‘tinytex’, ‘backports’, ‘generics’, ‘glue’, ‘lifecycle’, ‘memoise’, ‘blob’, ‘DBI’, ‘R6’, ‘tidyselect’, ‘vctrs’, ‘withr’, ‘data.table’, ‘gtable’, ‘isoband’, ‘scales’, ‘gargle’, ‘uuid’, ‘cellranger’, ‘curl’, ‘ids’, ‘rematch2’, ‘cpp11’, ‘pkgconfig’, ‘mime’, ‘openssl’, ‘timechange’, ‘utf8’, ‘systemfonts’, ‘textshaping’, ‘clipr’, ‘crayon’, ‘vroom’, ‘tzdb’, ‘progress’, ‘callr’, ‘fs’, ‘knitr’, ‘rmarkdown’, ‘selectr’, ‘stringi’, ‘fansi’, ‘broom’, ‘conflicted’, ‘cli’, ‘dbplyr’, ‘dplyr’, ‘dtplyr’, ‘forcats’, ‘ggplot2’, ‘googledrive’, ‘googlesheets4’, ‘haven’, ‘hms’, ‘httr’, ‘jsonlite’, ‘lubridate’, ‘magrittr’, ‘modelr’, ‘pillar’, ‘purrr’, ‘ragg’, ‘readr’, ‘readxl’, ‘reprex’, ‘rlang’, ‘rstudioapi’, ‘rvest’, ‘stringr’, ‘tibble’, ‘tidyr’, ‘xml2’

 tiververse を利用するには、次のようにしますが、コンフリクトしているというメッセージが出てきます。これは、名前が同じ関数が、R に含まれているためですが、tidyverse 導入後は、tidyverse に含まれる dplyr パッケージのものが使用されるという意味です。
R のものを使用したい場合は、下のようにパッケージを使用して記述しろという意味です。

library(tidyverse)
── Attaching core tidyverse packages ─────────────────────────────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ───────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package to force all conflicts to become errors

 tidyverse の準備ができたら、baseballr パッケージをインストールします。

install.packages("baseballr")

library(baseballr)

baseballr には様々な関数が利用できますが、STATCAST を対象にする場合は、以下の関数を利用します。

  • statcast_search()
  • statcast_search_batters()
  • statcast_search_pitchers()
  • statcast_leaderboards()

この関数群では、Baseball Savant の プレイヤーID が必要になります。この ID は Lahman、BASEBALL-REFERENCE、FanGraphs のものとは違うので注意しましょう。以下、一例です。

Baseball Savant playerid
選手名 ID
大谷翔平 660271
アーロン・ジャッジ 592450
今永昇太 684007
クリス・セール 519242

例えば、大谷翔平選手の 2024年のデータを取得する場合、以下のように取得してきましたが、2025年1月26日現在、baseballr の既知の問題で、現在、動作しません。

ohtani_shohei <- statcast_search(start_date = "2024-01-01", end_date = "2024-12-31", playerid = 660271)

 とはいえ、baseballr は、STATCAST 以外にも、FanGraphs、BASEBALL-REFERENCE の関数も含まれているので、次に紹介する Lahman パッケージとともにインストールしておきましょう。

Lahman

 STATCAST とは直接関係ありませんが、この流れで、続いて、セイバーメトリクスの基本的なデータとして利用されている Lahman パッケージを、インストールしておきましょう。

install.packages("Lahman")

 利用する際は、

library(Lahman)

 R でセイバーメトリクスに取り組む場合、基本は、tidyverse(これは、セイバーメトリクスに限らず、データサイエンス全般で使用します)、そして、データソースに応じて、baseballr(STATCAST、FanGraphs、BASEBALL-REFERENCE), Lahman(1871年以降の MLB の選手、監督、チームのデータ)を利用するようにします。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?