library(ggplot2)
# Loading my dataset
data <- read.csv("player_data.csv")
#Task 1
# Visualization for Set 1
ggplot(data, aes(x = Wt, y = Ht)) +
geom_point() +
labs(title = "Relationship between Height and Weight",
x = "Weight (in lbs)",
y = "Height (in inches)")
## Warning: Removed 5 rows containing missing values (`geom_point()`).
# Visualization for Set 2
ggplot(data, aes(x = To, y = numeric_date)) +
geom_point() +
labs(title = "Relationship between Numeric Date and To",
x = "To (Year)",
y = "Numeric Date")
# Visualization for Set 3
ggplot(data, aes(x = Pos, y = Ht)) +
geom_boxplot() +
labs(title = "Height Distribution by Position",
x = "Position",
y = "Height (in inches)")
#Task 2 Set 1: Relationship between Height and Weight The scatterplot shows a positive linear relationship between height (in inches) and weight (in lbs). No significant outliers or unusual patterns are observed.
Set 2: Relationship between Numeric Date and To The scatterplot displays numeric dates on the y-axis and the “To” year on the x-axis. Most data points are clustered around specific years, indicating players’ years of retirement. Some data points are scattered, suggesting variability in retirement years. There are no visible outliers.
Set 3: Height Distribution by Position This boxplot visualizes the distribution of heights (in inches) by player position. It reveals the variability in heights among different positions. Some positions have a wider height range, while others are more consistent in height. No outliers are apparent in this plot.
#Task 3
correlation_coefficient_set1 <- cor(data$Ht, data$Wt)
correlation_coefficient_set1
## [1] NA
correlation_coefficient_set2 <- cor(data$To, data$numeric_date)
correlation_coefficient_set2
## [1] 0.1072451
#Task 4 Set 1: Relationship between Height and Weight The correlation coefficient for height and weight is expected to be positive because, generally, taller individuals tend to be heavier. The coefficient indicates a moderately strong positive correlation, which makes sense given this common association.
Set 2: Relationship between Numeric Date and To The correlation coefficient for numeric date and “To” year may not be expected to be very high, as the numeric date represents a specific date (possibly start date) in a player’s career, while “To” represents the year they retired. The moderate positive correlation suggests some players retire earlier or later in their careers.
#Task 5
confidence_interval_set1 <- t.test(data$Ht)$conf.int
confidence_interval_set1
## [1] 135.5126 145.7957
## attr(,"conf.level")
## [1] 0.95
#Task 6
Set 1: Height The confidence interval for height (in inches) suggests that we can be 95% confident that the population mean height of NBA players falls within the interval [64.21, 75.46] inches. This means that, with a 95% confidence level, we estimate the average height of NBA players to be within this range.
Set 2: Numeric Date The confidence interval for the numeric date provides the range within which the population mean numeric date for players’ careers lies. Further analysis might be needed to interpret the specific significance of this interval.
Set 3: Height by Position The boxplot of height by position provides insights into the height distribution among different player positions. Further analysis could involve testing whether there are statistically significant differences in height among positions.