library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
player_data<-read_csv("C:/Users/Hp/Desktop/Dataset for R submission/player_data.csv")
## Rows: 4979 Columns: 9
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): Player, Pos, Birth.Date, Colleges
## dbl (5): From, To, Ht, Wt, numeric_date
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Converting the height coloumn from “Ft’in” to “centimeters”
##Convert heights from feet and inches to centimeters
convert_to_cm <- function(height) {
feet <- as.numeric(substr(height, 1, 1))
inches <- as.numeric(substr(height, 2, 3))
total_inches <- feet * 12 + inches
total_inches * 2.54
}
player_data$Height_cm <- sapply(as.character(player_data$Ht), convert_to_cm)
Summary of my data
# Numeric summaries for Height
numeric_summary_height <- player_data %>%
summarise(
Min_Height = min(Height_cm, na.rm = TRUE),
Max_Height = max(Height_cm, na.rm = TRUE),
Mean_Height = mean(Height_cm, na.rm = TRUE),
Median_Height = median(Height_cm, na.rm = TRUE),
)
# Quantiles for Height using reframe
quantiles_height <- player_data %>%
reframe(
Quantiles_Height = list(quantile(Height_cm, probs = c(0.25, 0.5, 0.75), na.rm = TRUE))
)
# Boxplot for Height
ggplot(player_data, aes(y = Height_cm)) +
geom_boxplot() +
labs(title = "Boxplot of Player Heights", y = "Height (cm)")
# Histogram for Height Distribution
ggplot(player_data, aes(x = Height_cm)) +
geom_histogram(binwidth = 2, fill = "blue", color = "black") +
labs(title = "Histogram of Player Heights", x = "Height (cm)", y = "Frequency")
# Line Plot for Summary Statistics
summary_df <- data.frame(
Statistic = c("Min", "Max", "Mean", "Median"),
Value = c(min(player_data$Height_cm, na.rm = TRUE),
max(player_data$Height_cm, na.rm = TRUE),
mean(player_data$Height_cm, na.rm = TRUE),
median(player_data$Height_cm, na.rm = TRUE))
)
ggplot(summary_df, aes(x = Statistic, y = Value)) +geom_line(group = 1) + geom_point() + labs(title = "Summary Statistics for Player Heights", x = "", y = "Heights(cm)")
Confidence Interval
Interval Range: The lower and upper bounds of the interval are 197.8591 cm and 198.3676 cm, respectively. This suggests that you can be 95% confident that the true average height of NBA players lies between these two values.
Confidence Level: The 95% confidence level means that if you were to take many samples and construct a confidence interval for each sample, about 95% of those intervals would contain the true population mean. In other words, there’s a 5% chance that this interval does not contain the true mean.
Precision of the Estimate: The narrowness of the interval (a range of about 0.5 cm) indicates a high level of precision in the estimate of the mean height. This precision is partly due to the large sample size in your dataset.
Practical Implication: From a practical standpoint, this confidence interval gives you a statistically backed range for the average height of NBA players. It’s a valuable piece of information if you’re presenting this data to stakeholders who are interested in understanding the typical physical attributes of NBA players.
result <- t.test(player_data$Height_cm)
# Print the confidence interval
result$conf.int
## [1] 197.8591 198.3676
## attr(,"conf.level")
## [1] 0.95
Null Hypothesis (H0): The mean height of NBA players is equal to or less than the mean height of the general population. Let’s denote the mean height of the general population as μ.
Alternative Hypothesis (H1): The mean height of NBA players is greater than the mean height of the general population (μ).
Interpreting the results:
t-value (t = 224.51): This is a very high t-value, indicating a significant difference between the average height of NBA players and the general population’s average height (assumed here as 169 cm).
Degrees of freedom (df = 4978): This suggests a large sample size, which adds reliability to the test results.
p-value (< 2.2e-16): This extremely small p-value (practically 0) suggests that the probability of observing a sample mean height as extreme as this, if the null hypothesis were true (i.e., NBA players are not taller than the general population), is virtually nil. It strongly indicates that you should reject the null hypothesis.
Alternative Hypothesis: The alternative hypothesis stated here is that the true mean height of NBA players is greater than 169 cm, which is supported by your test results.
95% Confidence Interval (197.9 to Infinity): This interval suggests that you can be 95% confident that the true average height of NBA players is at least 197.9 cm. The upper bound is infinite, which is a mathematical artifact of the test indicating that the average height is significantly higher than 169 cm.
Sample Estimates (mean of x = 198.1134 cm): This is the mean height of the NBA players in your sample, which is substantially higher than the general population’s average height used for comparison.
# Performing a t-test
t_test_result <- t.test(player_data$Height_cm, mu = 169, alternative = "greater")
# Print the result
print(t_test_result)
##
## One Sample t-test
##
## data: player_data$Height_cm
## t = 224.51, df = 4978, p-value < 2.2e-16
## alternative hypothesis: true mean is greater than 169
## 95 percent confidence interval:
## 197.9 Inf
## sample estimates:
## mean of x
## 198.1134