# Load the necessary library

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(ggthemes)
library(ggrepel)
library(effsize)
library(pwrss)
## 
## Attaching package: 'pwrss'
## 
## The following object is masked from 'package:stats':
## 
##     power.t.test
library(boot)
library(broom)
library(lindia)
library(dplyr)
library(ggplot2)
mpg<- read_delim("C:/Users/Hp/Desktop/Dataset for R submission/player_data.csv", delim = ",",show_col_types = FALSE)
glimpse(mpg)
## Rows: 4,979
## Columns: 9
## $ Player       <chr> "Alaa Abdelnaby", "Zaid Abdul-Aziz", "Kareem Abdul-Jabbar…
## $ From         <dbl> 1991, 1969, 1970, 1991, 1998, 1997, 1977, 1957, 1947, 201…
## $ To           <dbl> 1995, 1978, 1989, 2001, 2003, 2008, 1981, 1957, 1948, 201…
## $ Pos          <chr> "F-C", "C-F", "C", "G", "F", "F", "F", "G", "F", "G-F", "…
## $ Ht           <dbl> 610, 69, 72, 61, 66, 69, 67, 63, 63, 66, 68, 65, 60, 611,…
## $ Wt           <dbl> 240, 235, 225, 162, 223, 225, 220, 180, 195, 200, 225, 18…
## $ Birth.Date   <chr> "June 24 1968", "April 7 1946", "April 16 1947", "March 9…
## $ Colleges     <chr> "Duke", "Iowa State", "UCLA", "LSU", "Michigan San Jose S…
## $ numeric_date <dbl> 610, 69, 72, 61, 66, 69, 67, 63, 63, 66, 68, 65, 60, 611,…
# Create a subset of the dataset for ANOVA
data_anova <- mpg %>%
  select("Pos", `Ht`)

# Rename the columns for clarity
colnames(data_anova) <- c("Pos", "Ht")

# Perform ANOVA
anova_result <- aov(Ht ~ Pos, data = data_anova)
summary(anova_result)
##               Df    Sum Sq Mean Sq F value Pr(>F)    
## Pos            6  31022709 5170452   184.3 <2e-16 ***
## Residuals   4972 139457025   28048                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Create a subset of the dataset for regression
data_regression <- mpg %>%
  select(`Wt`, `Pos`)

# Rename the columns for clarity
colnames(data_regression) <- c("Wt", "Pos")

# Build a linear regression model
lm_model <- lm(Wt ~ Pos, data = data_regression)
summary(lm_model)
## 
## Call:
## lm(formula = Wt ~ Pos, data = data_regression)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -74.172 -11.661  -0.172  11.486 114.956 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 245.0436     0.7671  319.45   <2e-16 ***
## PosC-F      -15.3829     1.3980  -11.00   <2e-16 ***
## PosF        -26.5300     0.8973  -29.57   <2e-16 ***
## PosF-C      -20.2985     1.1612  -17.48   <2e-16 ***
## PosF-G      -41.9794     1.4180  -29.60   <2e-16 ***
## PosG        -56.8713     0.8738  -65.08   <2e-16 ***
## PosG-F      -45.6060     1.1737  -38.86   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 17.61 on 4967 degrees of freedom
##   (5 observations deleted due to missingness)
## Multiple R-squared:  0.542,  Adjusted R-squared:  0.5415 
## F-statistic: 979.8 on 6 and 4967 DF,  p-value: < 2.2e-16
lm_model_combined <- lm(Wt ~ Pos + mpg$Wt, data = data_regression)
summary(lm_model_combined)
## Warning in summary.lm(lm_model_combined): essentially perfect fit: summary may
## be unreliable
## 
## Call:
## lm(formula = Wt ~ Pos + mpg$Wt, data = data_regression)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -1.44e-13 -6.00e-15 -1.00e-15  2.00e-16  1.07e-11 
## 
## Coefficients:
##               Estimate Std. Error    t value Pr(>|t|)    
## (Intercept)  2.114e-12  3.073e-14  6.878e+01   <2e-16 ***
## PosC-F      -1.313e-13  1.221e-14 -1.075e+01   <2e-16 ***
## PosF        -2.288e-13  8.398e-15 -2.724e+01   <2e-16 ***
## PosF-C      -1.754e-13  1.033e-14 -1.699e+01   <2e-16 ***
## PosF-G      -3.629e-13  1.327e-14 -2.734e+01   <2e-16 ***
## PosG        -4.918e-13  1.027e-14 -4.790e+01   <2e-16 ***
## PosG-F      -3.940e-13  1.157e-14 -3.406e+01   <2e-16 ***
## mpg$Wt       1.000e+00  1.225e-16  8.166e+15   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.52e-13 on 4966 degrees of freedom
##   (5 observations deleted due to missingness)
## Multiple R-squared:      1,  Adjusted R-squared:      1 
## F-statistic: 2.08e+31 on 7 and 4966 DF,  p-value: < 2.2e-16
# Scatter plot of age vs. sex
ggplot(data_regression, aes(x = Wt, y = Pos, color = factor(mpg$Ht))) +
  geom_point() +
  labs(title = "Scatter Plot of Weight vs. Position",
       x = "Wt",
       y = "Pos") +
  theme_minimal()
## Warning: Removed 5 rows containing missing values (`geom_point()`).

ggplot(data_regression, aes(x = factor(mpg$Ht), y = Wt, fill = factor(mpg$Ht))) +
  geom_boxplot() +
  labs(title = "Box Plot of Weight by Height",
       x = "Wt",
       y = "Ht") +
  theme_minimal()
## Warning: Removed 5 rows containing non-finite values (`stat_boxplot()`).