Boris Davidovic - Homework 1

2)/3)

athleteData <- read.table("./AthleteData.csv", header=TRUE, sep=",", dec=".")
head(athleteData)
##   S.NO              Name Nationality Current.Rank Previous.Year.Rank  Sport
## 1    1        Mike Tyson         USA            1                n/a boxing
## 2    2    Buster Douglas         USA            2                n/a boxing
## 3    3 Sugar Ray Leonard         USA            3                n/a boxing
## 4    4      Ayrton Senna      Brazil            4                n/a     f1
## 5    5       Alain Prost      France            5                n/a     f1
## 6    6     Jack Nicklaus         USA            6                n/a   golf
##   Year Earnings.USD
## 1 1990         28.6
## 2 1990         26.0
## 3 1990         13.0
## 4 1990         10.0
## 5 1990          9.0
## 6 1990          8.6
tail(athleteData)
##     S.NO          Name Nationality Current.Rank Previous.Year.Rank      Sport
## 296  296  LeBron James         USA            5                  8 basketball
## 297  297 Stephen Curry         USA            6                  9 basketball
## 298  298  Kevin Durant         USA            7                 10 basketball
## 299  299   Tiger Woods         USA            8                 11       golf
## 300  300  Kirk Cousins         USA            9               >100        NFL
## 301  301  Carson Wentz         USA           10               >100        NFL
##     Year Earnings.USD
## 296 2020         88.2
## 297 2020         74.4
## 298 2020         63.9
## 299 2020         62.3
## 300 2020         60.5
## 301 2020         59.1

The data surrounds the highest paid athletes in the world in a given year from 1990-2020. There are a total of 301 observations. Each year has 10 records which indicate the top 10 highest paid athletes of that year, where they ranked in the previous year, what country they are from, what sport they played and what country they are from. Here is the variables the data described in more detail:

S.NO -> int value, indication of what row of data it is

Nationality -> chr value, what country the athlete is from

Current.Rank -> int value, what is their position in terms of pay of that specific year (i.e. 1 means they are the highest paid athlete of the year corresponding to the year value in the row)

Previous.Year.Rank -> chr value, where did they rank in terms of highest paid athletes in the previous year. The data consists of a mix of values: if they were in the top 10 the previous year, they have a clear indication of where they were ranked. If they were ranked, but outside the top 10, the data indicates approximately where they rank (i.e. >30, >40, etc.). Some of the data also has “not ranked” values which shows they were not ranked in the previous year. “n/a” is also a value used for values corresponding to 1990 as that is the first year of records

Sport -> chr value, what sport did the athlete play

Year -> int value, what year was the record in

Earnings.USD -> dbl value, how much the athlete made in that year in USD

