1) Compare Two Means

1.1) Create two sample sets

Create two samples from the gcookbook::heightweight data set , each of size 15, but one Female only, and the other Male only.

# Create initial data set from gcookbook
pop <-gcookbook::heightweight

# Set seed and sample number 'N'
set.seed(1515)
N <- 15

# Female sample of 15 students
samp_fem <- pop %>%
  filter(sex == "f")
samp_fem <- (samp_fem) %>%
  sample_n(N, replace=FALSE)
  
# Male sample of 15 students
samp_mal <- pop %>%
  filter(sex == "m")
samp_mal <- samp_mal %>%
  sample_n(N, replace=FALSE)

1.2) Run a two sample t-test

For the t-test parameters, I left the default arguments:
alternative = two.sided because we are performing a two sided t-test
mu = 0 because we are assuming the mean of the two samples are the same
var.equal = FALSE to approximate the degrees of freedom
conf.level = 0.95 because the sample size of each data frame is less than 30

# Two sample t-test for weight of both male and female samples

#The null hypothesis is that there is no statistically significant difference in weight between males and females. If p-value is greater than confidence interval, then we accept the null. 

#The alternative hypothesis is that on average, men's weight and females weights are different

ttest <- t.test(samp_fem$weightLb, samp_mal$weightLb, mu = 0, var.equal = FALSE)
ttest
## 
##  Welch Two Sample t-test
## 
## data:  samp_fem$weightLb and samp_mal$weightLb
## t = 0.65267, df = 27.755, p-value = 0.5193
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -8.131051 15.731051
## sample estimates:
## mean of x mean of y 
##  97.43333  93.63333
#t should be greater than x to be able to reject the null hypothesis
#t = .65267 > 

#p value should be less than the confidence interval 
#p value = .5193 > than .05 based on a 95% confidence interval
#we cannot reject the null hypothesis, which means there is not evidence of a statistically significant different between male and female weight 

# Assign variable for error bars in plot below

se <- ttest$stderr

The sample sets and plot are good examples of how random samples might be contrary to our general assumption of the data. I assumed that the sample sets would show that males have a higher mean weight than females, but this isn’t the case. The mean weight of females in this sample set is 97.43 and is 93.63 for males. I also thought that the error bars looked too big, but it makes sense with such a small sample size resulting in a standard error of 5.82.

1.3) Combine samples and plot

# Combine sample data frames

samp_combined <- bind_rows(samp_fem, samp_mal)

# Find the mean of each sex and add to new data frame

samp_means <- samp_combined %>%
  group_by(sex) %>%
  mutate(mean = mean(weightLb))

# Plot data
jitter <- ggplot(samp_means, aes(x=sex, y=weightLb, color=factor(sex))) +
  geom_jitter(
    width = 0.1, 
    size = 2, 
    alpha = .8) +
  geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=0.5) +
  theme_bw() +
  theme(
    legend.position = "none") +
  scale_x_discrete(labels = c("f" = "Female", "m" = "Male")) +
  labs(
    x = "Gender",
    y = "Age (years)",
    title = "Comparing female and male sample sets",
    subtitle = paste0("Sample size of ", N, " female students and ", N, " male students")
  )
jitter

# dont forget labels
#jitter

My sample sets and plot are good examples of how random samples might be contrary to your general assumption of the data. I assumed that the sample sets would show that males have a higher mean weight than females, but this isn’t the case. The mean weight of females in this sample set is 97.43 and is 93.63 for males. I also thought that the error bars looked too big, but it makes sense with such a small sample size resulting in a standard error of 5.82.

2) Plot by Category

2.1) Perform a 2-means (M vs. F Height) t-test for grades 5-10

As suggested, I created a grade column in my original pop data frame. I then created 10 new data frames, filtered by sex and grade, and ran a t-test for all grades. I used the default arguments for all t-tests, meaning the confidence level is 95% and the alpha is 0.05.

# Add grade variable to pop data frame

ttest$estimate
## mean of x mean of y 
##  97.43333  93.63333
ttest$stderr
## [1] 5.822234
# pop$grade <- code here

pop$grade <- as.numeric(round(pop$ageYear)-6)

