Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SVD exploration in R

  • Loading branch information...
commit 8541645b9bb8776f60130b364aa1ff9863bb06f4 1 parent b299d89
Philip (flip) Kromer authored
View
1  sports/baseball/baseball_databank/.gitignore
@@ -0,0 +1 @@
+tmp
View
231 sports/baseball/baseball_databank/01_bdb_fixes.sql
@@ -11,6 +11,237 @@ UPDATE `master` SET `bbrefID` = 'gilgahu01' WHERE `lahmanID` = 19417 AND
UPDATE `AwardsPlayers` SET `playerID` = 'braunry02' WHERE `playerID` = 'braunry01' AND `awardID` = 'Silver Slugger' AND yearID = 2012 AND `lgID` = 'NL';
UPDATE `AwardsPlayers` SET `playerID` = 'brechha01' WHERE `playerID` = 'Brecheen' AND `awardID` = 'Baseball Magazine All-Star';
+-- Old players, validated by hand
+UPDATE `master` SET `bbrefID` = 'sulliwi01' WHERE `lahmanID` = 19416 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'mckenpa01' WHERE `lahmanID` = 19415 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'mckenfr01' WHERE `lahmanID` = 19414 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'ruppeja99' WHERE `lahmanID` = 19420 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'defrato99' WHERE `lahmanID` = 19413 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'crossjo01' WHERE `lahmanID` = 19418 AND `bbrefID` IS NULL;
+
+-- Validated by hand, as no direct name match
+UPDATE `master` SET `bbrefID` = 'harriwi10' WHERE `lahmanID` = 19359 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'griffaj01' WHERE `lahmanID` = 19308 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'polloaj01' WHERE `lahmanID` = 19233 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'ramosaj01' WHERE `lahmanID` = 19391 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'rosenbj01' WHERE `lahmanID` = 19300 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'fickch01' WHERE `lahmanID` = 19279 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'mitchdj01' WHERE `lahmanID` = 19248 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'hoovejj01' WHERE `lahmanID` = 19242 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'hoeslj01' WHERE `lahmanID` = 19409 AND `bbrefID` IS NULL;
+
+-- Validated by matching: (first+last name in bdb = common name in WAR; debut was 2012; WAR table year was 2012)
+UPDATE `master` SET `bbrefID` = 'cespeyo01' WHERE `lahmanID` = 19207 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'galvifr01' WHERE `lahmanID` = 19208 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'pastoty01' WHERE `lahmanID` = 19209 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'aokino01' WHERE `lahmanID` = 19210 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'gonzama01' WHERE `lahmanID` = 19211 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'komater01' WHERE `lahmanID` = 19212 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'komater01' WHERE `lahmanID` = 19212 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'vogtst01' WHERE `lahmanID` = 19213 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'cruzrh01' WHERE `lahmanID` = 19214 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'flahery01' WHERE `lahmanID` = 19215 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'haguema01' WHERE `lahmanID` = 19216 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'kawasmu01' WHERE `lahmanID` = 19217 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'luetglu01' WHERE `lahmanID` = 19218 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'nieuwki01' WHERE `lahmanID` = 19219 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'oteroda01' WHERE `lahmanID` = 19220 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'jonesna01' WHERE `lahmanID` = 19221 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'phelpda01' WHERE `lahmanID` = 19222 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'rossro01' WHERE `lahmanID` = 19223 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'castile01' WHERE `lahmanID` = 19224 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'darviyu01' WHERE `lahmanID` = 19225 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'ramirer02' WHERE `lahmanID` = 19226 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'chenwe02' WHERE `lahmanID` = 19227 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'smylydr01' WHERE `lahmanID` = 19228 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'carpeda02' WHERE `lahmanID` = 19229 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'linch01' WHERE `lahmanID` = 19230 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'wielajo01' WHERE `lahmanID` = 19231 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'crawfev01' WHERE `lahmanID` = 19232 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'iwakuhi01' WHERE `lahmanID` = 19234 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'figuepe01' WHERE `lahmanID` = 19235 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'hutchdr01' WHERE `lahmanID` = 19236 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'peralwi01' WHERE `lahmanID` = 19237 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'weberth01' WHERE `lahmanID` = 19238 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'hefneje01' WHERE `lahmanID` = 19239 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'valdejo02' WHERE `lahmanID` = 19240 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'lutzza01' WHERE `lahmanID` = 19241 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'harpebr03' WHERE `lahmanID` = 19243 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'moorety01' WHERE `lahmanID` = 19244 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'putkolu01' WHERE `lahmanID` = 19245 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'corbipa01' WHERE `lahmanID` = 19246 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'jennida01' WHERE `lahmanID` = 19247 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'middlwi01' WHERE `lahmanID` = 19249 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'exposlu01' WHERE `lahmanID` = 19250 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'mikolmi01' WHERE `lahmanID` = 19251 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'faluir01' WHERE `lahmanID` = 19252 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'cardead01' WHERE `lahmanID` = 19253 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'doziebr01' WHERE `lahmanID` = 19254 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'pomerst01' WHERE `lahmanID` = 19255 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'quintjo01' WHERE `lahmanID` = 19256 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'friedch01' WHERE `lahmanID` = 19257 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'vanslsc01' WHERE `lahmanID` = 19258 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'mattike01' WHERE `lahmanID` = 19259 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'averyxa01' WHERE `lahmanID` = 19260 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'costami01' WHERE `lahmanID` = 19261 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'culbech01' WHERE `lahmanID` = 19262 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'gomezma01' WHERE `lahmanID` = 19263 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'leonsa01' WHERE `lahmanID` = 19264 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'diekmja01' WHERE `lahmanID` = 19265 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'herreel01' WHERE `lahmanID` = 19266 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'gomesya01' WHERE `lahmanID` = 19267 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'parkebl01' WHERE `lahmanID` = 19268 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'carsoro01' WHERE `lahmanID` = 19269 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'lallibl01' WHERE `lahmanID` = 19270 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'adamsma01' WHERE `lahmanID` = 19271 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'hernago01' WHERE `lahmanID` = 19272 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'hernago01' WHERE `lahmanID` = 19272 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'solando01' WHERE `lahmanID` = 19273 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'calhoko01' WHERE `lahmanID` = 19274 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'berryqu01' WHERE `lahmanID` = 19275 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'smithwi04' WHERE `lahmanID` = 19276 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'devrico01' WHERE `lahmanID` = 19277 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'diazju02' WHERE `lahmanID` = 19278 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'gonzami03' WHERE `lahmanID` = 19280 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'mercejo03' WHERE `lahmanID` = 19281 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'solanjh01' WHERE `lahmanID` = 19282 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'barnesc01' WHERE `lahmanID` = 19283 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'casteal01' WHERE `lahmanID` = 19284 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'crosbca01' WHERE `lahmanID` = 19285 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'freemsa01' WHERE `lahmanID` = 19286 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'grandya01' WHERE `lahmanID` = 19287 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'pryorst01' WHERE `lahmanID` = 19288 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'simmoan01' WHERE `lahmanID` = 19289 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'ramirel02' WHERE `lahmanID` = 19290 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'doolise01' WHERE `lahmanID` = 19291 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'holadbr01' WHERE `lahmanID` = 19292 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'danksjo02' WHERE `lahmanID` = 19293 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'negrokr01' WHERE `lahmanID` = 19294 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'schepta01' WHERE `lahmanID` = 19295 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'tollesh01' WHERE `lahmanID` = 19296 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'ortegjo01' WHERE `lahmanID` = 19297 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'robincl01' WHERE `lahmanID` = 19298 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'perezhe01' WHERE `lahmanID` = 19299 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'boxbebr01' WHERE `lahmanID` = 19301 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'kellyjo05' WHERE `lahmanID` = 19302 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'grimmju01' WHERE `lahmanID` = 19303 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'keuchda01' WHERE `lahmanID` = 19304 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'thornty01' WHERE `lahmanID` = 19305 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'archech01' WHERE `lahmanID` = 19306 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'norride01' WHERE `lahmanID` = 19307 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'roberty01' WHERE `lahmanID` = 19309 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'vinceni01' WHERE `lahmanID` = 19310 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'cabreed01' WHERE `lahmanID` = 19311 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'perezma02' WHERE `lahmanID` = 19312 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'bauertr01' WHERE `lahmanID` = 19313 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'septile01' WHERE `lahmanID` = 19314 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'warread01' WHERE `lahmanID` = 19315 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'brownba01' WHERE `lahmanID` = 19316 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'downsda02' WHERE `lahmanID` = 19317 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'omogrbr01' WHERE `lahmanID` = 19318 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'dysonsa01' WHERE `lahmanID` = 19319 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'mahonjo01' WHERE `lahmanID` = 19320 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'biancje01' WHERE `lahmanID` = 19321 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'edginjo01' WHERE `lahmanID` = 19322 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'rutlejo01' WHERE `lahmanID` = 19323 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'avilalu01' WHERE `lahmanID` = 19324 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'loupaa01' WHERE `lahmanID` = 19325 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'socolmi01' WHERE `lahmanID` = 19326 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'socolmi01' WHERE `lahmanID` = 19326 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'johnsst02' WHERE `lahmanID` = 19327 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'fifest01' WHERE `lahmanID` = 19328 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'gosean01' WHERE `lahmanID` = 19329 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'verdury01' WHERE `lahmanID` = 19330 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'hernape02' WHERE `lahmanID` = 19331 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'rosentr01' WHERE `lahmanID` = 19332 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'allenco01' WHERE `lahmanID` = 19333 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'wheelry01' WHERE `lahmanID` = 19334 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'belivje01' WHERE `lahmanID` = 19335 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'walljo02' WHERE `lahmanID` = 19336 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'segurje01' WHERE `lahmanID` = 19337 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'segurje01' WHERE `lahmanID` = 19337 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'harvema01' WHERE `lahmanID` = 19338 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'hendeji01' WHERE `lahmanID` = 19339 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'martest01' WHERE `lahmanID` = 19340 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'sierrmo01' WHERE `lahmanID` = 19341 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'cabreal03' WHERE `lahmanID` = 19342 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'oltmi01' WHERE `lahmanID` = 19343 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'rodried04' WHERE `lahmanID` = 19344 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'cappsca01' WHERE `lahmanID` = 19345 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'storemi01' WHERE `lahmanID` = 19346 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'straida01' WHERE `lahmanID` = 19347 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'burnsco01' WHERE `lahmanID` = 19348 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'hechaad01' WHERE `lahmanID` = 19349 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'mcbrima02' WHERE `lahmanID` = 19350 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'jacksbr01' WHERE `lahmanID` = 19351 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'vittejo01' WHERE `lahmanID` = 19352 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'barnebr02' WHERE `lahmanID` = 19353 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'jenkich01' WHERE `lahmanID` = 19354 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'raleybr01' WHERE `lahmanID` = 19355 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'machama01' WHERE `lahmanID` = 19356 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'elmorja01' WHERE `lahmanID` = 19357 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'jacksry02' WHERE `lahmanID` = 19358 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'brantro01' WHERE `lahmanID` = 19360 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'layneto01' WHERE `lahmanID` = 19361 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'geltzst01' WHERE `lahmanID` = 19362 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'redmoto01' WHERE `lahmanID` = 19363 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'mcpheky01' WHERE `lahmanID` = 19364 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'wilsoju10' WHERE `lahmanID` = 19365 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'rusinch01' WHERE `lahmanID` = 19366 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'skaggty01' WHERE `lahmanID` = 19367 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'wernean01' WHERE `lahmanID` = 19368 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'aumonph01' WHERE `lahmanID` = 19369 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'mchugco01' WHERE `lahmanID` = 19370 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'peguefr01' WHERE `lahmanID` = 19371 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'kellyca01' WHERE `lahmanID` = 19372 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'cloydty01' WHERE `lahmanID` = 19373 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'lerudst01' WHERE `lahmanID` = 19374 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'garciav01' WHERE `lahmanID` = 19375 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'heathde01' WHERE `lahmanID` = 19376 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'holtbr01' WHERE `lahmanID` = 19377 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'loughda01' WHERE `lahmanID` = 19378 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'perezeu01' WHERE `lahmanID` = 19379 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'maronni01' WHERE `lahmanID` = 19380 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'nealth01' WHERE `lahmanID` = 19381 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'profaju01' WHERE `lahmanID` = 19382 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'rodrihe04' WHERE `lahmanID` = 19383 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'machije01' WHERE `lahmanID` = 19384 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'phippde01' WHERE `lahmanID` = 19385 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'chapmja02' WHERE `lahmanID` = 19386 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'eatonad02' WHERE `lahmanID` = 19387 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'familje01' WHERE `lahmanID` = 19388 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'garcich02' WHERE `lahmanID` = 19389 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'jimenlu01' WHERE `lahmanID` = 19390 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'gregodi01' WHERE `lahmanID` = 19392 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'koehlto01' WHERE `lahmanID` = 19393 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'millesh01' WHERE `lahmanID` = 19394 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'villape01' WHERE `lahmanID` = 19395 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'grahaty01' WHERE `lahmanID` = 19396 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'triunca01' WHERE `lahmanID` = 19397 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'cingrto01' WHERE `lahmanID` = 19398 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'rodrist02' WHERE `lahmanID` = 19399 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'scahiro01' WHERE `lahmanID` = 19400 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'morribr01' WHERE `lahmanID` = 19401 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'rufda01' WHERE `lahmanID` = 19402 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'herrmch01' WHERE `lahmanID` = 19403 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'solisal01' WHERE `lahmanID` = 19404 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'fontwi01' WHERE `lahmanID` = 19405 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'mesame01' WHERE `lahmanID` = 19406 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'bundydy01' WHERE `lahmanID` = 19407 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'odorija01' WHERE `lahmanID` = 19408 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'tayloan01' WHERE `lahmanID` = 19410 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'ortegra01' WHERE `lahmanID` = 19411 AND `bbrefID` IS NULL;
+UPDATE `master` SET `bbrefID` = 'brummty01' WHERE `lahmanID` = 19412 AND `bbrefID` IS NULL;
+
+-- SELECT (CONCAT(peep.`nameFirst`, ' ', peep.`nameLast`) = bw.`nameCommon`) AS name_match,
+-- peep.`lahmanID`, peep.`playerID`, bw.`bbrefID`, peep.`bbrefID`, bw.`lahmanID`, bw.yearID,
+-- peep.`nameFirst`, peep.`nameLast`, bw.`nameCommon`
+-- FROM people peep
+-- LEFT JOIN `batting_war` bw ON (peep.`playerID` = bw.`bbrefID`)
+-- WHERE (peep.`bbrefID` IS NULL)
+-- ORDER BY name_match ASC
+-- ;
+
-- ===========================================================================
--
-- Restore Indices for 2012 Baseball Databank
View
62 sports/baseball/baseball_databank/02_people_table.sql
@@ -5,41 +5,41 @@
DROP TABLE IF EXISTS `people`;
CREATE TABLE `people` (
- `lahmanID` int(11) DEFAULT NULL,
- `playerID` varchar(10) DEFAULT NULL,
- `bbrefID` varchar(9) DEFAULT NULL,
- `retroID` varchar(9) default NULL,
+ `lahmanID` int(11) DEFAULT NULL,
+ `playerID` varchar(10) CHARACTER SET ascii DEFAULT NULL,
+ `bbrefID` varchar(9) CHARACTER SET ascii DEFAULT NULL,
+ `retroID` varchar(9) CHARACTER SET ascii DEFAULT NULL,
--
- `nameCommon` varchar(100) DEFAULT NULL,
+ `nameCommon` varchar(100) DEFAULT NULL,
--
- `birthYear` int(11) DEFAULT NULL,
- `birthMonth` int(11) DEFAULT NULL,
- `birthDay` int(11) DEFAULT NULL,
- `birthCountry` varchar(50) DEFAULT NULL,
- `birthState` varchar(2) DEFAULT NULL,
- `birthCity` varchar(50) DEFAULT NULL,
- `deathYear` int(11) DEFAULT NULL,
- `deathMonth` int(11) DEFAULT NULL,
- `deathDay` int(11) DEFAULT NULL,
- `deathCountry` varchar(50) DEFAULT NULL,
- `deathState` varchar(2) DEFAULT NULL,
- `deathCity` varchar(50) DEFAULT NULL,
- `nameFirst` varchar(50) DEFAULT NULL,
- `nameLast` varchar(50) DEFAULT NULL,
- `nameNote` varchar(255) DEFAULT NULL,
- `nameGiven` varchar(255) DEFAULT NULL,
- `nameNick` varchar(255) DEFAULT NULL,
+ `birthYear` int(11) DEFAULT NULL,
+ `birthMonth` int(11) DEFAULT NULL,
+ `birthDay` int(11) DEFAULT NULL,
+ `birthCountry` varchar(50) DEFAULT NULL,
+ `birthState` varchar(2) DEFAULT NULL,
+ `birthCity` varchar(50) DEFAULT NULL,
+ `deathYear` int(11) DEFAULT NULL,
+ `deathMonth` int(11) DEFAULT NULL,
+ `deathDay` int(11) DEFAULT NULL,
+ `deathCountry` varchar(50) DEFAULT NULL,
+ `deathState` varchar(2) DEFAULT NULL,
+ `deathCity` varchar(50) DEFAULT NULL,
+ `nameFirst` varchar(50) DEFAULT NULL,
+ `nameLast` varchar(50) DEFAULT NULL,
+ `nameNote` varchar(255) DEFAULT NULL,
+ `nameGiven` varchar(255) DEFAULT NULL,
+ `nameNick` varchar(255) DEFAULT NULL,
--
- `weight` int(11) DEFAULT NULL,
- `height` double DEFAULT NULL,
- `bats` varchar(1) DEFAULT NULL,
- `throws` varchar(1) DEFAULT NULL,
- `debut` varchar(10) DEFAULT NULL,
- `finalGame` varchar(10) DEFAULT NULL,
- `college` varchar(50) DEFAULT NULL,
+ `weight` int(11) DEFAULT NULL,
+ `height` double DEFAULT NULL,
+ `bats` varchar(1) DEFAULT NULL,
+ `throws` varchar(1) DEFAULT NULL,
+ `debut` varchar(10) DEFAULT NULL,
+ `finalGame` varchar(10) DEFAULT NULL,
+ `college` varchar(50) DEFAULT NULL,
--
- `managerID` varchar(10) DEFAULT NULL,
- `hofID` varchar(10) DEFAULT NULL,
+ `managerID` varchar(10) CHARACTER SET ascii DEFAULT NULL,
+ `hofID` varchar(10) CHARACTER SET ascii DEFAULT NULL,
PRIMARY KEY (`lahmanID`),
UNIQUE KEY `bbrefID` (`bbrefID`),
View
16 sports/baseball/baseball_databank/04_career_bat_pit.sql
@@ -7,9 +7,9 @@ DROP TABLE IF EXISTS `career_bat`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `career_bat` (
`lahmanID` int(11) DEFAULT NULL,
- `playerID` varchar(10) DEFAULT NULL,
- `bbrefID` varchar(9) DEFAULT NULL,
- `retroID` varchar(9) default NULL,
+ `playerID` varchar(10) CHARACTER SET ascii DEFAULT NULL,
+ `bbrefID` varchar(9) CHARACTER SET ascii DEFAULT NULL,
+ `retroID` varchar(9) CHARACTER SET ascii DEFAULT NULL,
--
`nameCommon` varchar(100) default NULL,
`nameFirst` varchar(50) default NULL,
@@ -86,7 +86,7 @@ REPLACE INTO career_bat
COUNT(DISTINCT bat.yearID) AS years, MIN(bat.yearID) AS begYear, MAX(bat.yearID) AS endYear,
hof.yearID AS hofYear, votedBy,
-- bat.stint, bat.teamID, bat.lgID,
- SUM(bat.G) AS G, SUM(bat.G_batting) AS G_batting, ast.G_allstar,
+ SUM(bat.G) AS G, SUM(bat.G_batting) AS G_batting, IFNULL(ast.G_allstar,0) AS G_allstar,
SUM(AB) AS AB, SUM(R) AS R, SUM(H) AS H, SUM(2B) AS 2B, SUM(3B) AS 3B, SUM(HR) AS HR, SUM(RBI) AS RBI,
SUM(SB) AS SB, SUM(CS) AS CS, SUM(BB) AS BB, SUM(SO) AS SO, SUM(IBB) AS IBB, SUM(HBP) AS HBP,
SUM(SH) AS SH, SUM(SF) AS SF, SUM(GIDP) AS GIDP
@@ -156,9 +156,9 @@ DROP TABLE IF EXISTS `career_pit`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `career_pit` (
`lahmanID` int(11) DEFAULT NULL,
- `playerID` varchar(10) DEFAULT NULL,
- `bbrefID` varchar(9) DEFAULT NULL,
- `retroID` varchar(9) default NULL,
+ `playerID` varchar(10) CHARACTER SET ascii DEFAULT NULL,
+ `bbrefID` varchar(9) CHARACTER SET ascii DEFAULT NULL,
+ `retroID` varchar(9) CHARACTER SET ascii DEFAULT NULL,
--
`nameCommon` varchar(100) default NULL,
`nameFirst` varchar(50) default NULL,
@@ -237,7 +237,7 @@ REPLACE INTO career_pit
SUM(pit.`GS`) AS `GS`, SUM(pit.`GF`) AS `GF`, SUM(pit.`CG`) AS `CG`,
SUM(pit.`SHO`) AS `SHO`, SUM(pit.`SV`) AS `SV`,
SUM(pit.`IPouts`) AS `IPouts`, SUM(pit.`IPouts`) / 3.0 AS `IP`,
- ast.`G_allstar`,
+ IFNULL(ast.G_allstar,0) AS G_allstar,
SUM(pit.`H`) AS `H`, SUM(pit.`R`) AS `R`, SUM(pit.`ER`) AS `ER`, SUM(pit.`HR`) AS `HR`,
SUM(pit.`BB`) AS `BB`, SUM(pit.`SO`) AS `SO`,
SUM(pit.`IBB`) AS `IBB`, SUM(pit.`WP`) AS `WP`, SUM(pit.`HBP`) AS `HBP`,
View
6 sports/baseball/baseball_databank/05_combined_career_table.sql
@@ -7,9 +7,9 @@ DROP TABLE IF EXISTS `career_all`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `career_all` (
`lahmanID` int(11) DEFAULT NULL,
- `playerID` varchar(10) DEFAULT NULL,
- `bbrefID` varchar(9) DEFAULT NULL,
- `retroID` varchar(9) default NULL,
+ `playerID` varchar(10) CHARACTER SET ascii DEFAULT NULL,
+ `bbrefID` varchar(9) CHARACTER SET ascii DEFAULT NULL,
+ `retroID` varchar(9) CHARACTER SET ascii DEFAULT NULL,
--
`nameCommon` varchar(100) default NULL,
`nameFirst` varchar(50) default NULL,
View
BIN  sports/baseball/baseball_databank/correlation_pairs.pdf
Binary file not shown
View
88 sports/baseball/baseball_databank/fiddle.r
@@ -0,0 +1,88 @@
+library(reshape2)
+library(plyr)
+library("RMySQL", lib.loc="/Library/Frameworks/R.framework/Versions/2.15/Resources/library")
+library(Matrix)
+library(ggplot2)
+# library(GGally)
+options(digits=2)
+
+# utilities
+
+chopmat <- function(mat, thresh=1e-12){ apply(mat, c(1,2), function(val){ if(abs(val) < thresh) 0 else val }) }
+mapstr <- function(strvec, s2){ aaply(strvec, 1, function(str){ paste0(str, s2) }) }
+
+#
+# Load from MySQL
+#
+mysqlc <- dbConnect(MySQL(), user="root", dbname="baseball")
+
+# apologies to you, Cap Anson, Pud Galvin, Old Hoss Radbourn and your contemporaries; we'll only include players whose careers extend into the 1900s
+req <- dbSendQuery(mysqlc, "select
+ playerID, nameCommon,
+ g, begYear, endYear,
+ -- g_batting, g_pitching, g_allstar,
+ pa, ab, r, h, 2b as x2b, 3b as x3b, hr, rbi, sb, bb, so,
+ -- ibb, hbp, sf, gidp,
+ bavg, tb, slg, obp, iso,
+ -- w, l, cg, sv, ipouts, ha, ra, er, hra, bba, soa,
+ -- era, whip, h_9, hr_9, bb_9, so_9, so_bb,
+ war, war_off, war_def, war_pit,
+ birthyear, weight, height, bats
+ FROM career_all WHERE (birthYear IS NOT NULL) AND (bats IS NOT NULL)
+ AND ((isPitcher = 'N') OR (hr > 50))
+ AND (endYear > 1900) AND (PA > 250)
+ AND (g_allstar >= 1)
+ -- AND (hofYear IS NOT NULL)
+ ")
+careers <- fetch(req, n=20000)
+huh <- dbHasCompleted(req) ; dbClearResult(req) ; dbDisconnect(mysqlc)
+
+
+# convert NA to 0
+careers$so[is.na(careers$so)] <- 0
+careers$war_pit[is.na(careers$war_pit)] <- 0
+careers$weight[ is.na(careers$weight)] <- mean(careers$weight[!is.na(careers$weight)])
+careers$height[ is.na(careers$height)] <- mean(careers$height[!is.na(careers$height)])
+
+# 'equivalent seasons' -- 502 plate appearances
+careers$eqseasons = careers$pa / 502
+
+id_cols <- c('playerID', 'nameCommon')
+ratelike_cols <- c( 'h', 'x2b', 'x3b', 'hr', 'sb', 'so', 'bb')
+feature_cols <- c( 'h', 'x2b', 'x3b', 'hr', 'sb', 'so', 'bb', 'war_def', 'weight') # 'slg', 'height')
+# rate_cols <- mapstr( ratelike_cols, 'rt' )
+# scaled_cols <- mapstr( scaled_cols, 'sc' )
+
+pl_rates <- careers[unlist(c(id_cols, 'pa', 'g', feature_cols, 'obp', 'slg', 'iso'))]
+pl_scrts <- careers[unlist(c(id_cols, 'pa', 'g', feature_cols, 'obp', 'slg', 'iso'))]
+
+# # Normalize to seasons using nominal 502 PA / season ; 162 IP (486 IPout) / season
+pl_rates[ratelike_cols] <- careers[ratelike_cols] / careers$eqseasons
+
+# Take Z-scores (`(x-x_avg)/ x_sdev`) of feature columns
+pl_scrts[feature_cols] <- colwise(scale)(pl_rates[feature_cols])
+
+# matricize players
+pmat <- matrix(unlist(pl_scrts[feature_cols]), ncol=length(pl_scrts[feature_cols]), byrow=FALSE)
+
+# svd of players
+psvd <- svd(pmat)
+
+# you can tell how to set kdims by where the eigenvalues (psvd$d) fall off:
+print(c('Significance of dimensions (look for the dropoff):', psvd$d))
+# where to truncate SVD
+kdims <- 6
+#
+psvd_dvec <- psvd$d
+psvd_umat <- psvd$u[,1:kdims]
+psvd_dmat <- Diagonal(length(psvd$d), psvd$d)
+psvd_vmat <- t(psvd$v)[1:kdims,]
+
+reconstituted <- ((psvd_umat %*% psvd_dmat[1:kdims,1:kdims]) %*% psvd_vmat)
+
+ careers[c('q1', 'q2', 'q3', 'q4')] <- pmat %*% psvd$v[,1:4]
+pl_rates[c('q1', 'q2', 'q3', 'q4')] <- pmat %*% psvd$v[,1:4]
+pl_scrts[c('q1', 'q2', 'q3', 'q4')] <- pmat %*% psvd$v[,1:4]
+
+# stats:::prcomp.default
+
View
84 sports/baseball/baseball_databank/load_careers.r
@@ -0,0 +1,84 @@
+library(reshape2)
+library(plyr)
+library("RMySQL", lib.loc="/Library/Frameworks/R.framework/Versions/2.15/Resources/library")
+library(Matrix)
+library(ggplot2)
+# library(GGally)
+
+mysqlc <- dbConnect(MySQL(), user="root", dbname="baseball")
+
+req <- dbSendQuery(mysqlc, "select
+ playerID, nameCommon,
+ g,
+ -- g_batting, g_pitching, g_allstar,
+ pa, ab, r, h, 2b as x2b, 3b as x3b, hr, rbi, sb, bb, so,
+ -- ibb, hbp, sf, gidp,
+ bavg, tb, slg, obp, iso,
+ -- w, l, cg, sv, ipouts, ha, ra, er, hra, bba, soa,
+ -- era, whip, h_9, hr_9, bb_9, so_9, so_bb,
+ war, war_off, war_def, war_pit,
+ birthyear, weight, height, bats
+ FROM career_all WHERE (PA > 250) -- AND (g_allstar >= 1)
+ ")
+careers <- fetch(req, n=20000)
+huh <- dbHasCompleted(req) ; dbClearResult(req) ; dbDisconnect(mysqlc)
+
+# convert NA to 0
+careers[is.na(careers)] <- 0
+
+# 'equivalent seasons' -- 502 plate appearances
+careers$eqseasons = careers$pa / 502
+
+mapstr <- function(strvec, s2){ aaply(strvec, 1, function(str){ paste(str, s2, sep='') }) }
+id_cols <- c('playerID', 'nameCommon')
+ratelike_cols <- c( 'h', 'x2b', 'x3b', 'hr', 'sb', 'so')
+feature_cols <- c('g', 'h', 'x2b', 'x3b', 'hr', 'sb', 'so', 'slg', 'weight', 'height')
+# rate_cols <- mapstr( ratelike_cols, 'rt' )
+# scaled_cols <- mapstr( scaled_cols, 'sc' )
+
+pl_rates <- careers[unlist(c(id_cols, 'pa', 'eqseasons', feature_cols))]
+pl_scrts <- careers[unlist(c(id_cols, 'pa', 'eqseasons', feature_cols))]
+
+pl_rates[ratelike_cols] <- careers[ratelike_cols] / careers$eqseasons
+pl_scrts[feature_cols] <- colwise(scale)(pl_rates[feature_cols])
+
+#
+# # matricize players
+# pmat <- matrix(unlist(players), ncol=length(players), byrow=FALSE)
+#
+# # Normalize to seasons using nominal 502 PA / season ; 162 IP (486 IPout) / season
+# # pmean <- colMeans(players)
+# # psdev <- sapply(players, sd)
+#
+# z_players <- t((t(players) - pmean) / psdev)
+#
+# # or could use apply t(apply( t(apply(players,1,'-',pmean) ), 1,'/',psdev))
+# # double check: ((z_players[1,] * psdev) + pmean) - players[1,]
+# # round(t((t(z_players) * psdev) + pmean) - players, 12)
+#
+# # svd of players
+# psvd <- svd(z_players)
+#
+# # where to truncate SVD
+# kdims <- 3
+#
+# psvd_dvec <- psvd$d
+# psvd_umat <- psvd$u[,1:kdims]
+# psvd_dmat <- Diagonal(length(psvd$d), psvd$d)
+# psvd_vmat <- psvd$v[1:kdims,]
+# sgr <- (psvd_umat %*% psvd_dmat[1:kdims,1:kdims] %*% psvd_vmat)
+#
+# vsigns <- psvd_vmat ; vsigns[psvd_vmat > 0] <- 1 ; vsigns[psvd_vmat < 0] <- -1 ;
+# usigns <- psvd_umat ; usigns[psvd_umat > 0] <- 1 ; usigns[psvd_umat < 0] <- -1 ;
+#
+# vs_colorder <- do.call(order, lapply(1:NROW(vsigns), function(i) vsigns[i, ]))
+# us_colorder <- do.call(order, lapply(1:NROW(usigns), function(i) usigns[i, ]))
+#
+# # # you can tell how many dims to use by where psvd_dvec falls off:
+# # psvd_dvec[1:12]
+#
+# # first 5 components of first three players (I think?)
+# coords35 <- pmat[1:3,] %*% t(psvd$v[1:5,])
+#
+# p_p_dot <- pmat %*% t(pmat)
+
View
37 sports/baseball/baseball_databank/plotting.r
@@ -0,0 +1,37 @@
+
+pairs.annot <- function(data, ...) {
+
+ panel.lm <- function (x, y, col = par("col"), bg = NA, pch = par("pch"),
+ cex = 1, col.lm = "red", lwd=par("lwd"), ...) {
+ points(x, y, pch = pch, col = col, bg = bg, cex = cex)
+ ok <- is.finite(x) & is.finite(y)
+ if (any(ok))
+ abline(lm(y~x,subset=ok), col = col.lm, ...)
+ }
+
+ panel.sse<-
+ function(y, x, digits=2)
+ {
+ usr <- par("usr"); on.exit(par(usr))
+ par(usr = c(0, 1, 0, 1))
+
+ model <- summary(lm(y~x))
+ r2<- model$r.squared
+ r<-sqrt(r2)*sign(model$coef[2,1])
+ # p<- model$coef[2,4]
+
+ txt <- round(r, digits)
+ txt <- bquote(r == .(txt))
+ text(0.5, 0.7, txt, cex=1.5)
+
+ txt <- round(r2, digits)
+ txt <- bquote(r^2 == .(txt))
+ text(0.5, 0.5, txt, cex=1.5)
+
+ # txt <- round(p, digits)
+ # txt <- bquote(P == .(txt))
+ # text(0.5, 0.3, txt, cex=1.5)
+ }
+
+ pairs(data,lower.panel=panel.sse,upper.panel=panel.lm)
+}
View
15 sports/baseball/baseball_reference/03_war_tables.sql
@@ -6,9 +6,9 @@
DROP TABLE IF EXISTS `batting_war`;
CREATE TABLE batting_war (
`lahmanID` int(11) DEFAULT NULL,
- `playerID` varchar(10) DEFAULT NULL,
- `bbrefID` varchar(9) DEFAULT NULL,
- `retroID` varchar(9) default NULL,
+ `playerID` varchar(10) CHARACTER SET ascii DEFAULT NULL,
+ `bbrefID` varchar(9) CHARACTER SET ascii DEFAULT NULL,
+ `retroID` varchar(9) CHARACTER SET ascii DEFAULT NULL,
--
`nameCommon` varchar(100),
--
@@ -59,7 +59,8 @@ CREATE TABLE batting_war (
KEY `bbrefID` (`bbrefID`),
KEY `lahmanID` (`lahmanID`),
KEY `playerID` (`playerID`),
- KEY `retroID` (`retroID`,`bbrefID`)
+ KEY `retroID` (`retroID`,`bbrefID`),
+ KEY `season` (`yearID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
;
@@ -97,9 +98,9 @@ ALTER TABLE `batting_war` ENABLE KEYS;
DROP TABLE IF EXISTS `pitching_war`;
CREATE TABLE pitching_war (
`lahmanID` int(11) DEFAULT NULL,
- `playerID` varchar(10) DEFAULT NULL,
- `bbrefID` varchar(9) DEFAULT NULL,
- `retroID` varchar(9) default NULL,
+ `playerID` varchar(10) CHARACTER SET ascii DEFAULT NULL,
+ `bbrefID` varchar(9) CHARACTER SET ascii DEFAULT NULL,
+ `retroID` varchar(9) CHARACTER SET ascii DEFAULT NULL,
--
`nameCommon` varchar(100),
--
View
8 sports/baseball/baseball_reference/99_checks.sql
@@ -0,0 +1,8 @@
+SELECT bw.`lahmanID`, bw.`nameCommon`, bw.`playerID`, bw.`yearID`, bw.lgID, bat.`lgID`, bw.PA, bw.G, bat.G, (100 + bat.G - bw.G) AS diffG, bw.`isPitcher`
+ FROM `batting_war` bw
+ LEFT JOIN Batting bat ON (bw.`playerID` = bat.`playerID`) AND (bw.`yearID` = bat.`yearID`) AND (bw.`stintID` = bat.`stint`)
+ WHERE (bw.PA > 0) AND (bat.G != bw.G)
+ ORDER BY yearID DESC
+ ;
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.