According to the Centers for Disease Control and Prevention, the single best way to protect against the flu is to be vaccinated. Traditionally, flu vaccines are manufactured using viruses grown in chicken eggs. A new method allows growing viruses in cell cultures instead. To test the effectiveness of such vaccines, in a recent clinical trial n = 3900 randomly selected healthy subjects aged 18 – 49 received a cell-derived influenza vaccine by injection. During a follow-up period of approximately 28 weeks, each subject was assessed whether he or she developed influenza, which happened for 26 of the 3900 subjects.
x <- 26 # had influenza
n <- 3900 # total number of subjects
The population of interest is healthy subjects aged 18 to 49. The parameter of interest is the proportion of healthy subjects aged 18 to 49 who develop the flue even though they have the vaccine.
PE <- x/n
PE
## [1] 0.006666667
P hat (Point Estimate) of the proportion of people with the vaccine but still got the flu is 0.0067.
SE <- sqrt(PE * (1 - PE) / n)
SE
## [1] 0.001303075
We are okay if our point estimate is off by 0.0013, as that is our standard error.
z <- qnorm(0.995)
ME <- z * SE
ME
## [1] 0.0033565
The margin of error for our confidence interval is 0.0034
lower_bound <- round(PE - ME, 5)
upper_bound <- round(PE + ME, 5)
CI <- paste("(", lower_bound, ",", upper_bound, ")", sep = "")
print(CI)
## [1] "(0.00331,0.01002)"
We are 99 percent confident that the true proportion of healthy subjects from ages 18 to 49 who get the flu after being vaccinated is between 0.00331 and 0.01002.
We cannot conclude that fewer than 1 percent of all people vaccinated with the vaccine will develop the flu due to the fact that 0.01002 contains 1 percent (0.01).
In 2004, the state of North Carolina released a large data set containing information on births recorded in this state. This data set is useful to researchers studying the relation between habits and practices of expectant mothers and the birth of their children. We will work with a random sample of observations from this data set.
Load the nc data set into our workspace.
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ 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
download.file("http://www.openintro.org/stat/data/nc.RData", destfile = "nc.RData")
load("nc.RData")
nc <- na.omit(nc)
We have observations on 13 different variables, some categorical and some numerical. The meaning of each variable is as follows. variable description
fage : father’s age in years. mage : mother’s age in years. mature : maturity status of mother. weeks : length of pregnancy in weeks. premie : whether the birth was classified as premature (premie) or full-term. visits : number of hospital visits during pregnancy. marital : whether mother is married or not married at birth. gained : weight gained by mother during pregnancy in pounds. weight : weight of the baby at birth in pounds. lowbirthweight : whether baby was classified as low birthweight (low) or not (not low). gender : gender of the baby, female or male. habit : status of the mother as a nonsmoker or a smoker. whitemom : whether mom is white or not white.
library(ggplot2)
ggplot(data = nc, aes(y = weight, fill = habit)) +
geom_boxplot()
Visually, these box plots show that the median weight of the children
born to each type of parent does not appear to be significantly
different. The median weight of the non smoking baby is slightly larger,
but not worth noting. The non smoking mothers had a large amount of
outliers in their babies, which shows a large skew left. This may
possibly be explained by a larger sample size.
Numerically how do the means compare to each other?
by(nc$weight, nc$habit, mean)
## nc$habit: nonsmoker
## [1] 7.24676
## ------------------------------------------------------------
## nc$habit: smoker
## [1] 6.886429
Numerically, the non smoker babies are larger by weight than the babies of smoking mothers.
H_o : There is not a difference in average birth weight of newborns depending on their mothers smoking status.
H_a : There is a statistical difference in the average birth weight depending on thier mothers smoking status.
by(nc$weight, nc$habit, length)
## nc$habit: nonsmoker
## [1] 716
## ------------------------------------------------------------
## nc$habit: smoker
## [1] 84
One of the conditions to check if inference is satisfied is if the sample is random and is less than 10 percent of the entire population. As seen above, 800 newborns were in this same. Because the data covers the entire state of North Carolina, we can assume that 800 is less than 10 percent of all newborns born in the state in 2004. The second test for inference is to make sure that the two samples are independent of each other. Because a mother is either a smoker or not, the two samples are independent of each other. Because both tests are passed, the data set is eligible to use.
smoker <- subset(nc, nc$habit == 'smoker')
nonsmoker <- subset(nc, nc$habit == 'nonsmoker')
t_test <- t.test(smoker$weight, nonsmoker$weight, alternative = "two.sided", conf.level = 0.9)
t_test
##
## Welch Two Sample t-test
##
## data: smoker$weight and nonsmoker$weight
## t = -2.3625, df = 108.54, p-value = 0.01994
## alternative hypothesis: true difference in means is not equal to 0
## 90 percent confidence interval:
## -0.6133701 -0.1072923
## sample estimates:
## mean of x mean of y
## 6.886429 7.246760
Based on the t-test, the found p-value of 0.01994 is less than the significance level of 0.1. Because of this, we reject the null hypothesis. There is evidence that the mean difference between newborns whose mothers smoke vs. those who do not smoke is different.
If there was an error in from part 5, it would be a type one error. In context of this problem, a type one error would be rejecting the null hypothesis when there is actually no significant difference in the average birth weight depending on the mothers’ smoking status.