pop$grade
##   [1]  6  7  7  7 10  8  9  6  7  6  6  9  7  6  6  6 10  6  6  9  6  6  8  9  9
##  [26]  8  9  9 12  6  8  8  6  6 10 10  8  9  9  9  8  8  8  8  6  9  6  6  6  9
##  [51]  9 10  6  6  6  6  7  8  9  6  9  9  6  6  7  7  6  7  7 10 10  6  6 10  6
##  [76]  9  8  7  6  6  9  8  8 10  9  6  9 10  9  9  6  8  8  7  6  7  8  6  6 12
## [101]  8  8  9  6 10  6  8 10  8  9  9  8  7  6  6  6  6 10  9  6  6  7  7  8  7
## [126]  6  6  8  7 11  9  9  6  9  9  6  9  6  7  7  6  7  9 10  8  8 10  6  9  9
## [151]  9  8  8  8  8  6  7  6  6  6 10  8  8  6 10  7  8  6  7  7  7  9  7  6  9
## [176]  8  6  6 10 11  6 10 10 11  7  8  8  6  6  8  8  9  8  7  8  9  9  9  8  6
## [201]  6 10  8  8  8  6  8  6  6  6  7  6 11  7  6 10 10  7  6  6 10  7  7 10  8
## [226]  7  9  7  7  9  6  8 10  8  8  7
# Assign variables for t-test to use for later results table
alpha = 0.05
CL = 1 - alpha

# Grade 6
fem_pop_g6 <- pop %>%
  filter(sex == "f", grade == 6)

mal_pop_g6 <- pop %>%
  filter(sex == "m", grade == 6)
fem_pop_g6
##    sex ageYear ageMonth heightIn weightLb grade
## 1    f   11.92      143     56.3     85.0     6
## 2    f   11.83      142     56.5     69.0     6
## 3    f   11.67      140     53.8     68.5     6
## 4    f   11.58      139     61.5    104.0     6
## 5    f   12.42      149     58.3     93.0     6
## 6    f   11.92      143     51.3     50.5     6
## 7    f   12.08      145     58.8     89.0     6
## 8    f   12.50      150     59.5     78.5     6
## 9    f   12.25      147     61.3    115.0     6
## 10   f   11.75      141     61.8     85.0     6
## 11   f   11.67      140     53.5     81.0     6
## 12   f   12.17      146     56.3     83.5     6
## 13   f   12.42      149     64.3    110.5     6
## 14   f   11.58      139     57.5     96.0     6
## 15   f   12.50      150     61.3     94.0     6
## 16   f   11.58      139     52.8     63.5     6
## 17   f   12.25      147     59.8     84.5     6
## 18   f   12.00      144     59.5     93.5     6
## 19   f   12.17      146     60.0    109.0     6
## 20   f   12.08      145     59.0     91.5     6
## 21   f   12.25      147     55.8     75.0     6
## 22   f   12.08      145     57.8     84.0     6
## 23   f   11.92      143     55.5     84.0     6
## 24   f   12.33      148     56.3     77.0     6
## 25   f   12.25      147     58.3    111.5     6
## 26   f   12.00      144     55.8     73.5     6
## 27   f   11.67      140     60.0     77.0     6
## 28   f   12.33      148     60.5     84.5     6
## 29   f   11.92      143     58.3     77.5     6
## 30   f   12.25      147     59.5    101.0     6
## 31   f   12.33      148     59.0     95.0     6
## 32   f   11.92      143     61.5    116.5     6
## 33   f   11.83      142     56.0     72.5     6
## 34   f   12.50      150     54.5     74.0     6
## 35   f   11.75      141     56.0     72.5     6
## 36   f   12.25      147     51.5     64.0     6
## 37   f   12.00      144     61.0     92.0     6
## 38   f   11.75      141     61.3     85.0     6
mal_pop_g6
##    sex ageYear ageMonth heightIn weightLb grade
## 1    m   12.00      144     57.3     76.5     6
## 2    m   12.50      150     59.5     84.0     6
## 3    m   12.50      150     60.8    128.0     6
## 4    m   11.58      139     60.5     87.0     6
## 5    m   12.25      147     50.5     79.0     6
## 6    m   12.17      146     57.5     90.0     6
## 7    m   11.75      141     53.3     84.0     6
## 8    m   12.50      150     59.0     99.5     6
## 9    m   11.67      140     59.5     94.5     6
## 10   m   12.17      146     57.3     83.0     6
## 11   m   11.67      140     56.5     84.0     6
## 12   m   12.00      144     62.8     94.0     6
## 13   m   11.92      143     57.5     75.0     6
## 14   m   12.00      144     59.5     88.0     6
## 15   m   12.42      149     57.0     92.0     6
## 16   m   12.00      144     60.0    117.5     6
## 17   m   12.25      147     57.0     84.0     6
## 18   m   12.50      150     59.5     84.0     6
## 19   m   11.67      140     58.5     86.5     6
## 20   m   12.00      144     57.0     84.0     6
## 21   m   12.42      149     52.5     81.0     6
## 22   m   11.83      142     55.0     70.0     6
## 23   m   11.83      142     58.8     84.0     6
## 24   m   12.08      145     56.5     91.0     6
## 25   m   11.92      143     57.5    101.0     6
## 26   m   12.50      150     59.0     98.0     6
## 27   m   12.50      150     61.8    118.0     6
## 28   m   11.75      141     57.5     85.0     6
## 29   m   11.83      142     56.0     87.5     6
## 30   m   12.33      148     60.5    118.0     6
## 31   m   11.67      140     56.8     83.5     6
## 32   m   12.00      144     60.0     89.0     6
## 33   m   12.42      149     56.3     72.0     6
## 34   m   12.17      146     55.0     71.5     6
## 35   m   11.58      139     55.0     73.5     6
## 36   m   11.83      142     55.0     76.0     6
ttest_g6 <- t.test(fem_pop_g6$weightLb, mal_pop_g6$weightLb, conf.level=CL)
ttest_g6 # pvalue = .3914, t = -.86 
## 
##  Welch Two Sample t-test
## 
## data:  fem_pop_g6$weightLb and mal_pop_g6$weightLb
## t = -0.86224, df = 71.85, p-value = 0.3914
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -9.580244  3.795156
## sample estimates:
## mean of x mean of y 
##  85.81579  88.70833
# Grade 7

