knitr::opts_chunk$set(echo = TRUE)

June madness is a package that quantifies the effects of climate on major league baseball. This package requires that you have a tibble formatted like the example Yankees_Weather data included in this package. To get data for your city of interest, you need data on the high, humidity, and if there was thunder for each day during the baseball season. To see the data formatting View(Yankees_Weather) in the console.

Load packages

library(tidyverse)
library(testthat)
library(junemadness)
data("Yankees_Weather")

Calculating the average humidity for months during the baseball season

SeasonHumd(Yankees_Weather)

Calculating the average high temperature for months during the baseball season

SeasonTemp(Yankees_Weather)

Calculating the increases in homerun probability from increased humidity

yankee_h = SeasonHumd(Yankees_Weather)
homeruns(yankee_h)

Calculating the probability of there being a homerun during a game given different weather inputs

#calculates the probability based off the fitted model of a game having at least one homerun when the temperature is 87 degrees fahrenheit and a humidity of 99%
homerun_probability_computation(homerun = Yankees_Weather$Homerun, humid = Yankees_Weather$humidity, temp = Yankees_Weather$high, temperature = 87, humidity = 99)

Calculating association between weather and ticket revenue for baseball games

compute_revenue_regression(revenue = Yankees_Weather$Revenue, storm = Yankees_Weather$thunder, humid = Yankees_Weather$humidity, temp = Yankees_Weather$high)

Calculating the mean temperature across years for cities that have baseball teams

#creating sample multidimensional array data
three_d_array <- array(
  sample(60:97,96,replace=T),
  dim = c(12,4, 2),
  dimnames = list(
    c("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"),
    c("2010", "2011", "2012", "2013"),
    c("Boston", "New York City")))

#computing the average yearly temperature for the different cities
yearly_temperature_computation(three_d_array)


gorchels/junemadness documentation built on June 16, 2019, 3:13 a.m.