Objective: R markdown with the goal of formatting a workflow in order to answer questions and provide a decision based on the p-value gained from certain data provided in homework 7 document.
Libraries: None
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.
Additional Information: two-proportion z-test -> one tailed -> p1 greater than p2
Hypothesis: The propertion of female students that took the biology exam is higher than the females that took the calculus AB exam.
p1 = proportion of females taking Biology AP exam
p2 = proportion of females taking Calculus AB exam
H0: p1 = p2
Ha: p1 > p2
Significance level: α = 0.05 -> 5% significance level
n1 <- 144790
x1 <- 84200
n2 <- 211693
x2 <- 102598
p1_hat <- x1/n1
p2_hat <- x2/n2
α = 0.05
Q1_results <- prop.test(c(x1, x2), c(n1, n2), alternative = "greater", correct = FALSE)
Q1_results
##
## 2-sample test for equality of proportions without continuity correction
##
## data: c(x1, x2) out of c(n1, n2)
## 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
p_value <- Q1_results$p.value
p_value
## [1] 0
Decision
decision <- ifelse(Q1_results$p.value < α, "p-value < 0.05 → reject H0", "p-value ≥ 0.05 → fail to reject H0")
decision
## [1] "p-value < 0.05 → reject H0"
Based on the result summary, the p-value was reported as less than the default minimum value of 2.2e-16. This indicates that the true p-value is even smaller than this minimum value.
Therefore, we reject the null hypothesis (H₀).
There is sufficient evidence at the 5% significance level to conclude that the proportion of female Biology AP students is higher than the proportion of female Calculus AB students.
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.
Additional Information: Two-Sample t-Test -> One tailed -> µ1 is less than µ2
Hypothesis: The group that was given the shot using new method cried less on average than the group that was given the shot using conventional method.
µ1 = Average crying time of group given the shot using new method
µ2 = Average crying time of group given the shot using conventional method
H0: µ1 = µ2
Ha: µ1 < µ2
Significance level: α = 0.05 -> 5% significance level
convention_method_group <- 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)
New_method_group <- 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)
Q2_results <- t.test(New_method_group, convention_method_group,
alternative = "less",
var.equal = FALSE)
α = 0.05
Q2_results
##
## Welch Two Sample t-test
##
## data: New_method_group and convention_method_group
## 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
p_value <- Q2_results$p.value
p_value
## [1] 0.4881039
Decision
decision <- ifelse(Q2_results$p.value < α, "p-value < 0.05 → reject H0", "p-value ≥ 0.05 → fail to reject H0")
decision
## [1] "p-value ≥ 0.05 → fail to reject H0"
Based on the result summary, the p-value is 0.4881039.
Because this p-value is much larger than 0.05, we fail to reject the null hypothesis (H0).
There is not sufficient evidence at the 5% significance level to conclude that the group given the shot with the new method cried less than the group given the shot with the conventional method.