fem_pop_g7 <- pop %>%
  filter(sex == "f", grade == 7)

mal_pop_g7 <- pop %>%
  filter(sex == "m", grade == 7)
fem_pop_g7
##    sex ageYear ageMonth heightIn weightLb grade
## 1    f   12.92      155     62.3    105.0     7
## 2    f   12.75      153     63.3    108.0     7
## 3    f   13.42      161     59.0     92.0     7
## 4    f   13.33      160     62.0     94.5     7
## 5    f   13.08      157     64.5    123.5     7
## 6    f   12.92      155     61.3    107.0     7
## 7    f   12.83      154     60.0    114.0     7
## 8    f   13.00      156     54.5     75.0     7
## 9    f   12.83      154     62.8     93.5     7
## 10   f   12.67      152     60.5    105.0     7
## 11   f   13.08      157     60.5    112.0     7
## 12   f   12.83      154     61.0    122.5     7
## 13   f   12.92      155     66.0    144.5     7
mal_pop_g7
##    sex ageYear ageMonth heightIn weightLb grade
## 1    m   13.08      157     60.5    105.0     7
## 2    m   13.33      160     60.5     84.0     7
## 3    m   13.00      156     61.8    112.0     7
## 4    m   12.58      151     66.3    117.0     7
## 5    m   12.75      153     60.0     84.0     7
## 6    m   12.58      151     58.3     86.0     7
## 7    m   12.58      151     61.0     81.0     7
## 8    m   13.33      160     59.3     78.5     7
## 9    m   13.00      156     66.3    106.0     7
## 10   m   13.08      157     58.0     80.5     7
## 11   m   13.00      156     58.3     92.5     7
## 12   m   13.00      156     61.5    108.5     7
## 13   m   13.17      158     65.0    121.0     7
## 14   m   13.00      156     68.5    114.0     7
## 15   m   12.67      152     59.5    105.0     7
## 16   m   12.92      155     61.8     91.5     7
## 17   m   13.33      160     64.0    116.0     7
## 18   m   13.25      159     63.3    112.0     7
## 19   m   12.67      152     60.8     97.0     7
## 20   m   13.42      161     56.8     75.0     7
## 21   m   12.75      153     64.8    128.0     7
## 22   m   13.25      159     62.8     99.0     7
## 23   m   12.75      153     57.8     79.5     7
## 24   m   12.92      155     57.3     80.5     7
## 25   m   12.58      151     59.3     87.0     7
ttest_g7 <- t.test(fem_pop_g7$weightLb, mal_pop_g7$weightLb, conf.level=CL)
ttest_g7 #p-value .101, t = 1.71, cannot reject null 
## 
##  Welch Two Sample t-test
## 
## data:  fem_pop_g7$weightLb and mal_pop_g7$weightLb
## t = 1.7103, df = 22.434, p-value = 0.101
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.070286 21.676440
## sample estimates:
## mean of x mean of y 
##  107.4231   97.6200
# Grade 8