The source of the data is from kaggle.com (https://www.kaggle.com/datasets/gaurav126/forbes-richest-athletes-1990-2021). The dataset on kaggle.com is extracted from topendsports.com

summary(athleteData[, -1])
##      Name           Nationality         Current.Rank    Previous.Year.Rank
##  Length:301         Length:301         Min.   : 1.000   Length:301        
##  Class :character   Class :character   1st Qu.: 3.000   Class :character  
##  Mode  :character   Mode  :character   Median : 5.000   Mode  :character  
##                                        Mean   : 5.449                     
##                                        3rd Qu.: 8.000                     
##                                        Max.   :10.000                     
##     Sport                Year       Earnings.USD   
##  Length:301         Min.   :1990   Min.   :  8.10  
##  Class :character   1st Qu.:1997   1st Qu.: 24.00  
##  Mode  :character   Median :2005   Median : 39.00  
##                     Mean   :2005   Mean   : 45.52  
##                     3rd Qu.:2013   3rd Qu.: 59.40  
##                     Max.   :2020   Max.   :300.00

Name -> categorical variable so cannot take descriptive statistics of it, insights would be better seen through graphs

Nationality -> also a categorical variable so cannot take descriptive statistics of it, insights would be better seen through graphs

Current.Rank -> this is technically a categorical variable as it is tied to rank, but the outputted descriptive statistics makes sense - the min is 1 and max is 10 which demonstrates it is a rank between 1 and 10

Previous.Year.Rank -> also a categorical variable so cannot take descriptive statistics of it, insights would be better seen through graphs

Sport -> also a categorical variable so cannot take descriptive statistics of it, insights would be better seen through graphs

Year -> also technically a categorical variable as it is tied to the year, but the outputted descriptive statistics makes sense - the min is 1990, max is 2020 and mean is 2005 which indicates the data is from 1990 to 2020

Earnings.USD -> the median of the earnings is 39 which means that more than half of these athletes make over $39 Million. The max is 300 which means there could be some large outliers in the data. Combined with the median being 39, it is likely the data is skewed to the right

library(ggplot2)
ggplot(athleteData, aes(y = Earnings.USD, x = Nationality)) + geom_boxplot() +  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(x = "Nationality", y = "Earnings (USD)", title = "Earnings by Nationality")

This graph shows earnings by nationality. We can see that the highest earning country is the United States - there is also a lot of outliers with the US data, indicating that most of the highest earning athletes are from the US.

Many countries such as Austria, Serbia, Spain and more have only one black line in the plot, indicating the country has one athlete who has been in the top 10 of athletes in terms of earnings at any point in the data set. Some countries such as Argentina, Brazil and Philippines have the black line closer to the lower part of the box (the 25th percentile) which shows the earnings for that country is right skewed (a higher number of athletes earn more than the median). Countries such as Portugal, Switzerland and the UK have the black line closer to the top part of the box (75th percentile) indicating that the earnings for that country are left skewed (a higher number of athletes earn less than the median).

library(ggplot2)
ggplot(athleteData, aes(y = Earnings.USD, x = Sport)) + geom_boxplot() +  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(x = "Nationality", y = "Earnings (USD)", title = "Earnings by Sport")

This graph shows earnings by sport. From this graph we can see that the highest earning sport is boxing and has outliers that are far above some other data points. From boxing, we can see the next highest earning sports are soccer, tennis and golf with tennis and golf being fairly similar in terms of earnings.

Most of the sports are slightly or fairly skewed towards the right in terms of earnings as many of the boxplots have the black line (median) towards the 25th percentile. This indicates that most sports have a few individuals that earn quite more than their counterparts which ultimately skews the data towards the right.

library(car)
## Loading required package: carData
scatterplot(y = athleteData$Earnings.USD, 
            x = athleteData$Year, 
            ylab = "Earnings in Millions $USD", 
            xlab = "Year", 
            smooth = FALSE)

This is a scatter plot that shows the relationship between the year and earnings. We can see from this data that there is a fairly strong relationship that as time has progressed, the earnings of top athletes has also increased. But there are some outliers in the data such as in 2015 and and 2018. In 2015, there a fight between Floyd Mayweather and Manny Pacquiao where they earned incredible sums of money, creating the outlier. It also looks like Mayweather had a fight in 2018 where he earned just under 300M USD.

Also, the box plot on the y-axis shows a right skewed distribution which is consistent with the above graphs where most sports by earnings are right skewed. This can also be shown with more points above the line of best fit than below. Overall, this indicates that there are certain individual athletes that make much more than the rest which skews the data.

ggplot(athleteData, aes(x = Nationality)) +
  geom_bar(fill = "skyblue", color = "black") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(x = "Nationality", y = "Frequency", title = "Frequency Plot by Nationality")

This is a graph showing the frequency of nationalities in this data set. From this graph we can see that USA makes up a significantly large portion of the athletes. This can likely be attributed to the USA having the Big 4 North American sports leagues (NBA, NFL, NHL, MLB). Most of the other countries have a small number of athletes or only an individual athlete in this data set.