The cases are births in the state of North Carolina
habit
and weight
. What does the plot highlight about the relationship between these two variables?The plots reveal that the baby weights of non-smoking mothers are higher
library(ggplot2)
qplot(habit, weight, data=subset(nc,!is.na(habit)),
geom="boxplot", main="Smoking & Non-Smoking new birth weights")
by
command above but replacing mean
with length
.The conditions are satisfied, as the sample sizes are larger than 30, presumably represent less than 10% of the population, and are independant.
## nc$habit: nonsmoker
## [1] 873
## --------------------------------------------------------
## nc$habit: smoker
## [1] 126
H0: (\(\mu_{nonsmoker} = \mu_{smoker}\))
HA: (\(\mu_{nonsmoker} ≠\mu_{smoker}\))
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 )
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.We are 95% certain that the mean pregnancy length is between 38.15 and 38.5 weeks. The sample is skewed left
inference(y = nc$weeks, est = "mean", type = "ci",
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 )
conflevel = 0.90
.inference(y = nc$weeks, est = "mean", type = "ci",
alternative = "twosided", method = "theoretical",conflevel=.9)
## Single mean
## Summary statistics:
## mean = 38.3347 ; sd = 2.9316 ; n = 998
## Standard error = 0.0928
## 90 % Confidence interval = ( 38.182 , 38.4873 )
As shown below, since the p-value is ~.17 is higher than an alpha of .05, we fail to reject the null hypothesis (mu_mature mom - mu_younger mom = 0 ).
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
Here I use the by() function to provide summary statistics for each group. This indicates that corresponding age ranges for each group
## nc$mature: mature mom
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 35.00 35.00 37.00 37.18 38.00 50.00
## --------------------------------------------------------
## nc$mature: younger mom
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 13.00 21.00 25.00 25.44 30.00 34.00
inference
function, report the statistical results, and also provide an explanation in plain language.QUESTION: Do younger mothers have more boys than mature mothers?
Below we test two categorical variables, gender and mature. In the sample, we observe a difference in the proportions of boys of -.0095. This value falls well within the range of possible observed values if the null hypothesis were true (no difference in proportion of boys between age groups) and so we fail to reject the Null Hypothesis.
inference(y = nc$gender, x = nc$mature, est = "proportion", type = "ht", null = 0,
alternative = "twosided", method = "theoretical", success="male")
## Response variable: categorical, Explanatory variable: categorical
## Two categorical variables
## Difference between two proportions -- success: male
## Summary statistics:
## x
## y mature mom younger mom Sum
## female 68 435 503
## male 65 432 497
## Sum 133 867 1000
## Observed difference between proportions (mature mom-younger mom) = -0.0095
##
## H0: p_mature mom - p_younger mom = 0
## HA: p_mature mom - p_younger mom != 0
## Pooled proportion = 0.497
## Check conditions:
## mature mom : number of expected successes = 66 ; number of expected failures = 67
## younger mom : number of expected successes = 431 ; number of expected failures = 436
## Standard error = 0.047
## Test statistic: Z = -0.205
## p-value = 0.8376