
dice(HR, BB, HBP, K, IP)
## Defense-Independent Component ERA (dice) function is currently defined as
function (HR, BB, HBP, K, IP)
{
defenseERA <- 3 + ((13 * HR + 3 * BB + 3 * HBP - 2 * K)/IP)
return(defenseERA)
}
## Let's take 2014's MLB MVP, Clayton Kershaw, and find his DICE
## Stats for Clayton Kershaw available on
## http://www.baseball-reference.com/players/k/kershcl01-pitch.shtml
## For 2014, Kershaw allowed 9 HR, 31 BB, 2 HBP, 239 K, and 198.1 IP
## The formula for his DICE using the dice function is below
## Output should be 1.677436
dice(9,31,2,239,198.1)
Run the code above in your browser using DataLab