fem_pop_g8 <- pop %>%
  filter(sex == "f", grade == 8)

mal_pop_g8 <- pop %>%
  filter(sex == "m", grade == 8)
fem_pop_g8
##    sex ageYear ageMonth heightIn weightLb grade
## 1    f   14.25      171     62.5    112.0     8
## 2    f   13.67      164     58.0     83.5     8
## 3    f   13.83      166     61.5    103.5     8
## 4    f   14.17      170     64.3     90.0     8
## 5    f   13.50      162     58.0     84.0     8
## 6    f   14.08      169     62.3     99.5     8
## 7    f   14.42      173     62.8    102.5     8
## 8    f   13.83      166     59.3     89.5     8
## 9    f   14.00      168     61.5     95.0     8
## 10   f   14.08      169     62.0     98.5     8
## 11   f   13.92      167     62.3     92.5     8
## 12   f   13.67      164     65.3     98.0     8
## 13   f   14.25      171     61.5     91.0     8
## 14   f   14.33      172     64.8    142.0     8
## 15   f   13.75      165     61.3    106.5     8
## 16   f   13.75      165     55.5     67.0     8
## 17   f   13.58      163     56.5     84.0     8
## 18   f   14.25      171     63.0     84.0     8
## 19   f   13.92      167     61.0     93.5     8
## 20   f   13.67      164     63.3    108.0     8
## 21   f   14.08      169     61.5     85.0     8
mal_pop_g8
##    sex ageYear ageMonth heightIn weightLb grade
## 1    m   13.75      165     64.8     98.0     8
## 2    m   14.42      173     61.3     93.0     8
## 3    m   13.67      164     57.8     95.0     8
## 4    m   13.50      162     64.5    119.0     8
## 5    m   13.67      164     60.5     95.0     8
## 6    m   14.42      173     69.0    112.5     8
## 7    m   14.17      170     63.8    112.5     8
## 8    m   14.50      174     66.0    108.0     8
## 9    m   13.67      164     63.5    108.0     8
## 10   m   14.08      169     62.0    100.0     8
## 11   m   14.33      172     65.0    112.0     8
## 12   m   14.00      168     60.0     93.5     8
## 13   m   14.00      168     66.5    111.5     8
## 14   m   14.50      174     69.8    119.5     8
## 15   m   13.83      166     62.5     84.0     8
## 16   m   13.58      163     65.3    117.5     8
## 17   m   13.83      166     67.3    121.0     8
## 18   m   14.42      173     66.0    112.0     8
## 19   m   13.50      162     60.0    105.0     8
## 20   m   13.83      166     62.0     91.0     8
## 21   m   13.58      163     66.0    112.0     8
## 22   m   14.25      171     61.8    112.0     8
## 23   m   13.50      162     63.0     91.0     8
## 24   m   14.50      174     63.0    112.0     8
## 25   m   13.67      164     58.0     84.0     8
## 26   m   13.67      164     66.5    112.0     8
## 27   m   13.67      164     61.5    140.0     8
## 28   m   13.92      167     62.0    107.5     8
ttest_g8 <- t.test(fem_pop_g8$weightLb, mal_pop_g8$weightLb, conf.level=CL)
ttest_g8 #p-value = .011 t = -2.655, reject null, significant weight difference.  
## 
##  Welch Two Sample t-test
## 
## data:  fem_pop_g8$weightLb and mal_pop_g8$weightLb
## t = -2.6553, df = 38.985, p-value = 0.01142
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -18.823615  -2.545433
## sample estimates:
## mean of x mean of y 
##  95.69048 106.37500
# Grade 9

fem_pop_g9 <- pop %>%
  filter(sex == "f", grade == 9)

mal_pop_g9 <- pop %>%
  filter(sex == "m", grade == 9)
