https://rpubs.com/ScottWeiner19/1009344

Purpose

The objective of this document is to assess the correlation between the age of an mlb player and their 90 foot sprint time, which is the distance between bases.

#assessing relationship between baseball player age and 90 ft sprint (aka split) time

Speedofplayers <- read.csv(file ='running_splits_R.csv')
head(Speedofplayers)
##   last_name first_name player_id name_abbrev team_id position_name age bat_side
## 1    Abrams         CJ    682928         WSH     120            SS  21        L
## 2     Abreu       José    547989         CWS     145            1B  35        R
## 3 Acuña Jr.     Ronald    660670         ATL     144            RF  24        R
## 4    Adames      Willy    642715         MIL     158            SS  26        R
## 5     Adams      Riley    656180         WSH     120             C  26        R
## 6     Adell         Jo    666176         LAA     108            LF  23        R
##   seconds_since_hit_000 seconds_since_hit_005 seconds_since_hit_010
## 1                     0                  0.53                  0.82
## 2                     0                  0.57                  0.92
## 3                     0                  0.54                  0.85
## 4                     0                  0.56                  0.88
## 5                     0                  0.56                  0.89
## 6                     0                  0.55                  0.85
##   seconds_since_hit_015 seconds_since_hit_020 seconds_since_hit_025
## 1                  1.07                  1.30                  1.51
## 2                  1.20                  1.45                  1.68
## 3                  1.10                  1.33                  1.54
## 4                  1.14                  1.39                  1.61
## 5                  1.16                  1.41                  1.64
## 6                  1.11                  1.34                  1.55
##   seconds_since_hit_030 seconds_since_hit_035 seconds_since_hit_040
## 1                  1.71                  1.90                  2.09
## 2                  1.90                  2.11                  2.32
## 3                  1.74                  1.93                  2.12
## 4                  1.82                  2.02                  2.21
## 5                  1.86                  2.07                  2.27
## 6                  1.75                  1.94                  2.13
##   seconds_since_hit_045 seconds_since_hit_050 seconds_since_hit_055
## 1                  2.27                  2.44                  2.62
## 2                  2.52                  2.71                  2.90
## 3                  2.30                  2.48                  2.65
## 4                  2.40                  2.59                  2.77
## 5                  2.47                  2.66                  2.86
## 6                  2.31                  2.48                  2.65
##   seconds_since_hit_060 seconds_since_hit_065 seconds_since_hit_070
## 1                  2.79                  2.95                  3.12
## 2                  3.09                  3.27                  3.46
## 3                  2.82                  2.99                  3.16
## 4                  2.94                  3.12                  3.29
## 5                  3.04                  3.23                  3.42
## 6                  2.82                  2.99                  3.15
##   seconds_since_hit_075 seconds_since_hit_080 seconds_since_hit_085
## 1                  3.29                  3.45                  3.63
## 2                  3.64                  3.83                  4.02
## 3                  3.32                  3.49                  3.65
## 4                  3.47                  3.64                  3.81
## 5                  3.60                  3.79                  3.97
## 6                  3.31                  3.47                  3.64
##   seconds_since_hit_090
## 1                  3.82
## 2                  4.22
## 3                  3.82
## 4                  3.99
## 5                  4.17
## 6                  3.81
Age <- (Speedofplayers$age)

##Split_Time is time in seconds to sprint 90 ft. 
Split_Time <- (Speedofplayers$seconds_since_hit_090)

x <- lm(Split_Time ~ Age)
summary(x)
## 
## Call:
## lm(formula = Split_Time ~ Age)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.34066 -0.11242 -0.02036  0.09920  0.62404 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 3.573538   0.049397   72.34   <2e-16 ***
## Age         0.017649   0.001756   10.05   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1551 on 572 degrees of freedom
## Multiple R-squared:   0.15,  Adjusted R-squared:  0.1485 
## F-statistic:   101 on 1 and 572 DF,  p-value: < 2.2e-16
resx <-residuals(x)


cf <-coef(x)
int <- cf[1]
sl <- cf[2]
int
## (Intercept) 
##    3.573538
sl
##        Age 
## 0.01764916

Correlation and Residual Plots

You can also embed plots, for example:

plot(Split_Time ~ Age, main="Age vs 90 Foot Split Time",
ylab="Split Time (seconds)",
xlab= "Age         slope = 0.0176 seconds   R^2 = 0.155"
)
abline(x,lwd=6)

plot(resx, main= "Residual Plot")
abline(0,0)