Giter Club home page Giter Club logo

mlbstats's Introduction

mlbstats: Major League Baseball Player Statistics Calculator

CRAN_Status_Badge Downloads Documentation

Why should I use mlbstats?

This package is a player-level baseball statistics calculator. Similar to using sum(2,2) to perform the operation 2 + 2, mlbstats allows for simple computation of a host of player-level metrics based on raw inputs. Common metrics from major league baseball (MLB) include batting, pitching, fielding, baserunning, and player-summary statistics. The goal of this package, then, is to provide an easy-to-use calculator to efficiently calculate player metrics based on raw, easily obtainable data. For some other metrics such as WAR, UZR, PWA, etc., see https://www.baseball-reference.com/ or Bill James' sabermetrics guides.

Take a look at the package, along with many other excellent related packages, in the Sports Analytics CRAN Task View.

How do I use mlbstats?

From the simplest calculations (e.g., batting average = number of hits / at bats) to complicated ones (e.g., a pitcher's component earned run average, calculated as, 9 * ((h + bb + hbp) * (0.89 * (1.255 * (h - hr) + 4 * hr) + 0.56 * (bb + hbp - ibb)) / (bfp * ip)) - 0.56)), unique functions in mlbstats take unique values from player-level data, and return the desired metric.

Installation

install.packages("mlbstats")
library(mlbstats)

Implementation

Jose Altuve's (Houston Astros Silver Slugger) 2017 Regular Season OBP (on-base percentage)
obp(
  h = 204, # hits
  bb = 58, # walks
  hbp = 9, # hits by pitch
  ab = 590, # at bats
  sf = 4 # sacrifice flys
) 

[1] 0.4099849

Corroborate with the official MLB statistics, recording Altuve's 2017 regular season OBP as 0.410.

Chris Sale (Boston Red Sox Pitcher) 2017 Regular Season PFR (power finesse ratio)
pfr(
  k = 308, # strikeouts
  bb = 43, # walks
  ip = 214.1 # innings pitched
)

[1] 1.639421

How do I get mlbstats?

Load the package (0.1.0) from CRAN. If you have any questions, find any bugs requiring fixing, or find metrics I left out, either open an issue ticket or feel free to reach out directly. If you use the package for any published work, I would love to know!

mlbstats's People

Contributors

pdwaggoner avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.