fem_pop_g9
##    sex ageYear ageMonth heightIn weightLb grade
## 1    f   15.42      185     59.0    104.0     9
## 2    f   14.83      178     61.5    103.5     9
## 3    f   15.00      180     63.3    114.0     9
## 4    f   14.67      176     61.3    112.0     9
## 5    f   15.42      185     63.3    101.0     9
## 6    f   14.58      175     60.8     93.5     9
## 7    f   15.00      180     59.0    112.0     9
## 8    f   14.75      177     61.8    142.5     9
## 9    f   15.42      185     65.3    118.0     9
## 10   f   15.17      182     58.3    104.5     9
## 11   f   15.33      184     62.3    108.0     9
## 12   f   14.75      177     61.3    112.0     9
## 13   f   14.83      178     63.5    148.5     9
## 14   f   15.25      183     64.3    109.5     9
## 15   f   15.25      183     64.5    102.5     9
## 16   f   15.42      185     60.0    106.0     9
## 17   f   14.83      178     66.5    117.5     9
## 18   f   14.75      177     61.3     81.0     9
## 19   f   15.25      183     66.5    112.0     9
## 20   f   14.92      179     63.0     98.5     9
## 21   f   15.17      182     65.5    133.0     9
## 22   f   15.17      182     62.0     91.5     9
## 23   f   15.17      182     64.0    111.5     9
## 24   f   14.58      175     60.3     86.0     9
## 25   f   15.00      180     61.3    110.5     9
mal_pop_g9
##    sex ageYear ageMonth heightIn weightLb grade
## 1    m   15.25      183     64.8    111.0     9
## 2    m   14.67      176     63.8     98.5     9
## 3    m   14.67      176     65.0    118.5     9
## 4    m   15.42      185     66.0    105.0     9
## 5    m   15.00      180     61.8    104.0     9
## 6    m   15.25      183     66.0    105.5     9
## 7    m   14.83      178     67.3    119.5     9
## 8    m   14.58      175     64.0     92.0     9
## 9    m   14.58      175     68.0    112.0     9
## 10   m   14.58      175     63.5     98.5     9
## 11   m   15.33      184     66.5    112.0     9
## 12   m   14.67      176     61.5     81.0     9
## 13   m   15.17      182     67.0    133.0     9
## 14   m   14.75      177     63.0    111.0     9
## 15   m   14.75      177     60.5    112.0     9
## 16   m   14.58      175     65.5    114.0     9
## 17   m   14.83      178     63.8    112.0     9
## 18   m   14.83      178     63.5    102.5     9
ttest_g9 <- t.test(fem_pop_g9$weightLb, mal_pop_g9$weightLb, conf.level=CL)
ttest_g9 #p-value .72 , t = 0.35, cannot reject null 
## 
##  Welch Two Sample t-test
## 
## data:  fem_pop_g9$weightLb and mal_pop_g9$weightLb
## t = 0.35093, df = 40.932, p-value = 0.7274
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -6.805071  9.667293
## sample estimates:
## mean of x mean of y 
##  109.3200  107.8889
# Grade 10

fem_pop_g10 <- pop %>%
  filter(sex == "f", grade == 10)

mal_pop_g10 <- pop %>%
  filter(sex == "m", grade == 10)
fem_pop_g10
##    sex ageYear ageMonth heightIn weightLb grade
## 1    f   15.92      191     62.5    112.5    10
## 2    f   15.92      191     65.3    107.0    10
## 3    f   15.50      186     57.8     95.0    10
## 4    f   16.42      197     61.5    121.0    10
## 5    f   16.42      197     64.8    112.0    10
## 6    f   15.92      191     63.3    113.5    10
## 7    f   15.83      190     66.8    140.0    10
## 8    f   15.75      189     64.3    113.5    10
## 9    f   15.83      190     56.8     98.5    10
## 10   f   15.50      186     57.0     83.5    10
## 11   f   16.08      193     59.8    115.0    10
## 12   f   15.50      186     63.5    108.0    10
mal_pop_g10
##    sex ageYear ageMonth heightIn weightLb grade
## 1    m   15.75      189     67.0    128.0    10
## 2    m   16.08      193     66.3    133.0    10
## 3    m   15.50      186     66.0    112.0    10
## 4    m   15.67      188     67.3    112.0    10
## 5    m   16.08      193     67.8    127.5    10
## 6    m   15.67      188     71.0    140.0    10
## 7    m   15.75      189     66.3    112.0    10
## 8    m   15.67      188     65.8    150.5    10
## 9    m   15.67      188     63.3    115.5    10
## 10   m   16.08      193     72.0    150.0    10
## 11   m   16.17      194     65.3    134.5    10
## 12   m   15.50      186     66.5    112.0    10
## 13   m   16.33      196     64.5     98.0    10
## 14   m   15.75      189     65.0    114.0    10
ttest_g10 <- t.test(fem_pop_g10$weightLb, mal_pop_g10$weightLb, conf.level=CL)
ttest_g10 # Pvalue is .022 < .05, t = -2.43 > -2.262, reject null, significant weight difference. 
## 
##  Welch Two Sample t-test
## 
## data:  fem_pop_g10$weightLb and mal_pop_g10$weightLb
## t = -2.4335, df = 23.972, p-value = 0.02278
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -26.347653  -2.164252
## sample estimates:
## mean of x mean of y 
##  109.9583  124.2143

