#Necessary libraries
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
library(ggplot2)
library(pwr)
# Loading my dataset
data <- read.csv("player_data.csv")
data$Ht <- as.numeric(gsub("-", ".", data$Ht))
#Converting the "Wt" column to numeric
data$Wt <- as.numeric(data$Wt)
Alpha Level (α): A smaller alpha value (0.01) reduces the risk of Type I errors but increases the risk of Type II errors (failing to reject a false null hypothesis). Conversely, a larger alpha level (e.g., 0.10) increases the risk of Type I errors but reduces the risk of Type II errors. This is why I chose a value of 0.05 since it is the most commonly used value and is netiher too small nor too big.
To keep the process simple, I am using default power level and minimum effect size values given in the library If the p-value from the correlation test is less than 0.05 (our alpha level), we will reject the null hypothesis, suggesting that there is a significant correlation between height and weight.
#Setting alpha level for hypothesis testing
alpha <- 0.05
Hypothesis 1: Testing for correlation using Pearson Correlation test
Null Hypothesis (H0):There is no significant correlation between a player’s height (Ht) and weight (Wt).
Alternative Hypothesis (Ha): There is a significant correlation between a player’s height (Ht) and weight (Wt).
## Performing a Pearson correlation test
correlation_test_result <- cor.test(data$Ht, data$Wt, method = "pearson")
correlation_test_result
##
## Pearson's product-moment correlation
##
## data: data$Ht and data$Wt
## t = 22.188, df = 4972, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.2746621 0.3252410
## sample estimates:
## cor
## 0.3001625
## Visualization 1: Scatterplot to illustrate the correlation between height and weight
ggplot(data, aes(x = Ht, y = Wt)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "blue") +
labs(title = "Scatterplot of Height vs. Weight", x = "Height (in inches)", y = "Weight (in lbs)")
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 5 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 5 rows containing missing values (`geom_point()`).
Hypothesis 2: Testing for Mean Difference
Null Hypothesis (H0): The average weight (Wt) of players who attended college is equal to the average weight of players who did not attend college.
Alternative Hypothesis (Ha): The average weight (Wt) of players who attended college is not equal to the average weight of players who did not attend college.
## Subsetting data into two groups: College attendees and non-attendees
college_attendees <- data %>% filter(Colleges != "")
non_college_attendees <- data %>% filter(Colleges == "")
## Perform a t-test to compare the average height between the two groups
t_test_result <- t.test(college_attendees$Wt, non_college_attendees$Wt, alternative = "two.sided")
t_test_result
##
## Welch Two Sample t-test
##
## data: college_attendees$Wt and non_college_attendees$Wt
## t = -9.1533, df = 385.75, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -18.92985 -12.23553
## sample estimates:
## mean of x mean of y
## 208.2635 223.8462
## Visualization 2: Boxplot to illustrate weight differences between college attendees and non-attendees
ggplot(data, aes(x = factor(Colleges), y = Wt)) +
geom_boxplot() +
labs(title = "Boxplot of Weight by College Attendance Status", x = "College Attendance", y = "Weight (lbs)")
## Warning: Removed 5 rows containing non-finite values (`stat_boxplot()`).
Fishers Style test for significance to test equality of variances
If the p-value is less than the chosen significance level (alpha), we should reject the null hypothesis (H0). This would indicate that there is evidence to suggest that the variances of weight in the two groups are not equal, implying that the assumption of equal variances for a t-test may not hold.
If the p-value is greater than alpha, we’ll fail to reject the null hypothesis. This would suggest that there is no significant evidence to suggest a difference in variances between the two groups, and the assumption of equal variances for a t-test can be reasonably assumed.
The hypotheses for Levene’s test:
Null Hypothesis (H0): The variances of the weight (Wt) in the college attendee group and non-college attendee group are equal.
Alternative Hypothesis (Ha): The variances of the weight (Wt) in the two groups are not equal.
#Levene's test to test for equality of variances
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
levene_test_result <- leveneTest(Wt ~ Colleges, data = data)
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
levene_test_result
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 792 1.3666 1.682e-09 ***
## 4181
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The output from my Levene’s Test for Homogeneity of Variance displays the following results:
The test statistic (F value), which is approximately 1.3666.
The p-value associated with the test statistic is approximately 1.682e-09, which is a very small p-value.
Since the p-value (approximately 1.682e-09) is much smaller than the typical significance level of 0.05, we reject the null hypothesis (H0). This result suggests that there is strong evidence to indicate that the variances of weight in the “College” and “Non-College” groups are not equal.