#1: What are the cases in this data set? How many cases are there in our sample?
The cases are babies born in North Caronlina in 2004. There are 1000 observations in this sample.
#2: Make a side-by-side boxplot of habit and weight. What does the plot highlight about the relationship between these two variables?
boxplot(nc$weight ~ nc$habit)
The average baby for both groups appears to be roughly the same however there are many more lower outliers for the nonsmokers compared to the smokers.
#3: Check if the conditions necessary for inference are satisfied. Note that you will need to obtain sample sizes to check the conditions. You can compute the group size using the same by command above but replacing mean with length.
by(nc$weight, nc$habit, length)
## nc$habit: nonsmoker
## [1] 873
## --------------------------------------------------------
## nc$habit: smoker
## [1] 126
It is a safe assumption that the observations are independence and the above code verified that there are more than 30 observations in each group. The conditions for inference are satisfied.
#4: Write the hypotheses for testing if the average weights of babies born to smoking and non-smoking mothers are different.
\(H_0:u_{diff}=0\) \(H_a:u_{diff}\neq0\)
#5: Change the type argument to “ci” to construct and record a confidence interval for the difference between the weights of babies born to smoking and non-smoking mothers.
inference(y = nc$weight, x = nc$habit, est = "mean", type = "ci", null = 0,
alternative = "twosided", method = "theoretical")
## Response variable: numerical, Explanatory variable: categorical
## Difference between two means
## Summary statistics:
## n_nonsmoker = 873, mean_nonsmoker = 7.1443, sd_nonsmoker = 1.5187
## n_smoker = 126, mean_smoker = 6.8287, sd_smoker = 1.3862
## Observed difference between means (nonsmoker-smoker) = 0.3155
##
## Standard error = 0.1338
## 95 % Confidence interval = ( 0.0534 , 0.5777 )
The confidence interval is \((0.0534,0.5777)\)
#1: Calculate a 95% confidence interval for the average length of pregnancies (weeks) and interpret it in context. Note that since you’re doing inference on a single population parameter, there is no explanatory variable, so you can omit the x variable from the function.
inference(y = nc$weeks, est = "mean", type = "ci", null = 0,
alternative = "twosided", method = "theoretical")
## Single mean
## Summary statistics:
## mean = 38.3347 ; sd = 2.9316 ; n = 998
## Standard error = 0.0928
## 95 % Confidence interval = ( 38.1528 , 38.5165 )
It can be stated with 95% confidence that the average pregancy length of the population is between 38.1528 and 38.5165 weeks.
#2: Calculate a new confidence interval for the same parameter at the 90% confidence level. You can change the confidence level by adding a new argument to the function: conflevel = 0.90.
inference(y = nc$weeks, est = "mean", type = "ci", null = 0,
alternative = "twosided", method = "theoretical", conflevel=0.9)
## Single mean
## Summary statistics:
## mean = 38.3347 ; sd = 2.9316 ; n = 998
## Standard error = 0.0928
## 90 % Confidence interval = ( 38.182 , 38.4873 )
It can be stated with 95% confidence that the average pregancy length of the population is between 38.182 and 38.4873 weeks.
#3: Conduct a hypothesis test evaluating whether the average weight gained by younger mothers is different than the average weight gained by mature mothers.
inference(y = nc$gained, x=nc$mature, est = "mean", type = "ht", null = 0,
alternative = "twosided", method = "theoretical")
## Response variable: numerical, Explanatory variable: categorical
## Difference between two means
## Summary statistics:
## n_mature mom = 129, mean_mature mom = 28.7907, sd_mature mom = 13.4824
## n_younger mom = 844, mean_younger mom = 30.5604, sd_younger mom = 14.3469
## Observed difference between means (mature mom-younger mom) = -1.7697
##
## H0: mu_mature mom - mu_younger mom = 0
## HA: mu_mature mom - mu_younger mom != 0
## Standard error = 1.286
## Test statistic: Z = -1.376
## p-value = 0.1686
With a p-value of 0.1686, we fail to reject the null hypothesis. There is no evidence to suggest that there is a difference in weight gain between mature mothers and young mothers.
#4: Now, a non-inference task: Determine the age cutoff for younger and mature mothers. Use a method of your choice, and explain how your method works.
nc %>%
group_by(mature) %>%
summarise(min = min(mage), max=max(mage))
## # A tibble: 2 x 3
## mature min max
## <fct> <dbl> <dbl>
## 1 mature mom 35.0 50.0
## 2 younger mom 13.0 34.0
The cut off is between 34 and 35. I confirmed this by printing out the min and max ages for each group.
#5: Pick a pair of numerical and categorical variables and come up with a research question evaluating the relationship between these variables. Formulate the question in a way that it can be answered using a hypothesis test and/or a confidence interval. Answer your question using the inference function, report the statistical results, and also provide an explanation in plain language.
inference(y = nc$visits/ nc$weeks, x=nc$premie, est = "mean", type = "ht", null = 0,
alternative = "twosided", method = "theoretical")
## Response variable: numerical, Explanatory variable: categorical
## Difference between two means
## Summary statistics:
## n_full term = 840, mean_full term = 0.3151, sd_full term = 0.0968
## n_premie = 150, mean_premie = 0.3211, sd_premie = 0.137
## Observed difference between means (full term-premie) = -0.006
##
## H0: mu_full term - mu_premie = 0
## HA: mu_full term - mu_premie != 0
## Standard error = 0.012
## Test statistic: Z = -0.515
## p-value = 0.6068
Is there evidence to suggest a difference in the per week visit rate of mothers that give birth to premature babies compared to full term babies?
\(H_0:u_{diff}=0\) \(H_a:u_{diff}\neq0\)
With a p-value of \(.6068\), we fail to reject the null hypothesis. There is no evidence to suggest that mother’s of premature babies visit the hospital on a different basis than mother’s who have full term children.