2.2) The null hypothesis

The null hypothesis is that the there is no significant correlation between sex and height for each grade. We’ll know if the null hypothesis is true by looking at the p-value from each t-test. If the p-value is greater than 0.05, we can accept the null hypothesis. If the p-value is less than 0.05, we can reject the null hypothesis.

Results:

Grade 6
Is 0.391 > 0.05? TRUE

Grade 7
Is 0.101 > 0.05? TRUE

Grade 8
Is 0.0114 > 0.05? FALSE

Grade 9
Is 0.727 > 0.05? TRUE

Grade 10
Is 0.0228 > 0.05? FALSE

For grades 6, 7, and 9 the null hypothesis is TRUE. This means we’re 95% confident that there’s no statistical correlation between sex and weight.

For grades 8 and 10, the null hypothesis is FALSE. This means we can’t confidently rule out a statistical correlation between sex and height. In other words, its possible that a reason for weight difference is gender.

2.3) Optional/Unfinished

Overall, growth trajectories vary year by year. Some years, we are able to observe a statistical relationship between weight and gender, and other years we are 95% confident that there is not a difference.

I added the means and the p-value as labels to the visuals below and it made it easier for me to see the takeaways. In 6 grade, men and women on average, are close in weight. We are 95% confident that there is not a statistical difference based on gender. In 7th grade, while the sample of women weighted more than men, on average, we did not find statistical correlation since the p-value was less than the confidence interval. Similar to 6th grade, the difference may have been due to chance. In 8th grade, on average, men weighted more than women. It’s possible that there is a difference based on gender, since the p-value was less than the confidence interval. In 9th grade, we were 95% confident that there is no difference between the genders. However in 10th grade, we can’t confidently rule it out.

# Combine data frames created for each grade above

# Grade 6
tf6 <- t.test(fem_pop_g6$weightLb)
tm6 <- t.test(mal_pop_g6$weightLb)
g6 <- bind_rows(fem_pop_g6, mal_pop_g6)

g6plot <- ggplot(g6, aes(x= weightLb, color=factor(sex))) +
  geom_density() +
  geom_vline(aes(xintercept=tf6$estimate), color="#F8766D", size=1.25) +
  geom_vline(aes(xintercept=tf6$conf.int[1]), color="#F8766D", alpha=.75, linetype="dashed") +
  geom_vline(aes(xintercept=tf6$conf.int[2]), color="#F8766D", alpha=.75, linetype="dashed") +
  geom_vline(aes(xintercept=tm6$estimate), color="#00BFC4", size=1.25) +
  geom_vline(aes(xintercept=tm6$conf.int[1]), color="#00BFC4", alpha=.75, linetype="dashed") +
  geom_vline(aes(xintercept=tm6$conf.int[2]), color="#00BFC4", alpha=.75, linetype="dashed") +
  theme(
    legend.position = "none"
  ) +
  labs(title="Grade 6")+
  geom_label(data=mal_pop_g6, aes(x=mean(mal_pop_g6$weightLb), y=.02), label= paste0("Mean:", round(mean(mal_pop_g6$weightLb),)))+
  geom_label(data=fem_pop_g6, aes(x=mean(fem_pop_g6$weightLb), y=.04), label= paste0("Mean:", round(mean(fem_pop_g6$weightLb),)))+
  geom_label(aes(x=75, y=.04), color = "black", label= paste0("Pvalue:", round(ttest_g6$p.value, digits = 2)))
g6plot
## Warning: Use of `mal_pop_g6$weightLb` is discouraged. Use `weightLb` instead.
## Warning: Use of `fem_pop_g6$weightLb` is discouraged. Use `weightLb` instead.

