1. Build data frame
age <- c(18, 23, 25, 35, 65, 54,34, 72, 50, 48, 18, 39, 37)
maxHR <- c(200, 189, 189, 185, 170, 175, 185, 168, 170, 175, 205, 190, 178)
df <- data.frame(age, maxHR)
df
##    age maxHR
## 1   18   200
## 2   23   189
## 3   25   189
## 4   35   185
## 5   65   170
## 6   54   175
## 7   34   185
## 8   72   168
## 9   50   170
## 10  48   175
## 11  18   205
## 12  39   190
## 13  37   178
  1. Linear Regression Model
lm_result <- lm(maxHR ~age, data = df)
lm_result
## 
## Call:
## lm(formula = maxHR ~ age, data = df)
## 
## Coefficients:
## (Intercept)          age  
##    207.3326      -0.6107
summary(lm_result)
## 
## Call:
## lm(formula = maxHR ~ age, data = df)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.7994 -3.0660 -0.9594  3.6593  8.6593 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 207.33264    3.71092   55.87 7.45e-15 ***
## age          -0.61066    0.08601   -7.10 1.99e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.133 on 11 degrees of freedom
## Multiple R-squared:  0.8209, Adjusted R-squared:  0.8046 
## F-statistic: 50.41 on 1 and 11 DF,  p-value: 1.992e-05
#This is meaningful model : maxHR = 207.3326 - 0.6107 * age
  1. Visualization
library(ggplot2)
ggplot(df, aes(age, maxHR))+ geom_point() + xlab("AGE") + ylab(" Maximum Heart Rate") + ggtitle("Relation between Maximum Heart Rate and Age") + stat_smooth()
## `geom_smooth()` using method = 'loess'

ggplot(df, aes(age, maxHR))+ geom_point() + xlab("AGE") + ylab(" Maximum Heart Rate") + ggtitle("Relation between Maximum Heart Rate and Age") + stat_smooth(method = lm, level = 0.85)