From 180013dac62888ded28e059f62e03ffb14ee1d74 Mon Sep 17 00:00:00 2001 From: Chris Hamm Date: Wed, 10 Aug 2016 16:56:18 -0400 Subject: [PATCH] Corrected OBP formula in "get.stats" Corrected code in "get.stats" function to reflect correct OBP formula. Added HBP to numerator and denominator, removed H from denominator. --- scripts/Chap8.trajectories.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/Chap8.trajectories.R b/scripts/Chap8.trajectories.R index 0d1d203..5a87263 100644 --- a/scripts/Chap8.trajectories.R +++ b/scripts/Chap8.trajectories.R @@ -33,7 +33,7 @@ get.stats <- function(player.id){ d$Age <- d$yearID - byear d$SLG <- with(d, (H - X2B - X3B - HR + 2 * X2B + 3 * X3B + 4 * HR) / AB) - d$OBP <- with(d, (H + BB) / (H + AB + BB + SF)) + d$OBP <- with(d, (H + BB + HBP) / (AB + BB + SF + HBP)) # HBP are part of OBP formula, H should not be in denominator. d$OPS <- with(d, SLG + OBP) d } @@ -298,4 +298,4 @@ ggplot(dnew, aes(Age, OPS)) + geom_point(size=4) + stat_smooth(method="lm", se=FALSE, size=1.5, formula=y ~ poly(x, 2, raw=TRUE)) + theme_bw() -################################################################ \ No newline at end of file +################################################################