# Grade 7
tf7 <- t.test(fem_pop_g7$weightLb)
tm7 <- t.test(mal_pop_g7$weightLb)
g7 <- bind_rows(fem_pop_g7, mal_pop_g7)

g7plot <- ggplot(g7, aes(x= weightLb, color=factor(sex))) +
  geom_density() +
  geom_vline(aes(xintercept=tf7$estimate), color="#F8766D", size=1.25) +
  geom_vline(aes(xintercept=tf7$conf.int[1]), color="#F8766D", alpha=.75, linetype="dashed") +
  geom_vline(aes(xintercept=tf7$conf.int[2]), color="#F8766D", alpha=.75, linetype="dashed") +
  geom_vline(aes(xintercept=tm7$estimate), color="#00BFC4", size=1.25) +
  geom_vline(aes(xintercept=tm7$conf.int[1]), color="#00BFC4", alpha=.75, linetype="dashed") +
  geom_vline(aes(xintercept=tm7$conf.int[2]), color="#00BFC4", alpha=.75, linetype="dashed") +
  theme(
    legend.position = "none"
  ) +
  labs(title="Grade 7")+
  geom_label(data=mal_pop_g7, aes(x=mean(mal_pop_g7$weightLb), y=.02), label= paste0("Mean:", round(mean(mal_pop_g7$weightLb),)))+
  geom_label(data=fem_pop_g7, aes(x=mean(fem_pop_g7$weightLb), y=.04), label= paste0("Mean:", round(mean(fem_pop_g7$weightLb),)))+
  geom_label(aes(x=130, y=.04), color = "black", label= paste0("Pvalue:", round(ttest_g7$p.value, digits = 2)))
g7plot
## Warning: Use of `mal_pop_g7$weightLb` is discouraged. Use `weightLb` instead.
## Warning: Use of `fem_pop_g7$weightLb` is discouraged. Use `weightLb` instead.

# Grade 8
tf8 <- t.test(fem_pop_g8$weightLb)
tm8 <- t.test(mal_pop_g8$weightLb)
g8 <- bind_rows(fem_pop_g8, mal_pop_g8)

g8plot <- ggplot(g8, aes(x= weightLb, color=factor(sex))) +
  geom_density() +
  geom_vline(aes(xintercept=tf8$estimate), color="#F8766D", size=1.25) +
  geom_vline(aes(xintercept=tf8$conf.int[1]), color="#F8766D", alpha=.75, linetype="dashed") +
  geom_vline(aes(xintercept=tf8$conf.int[2]), color="#F8766D", alpha=.75, linetype="dashed") +
  geom_vline(aes(xintercept=tm8$estimate), color="#00BFC4", size=1.25) +
  geom_vline(aes(xintercept=tm8$conf.int[1]), color="#00BFC4", alpha=.75, linetype="dashed") +
  geom_vline(aes(xintercept=tm8$conf.int[2]), color="#00BFC4", alpha=.75, linetype="dashed") +
  theme(
    legend.position = "none"
  ) +
  labs(title="Grade 8")+
   geom_label(data=mal_pop_g8, aes(x=mean(mal_pop_g8$weightLb), y=.02), label= paste0("Mean:", round(mean(mal_pop_g8$weightLb),)))+
  geom_label(data=fem_pop_g8, aes(x=mean(fem_pop_g8$weightLb), y=.04), label= paste0("Mean:", round(mean(fem_pop_g8$weightLb),)))+
  geom_label(aes(x=130, y=.04), color = "black", label= paste0("Pvalue:", round(ttest_g8$p.value, digits = 2)))
g8plot
## Warning: Use of `mal_pop_g8$weightLb` is discouraged. Use `weightLb` instead.
## Warning: Use of `fem_pop_g8$weightLb` is discouraged. Use `weightLb` instead.

# Grade 9
tf9 <- t.test(fem_pop_g9$weightLb)
tm9 <- t.test(mal_pop_g9$weightLb)
g9 <- bind_rows(fem_pop_g9, mal_pop_g9)

