Question 1: Many high school students take the AP tests in different subject areas. In 2017, of the 144,790 students who took the biology exam 84,200 of them were female. In that same year, of the 211,693 students who took the calculus AB exam 102,598 of them were female. Is there enough evidence to show that the proportion of female students taking the biology exam is higher than the proportion of female students taking the calculus AB exam? Test at the 5% level.

I’m doing the hypothesis test, and in this case a z-test makes the most sense. I’m also finding the p-value.

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.3     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.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
n_biology <- 144790
x_biology <- 84200
n_calc <- 211693
x_calc <- 102598

alpha <- 0.05

p_biology <- x_biology / n_biology
p_calc <- x_calc / n_calc

cat("Female proportion in Biology:", round(p_biology, 4), "\n")
## Female proportion in Biology: 0.5815
cat("Female proportion in Calculus AB:", round(p_calc, 4), "\n")
## Female proportion in Calculus AB: 0.4847
#Perform two-proportion z-test
prop_test_result <- prop.test(
  x = c(x_biology, x_calc),
  n = c(n_biology, n_calc),
  alternative = "greater",
  conf.level = 0.95,
  correct = FALSE)

print(prop_test_result)
## 
##  2-sample test for equality of proportions without continuity correction
## 
## data:  c(x_biology, x_calc) out of c(n_biology, n_calc)
## X-squared = 3235.3, df = 1, p-value < 2.2e-16
## alternative hypothesis: greater
## 95 percent confidence interval:
##  0.09409523 1.00000000
## sample estimates:
##    prop 1    prop 2 
## 0.5815319 0.4846547
# Extract p-value
p_value <- prop_test_result$p.value
cat("\nP-value:", p_value, "\n")
## 
## P-value: 0

p₁: proportion of female students taking the AP Biology exam p₂: proportion of female students taking the AP Calculus AB exam

H0:p₁ ≤ p₂ Ha:p₁ > p₂

State the significance level α: 0.05 (5%)

p-value P value is zero.

State your decision.

We are able to reject the null hypothesis. Our alternative hypothesis, that a higher proportion of female students take the AP Biology exam instead of AP Calculcus AB exam, appears to be true.

Question 2: A vitamin K shot is given to infants soon after birth. The study is to see if how they handle the infants could reduce the pain the infants feel. One of the measurements taken was how long, in seconds, the infant cried after being given the shot. A random sample was taken from the group that was given the shot using conventional methods, and a random sample was taken from the group that was given the shot where the mother held the infant prior to and during the shot. Is there enough evidence to show that infants cried less on average when they are held by their mothers than if held using conventional methods? Test at the 5% level.

μ₁: mean crying time (seconds) μ₂: mean crying time (seconds)

A left-sided one tailed t test makes the most sense for this sample. First we’ll have to import the data.

infantKshot <- c(63, 0, 2, 46, 33, 33, 29, 23, 11, 12, 48, 15, 33, 14, 51, 37, 24, 70, 63, 0, 73, 39, 54, 52, 39, 34, 30, 55, 58, 18)

infantheld <- c(0, 32, 20, 23, 14, 19, 60, 59, 64, 64, 72, 50, 44, 14, 10, 58, 19, 41, 17, 5, 36, 73, 19, 46, 9, 43, 73, 27, 25, 18)

t_test_result <- t.test(
  x = infantheld,
  y = infantKshot,
  alternative = "less",  
  var.equal = FALSE,  
  conf.level = 0.95)

print(t_test_result)
## 
##  Welch Two Sample t-test
## 
## data:  infantheld and infantKshot
## t = -0.029953, df = 57.707, p-value = 0.4881
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
##      -Inf 9.135003
## sample estimates:
## mean of x mean of y 
##  35.13333  35.30000
#Extract p-value
p_value_t <- t_test_result$p.value
cat("\nP-value:", p_value_t, "\n")
## 
## P-value: 0.4881039

State the significance level α: 0.05 (5%)

p-value Because the p-value is so large, 0.4881039, this data is not significant.

State your decision.

Because the data isn’t significant, we can’t claim that either the shot group or the mother’s embrace group because they don’t have enough evidence.