Project 2

source: Trevor Raab

Introduction: Today I will be focusing on long distance runners and measuring their emotional intelligence levels. There variables that are covered their sex, age, pb of 100 km, pb of their elevation, their avg km per week, measurement of emotional intelligence and situational management. I will primary be covering how each of these variables affect one another. I chose this dataset because personal health and fitness is meaningful to me and I wanted to dive deeper of how it affects others.

First we important each library necessary

library(plotly)
Loading required package: ggplot2

Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':

    last_plot
The following object is masked from 'package:stats':

    filter
The following object is masked from 'package:graphics':

    layout
library(ggplot2)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

Set our working directories

setwd("C:/Users/jfgam/Downloads/Data 110")
ultrarunning <- read.csv("ultrarunning.csv")

We then clean up our dataset to prepare for upcoming graphs and regression data

ultrarunning_clean <- ultrarunning %>%
  mutate(
    sex = factor(sex,
                 levels = c(1, 2),
                 labels = c("Male", "Female")),
    pb_surface = factor(pb_surface,
                        levels = c(1, 2, 3, 4),
                        labels = c("Trail", "Track", "Road", "Mixed"))
  )

Then rename the values as needed and remove the variables that will not be used

ultrarunning_model_data <- ultrarunning_clean %>%
  select(age, avg_km, pb_elev, teique_sf, pb100k_dec) %>%
  rename(
    Age = age,
    Weekly_Distance = avg_km,
    Elevation = pb_elev,
    Emotional_Intelligence = teique_sf,
    Completion_Time = pb100k_dec
  ) %>%
  filter(
    !is.na(Age),
    !is.na(Weekly_Distance),
    !is.na(Elevation),
    !is.na(Emotional_Intelligence),
    !is.na(Completion_Time)
  )


summary(ultrarunning_model_data)
      Age        Weekly_Distance    Elevation    Emotional_Intelligence
 Min.   :18.00   Min.   :  5.00   Min.   :   0   Min.   :2.970         
 1st Qu.:31.00   1st Qu.: 60.00   1st Qu.: 781   1st Qu.:4.650         
 Median :38.00   Median : 72.00   Median :2200   Median :5.200         
 Mean   :39.37   Mean   : 74.08   Mean   :2554   Mean   :5.128         
 3rd Qu.:45.50   3rd Qu.: 88.00   3rd Qu.:3800   3rd Qu.:5.630         
 Max.   :87.00   Max.   :160.00   Max.   :9449   Max.   :7.000         
 Completion_Time
 Min.   : 6.50  
 1st Qu.:12.21  
 Median :14.36  
 Mean   :14.68  
 3rd Qu.:16.71  
 Max.   :23.50  

Construct a multiple linear regression models

ultra_model <- lm( Completion_Time ~ Age + Weekly_Distance +  Elevation + Emotional_Intelligence,
  data = ultrarunning_model_data
)


summary(ultra_model)

Call:
lm(formula = Completion_Time ~ Age + Weekly_Distance + Elevation + 
    Emotional_Intelligence, data = ultrarunning_model_data)

Residuals:
    Min      1Q  Median      3Q     Max 
-6.4692 -2.1856 -0.3081  1.8319  8.6131 

Coefficients:
                         Estimate Std. Error t value Pr(>|t|)    
(Intercept)            13.9037379  1.9773437   7.032 3.58e-11 ***
Age                    -0.0218346  0.0211344  -1.033 0.302856    
Weekly_Distance        -0.0489921  0.0091954  -5.328 2.79e-07 ***
Elevation               0.0004000  0.0001097   3.646 0.000344 ***
Emotional_Intelligence  0.8272605  0.3189216   2.594 0.010228 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3.118 on 190 degrees of freedom
Multiple R-squared:  0.2008,    Adjusted R-squared:  0.184 
F-statistic: 11.94 on 4 and 190 DF,  p-value: 1.133e-08

What this means for the regression lines: The overall model is statistically signifcant. Looking at variables individually, elevation and emotional intelligence have an assocation with longer completion times. Something else you can take from this is since weekly running distance has a negative coefficient, you can conclude that runners with more km per week have shorter completion times.

# Create final scatterplot
final_plot <- ggplot(
  ultrarunning_model_data,
  aes(
    x = Weekly_Distance,
    y = Completion_Time,
    color = Emotional_Intelligence,
    text = paste(
      "Age:", Age,
      "<br>Weekly Distance:", Weekly_Distance,
      "<br>Elevation:", Elevation,
      "<br>Emotional Intelligence:", Emotional_Intelligence,
      "<br>Completion Time:", Completion_Time
    )
  )
) +
  geom_point(size = 3, alpha = 0.8) +
  geom_smooth(method = "lm", color = "black",
              se = TRUE) +
  scale_color_viridis_c(option = "plasma") +
  labs(
    title = "Weekly Running Distance and 100km pb Relationship",
    subtitle = "Examining completion time in relation to training distance and emotional intelligence",
    x = "Average Weekly Running Distance (Kilometers)",
    y = "100 km Completion Time (Hours)",
    color = "Emotional Intelligence",
    caption = "Source: Ultra-Running and Emotional Intelligence dataset"
  ) +
  theme_minimal()

# Make scatterplot interactive
ggplotly(final_plot, tooltip = "text")
`geom_smooth()` using formula = 'y ~ x'

Conclusion: This interactive plot gives us all the information we need regarding runners and how their habits, personal bests, age/sex, and weekly running distances affect their completion time and emotional intelligence. From this graph, a negative relationship with weekly running distance and completion time. This means that runners who run more each week have a tendency to finish faster. Emotional intelligence can also be seen to correlate with longer running times.