g9plot <- ggplot(g9, aes(x= weightLb, color=factor(sex))) +
  geom_density() +
  geom_vline(aes(xintercept=tf9$estimate), color="#F8766D", size=1.25) +
  geom_vline(aes(xintercept=tf9$conf.int[1]), color="#F8766D", alpha=.75, linetype="dashed") +
  geom_vline(aes(xintercept=tf9$conf.int[2]), color="#F8766D", alpha=.75, linetype="dashed") +
  geom_vline(aes(xintercept=tm9$estimate), color="#00BFC4", size=1.25) +
  geom_vline(aes(xintercept=tm9$conf.int[1]), color="#00BFC4", alpha=.75, linetype="dashed") +
  geom_vline(aes(xintercept=tm9$conf.int[2]), color="#00BFC4", alpha=.75, linetype="dashed") +
  theme(
    legend.position = "none"
  ) +
  labs(title="Grade 9")+
   geom_label(data=mal_pop_g9, aes(x=mean(mal_pop_g9$weightLb), y=.02), label= paste0("Mean:", round(mean(mal_pop_g9$weightLb),)))+
  geom_label(data=fem_pop_g9, aes(x=mean(fem_pop_g9$weightLb), y=.04), label= paste0("Mean:", round(mean(fem_pop_g9$weightLb),)))+
  geom_label(aes(x=130, y=.04), color = "black", label= paste0("Pvalue:", round(ttest_g9$p.value, digits = 2)))
g9plot
## Warning: Use of `mal_pop_g9$weightLb` is discouraged. Use `weightLb` instead.
## Warning: Use of `fem_pop_g9$weightLb` is discouraged. Use `weightLb` instead.

# Grade 10
tf10 <- t.test(fem_pop_g10$weightLb)
tm10 <- t.test(mal_pop_g10$weightLb)
g10 <- bind_rows(fem_pop_g10, mal_pop_g10)

g10plot <- ggplot(g10, aes(x= weightLb, color=factor(sex))) +
  geom_density() +
  geom_vline(aes(xintercept=tf10$estimate), color="#F8766D", size=1.25) +
  geom_vline(aes(xintercept=tf10$conf.int[1]), color="#F8766D", alpha=.75, linetype="dashed") +
  geom_vline(aes(xintercept=tf10$conf.int[2]), color="#F8766D", alpha=.75, linetype="dashed") +
  geom_vline(aes(xintercept=tm10$estimate), color="#00BFC4", size=1.25) +
  geom_vline(aes(xintercept=tm10$conf.int[1]), color="#00BFC4", alpha=.75, linetype="dashed") +
  geom_vline(aes(xintercept=tm10$conf.int[2]), color="#00BFC4", alpha=.75, linetype="dashed") +
  theme(
    legend.position = "none"
  ) +
  labs(title="Grade 10")+
  geom_label(data=mal_pop_g10, aes(x=mean(mal_pop_g10$weightLb), y=.02), label= paste0("Mean:", round(mean(mal_pop_g10$weightLb),)))+
  geom_label(data=fem_pop_g10, aes(x=mean(fem_pop_g10$weightLb), y=.04), label= paste0("Mean:", round(mean(fem_pop_g10$weightLb),)))+
  geom_label(aes(x=130, y=.04), color = "black", label= paste0("Pvalue:", round(ttest_g10$p.value, digits = 2)))
g10plot
## Warning: Use of `mal_pop_g10$weightLb` is discouraged. Use `weightLb` instead.
## Warning: Use of `fem_pop_g10$weightLb` is discouraged. Use `weightLb` instead.

all_plots <- plot_grid(
  g6plot,
  g7plot,
  g8plot,
  g9plot,
  g10plot,
  align = c("hv"),
  nrow = 3
)
## Warning: Use of `mal_pop_g6$weightLb` is discouraged. Use `weightLb` instead.
## Warning: Use of `fem_pop_g6$weightLb` is discouraged. Use `weightLb` instead.
## Warning: Use of `mal_pop_g7$weightLb` is discouraged. Use `weightLb` instead.
## Warning: Use of `fem_pop_g7$weightLb` is discouraged. Use `weightLb` instead.
## Warning: Use of `mal_pop_g8$weightLb` is discouraged. Use `weightLb` instead.
## Warning: Use of `fem_pop_g8$weightLb` is discouraged. Use `weightLb` instead.
## Warning: Use of `mal_pop_g9$weightLb` is discouraged. Use `weightLb` instead.
## Warning: Use of `fem_pop_g9$weightLb` is discouraged. Use `weightLb` instead.
## Warning: Use of `mal_pop_g10$weightLb` is discouraged. Use `weightLb` instead.
## Warning: Use of `fem_pop_g10$weightLb` is discouraged. Use `weightLb` instead.
all_plots