# A tibble: 6 × 14
age gender grade hispanic race height weight helmet_12m
<int> <chr> <chr> <chr> <chr> <dbl> <dbl> <chr>
1 14 female 9 not Black or African American NA NA never
2 15 female 9 hispanic Native Hawaiian or Other… 1.73 84.4 never
3 15 female 9 not Black or African American 1.6 55.8 never
4 16 male 9 not Black or African American 1.68 74.8 never
5 14 male 9 not Black or African American 1.73 73.5 never
6 15 male 9 not Black or African American 1.83 67.6 never
# ℹ 6 more variables: text_while_driving_30d <chr>, physically_active_7d <int>,
# hours_tv_per_school_day <chr>, strength_training_7d <int>,
# school_night_hours_sleep <chr>, text_ind <chr>
What is the margin of error for the estimate of the proportion of non-helmet wearers that have texted while driving each day for the past 30 days based on this survey?
Using the infer package, calculate confidence intervals for two other categorical variables (you’ll need to decide which level to call “success”, and report the associated margins of error. Interpet the interval in context of the data. It may be helpful to create new data sets for each of the two countries first, and then use these data sets to construct the confidence intervals.
# A tibble: 13,571 × 14
age gender grade hispanic race height weight helmet_12m
<int> <chr> <chr> <chr> <chr> <dbl> <dbl> <chr>
1 14 female 9 not Black or African Americ… NA NA never
2 14 female 9 not Black or African Americ… NA NA never
3 15 female 9 hispanic Native Hawaiian or Othe… 1.73 84.4 never
4 15 female 9 not Black or African Americ… 1.6 55.8 never
5 15 female 9 not Black or African Americ… 1.5 46.7 did not r…
6 15 female 9 not Black or African Americ… 1.57 67.1 did not r…
7 15 female 9 not Black or African Americ… 1.65 132. did not r…
8 14 male 9 not Black or African Americ… 1.88 71.2 never
9 15 male 9 not Black or African Americ… 1.75 63.5 never
10 15 male 10 not Black or African Americ… 1.37 97.1 did not r…
# ℹ 13,561 more rows
# ℹ 6 more variables: text_while_driving_30d <chr>, physically_active_7d <int>,
# hours_tv_per_school_day <chr>, strength_training_7d <int>,
# school_night_hours_sleep <chr>, gender_var <chr>
# Interpretation# We are 95% confident that the true difference in proportions of female and not female youth of the yrbss dataset is between 47.911% and 49.687%.
# A tibble: 13,352 × 14
age gender grade hispanic race height weight helmet_12m
<int> <chr> <chr> <chr> <chr> <dbl> <dbl> <chr>
1 14 female 9 not Black or African Americ… NA NA never
2 14 female 9 not Black or African Americ… NA NA never
3 15 female 9 hispanic Native Hawaiian or Othe… 1.73 84.4 never
4 15 female 9 not Black or African Americ… 1.6 55.8 never
5 15 female 9 not Black or African Americ… 1.5 46.7 did not r…
6 15 female 9 not Black or African Americ… 1.57 67.1 did not r…
7 15 female 9 not Black or African Americ… 1.65 132. did not r…
8 14 male 9 not Black or African Americ… 1.88 71.2 never
9 15 male 9 not Black or African Americ… 1.75 63.5 never
10 15 male 10 not Black or African Americ… 1.37 97.1 did not r…
# ℹ 13,342 more rows
# ℹ 6 more variables: text_while_driving_30d <chr>, physically_active_7d <int>,
# hours_tv_per_school_day <chr>, strength_training_7d <int>,
# school_night_hours_sleep <chr>, hispanic_var <chr>
# Interpretation# We are 95% confident that the true difference in proportions of non-hispanic and hispanic youth of the yrbss dataset is between 73.637% and 75.038%.
How does the proportion affect the margin of error?
Exercise 5
Describe the relationship between p and me. Include the margin of error vs. population proportion plot you constructed in your answer. For a given sample size, for which value of p is margin of error maximized?
n <-1000p <-seq(from =0, to =1, by =0.01)me <-2*sqrt(p * (1- p)/n)dd <-data.frame(p = p, me = me)ggplot(data = dd, aes(x = p, y = me)) +geom_line() +labs(x ="Population Proportion", y ="Margin of Error")
# p is maximized when the population proportion is 0.50.
More Practice
Exercise 9
Is there convincing evidence that those who sleep 10+ hours per day are more likely to strength train every day of the week? As always, write out the hypotheses for any tests you conduct and outline the status of the conditions for inference. If you find a significant difference, also quantify this difference with a confidence interval.
# Ho: There is no evidence those who sleep 10+ hours per day are more likely to strength train every day of the week.# Ha: There is evidence those who sleep 10+ hours per day are more likely to strength train every day of the week.# Compare the proportions of those who strength train 7 days of the week and sleep 10+ hours vs those who sleep lesssleep1 <- yrbss |>mutate(longer_sleep =ifelse(school_night_hours_sleep =="10+", "yes", "no")) |>filter(!is.na(longer_sleep))
Exercise 10
Let’s say there has been no difference in likeliness to strength train every day of the week for those who sleep 10+ hours. What is the probablity that you could detect a change (at a significance level of 0.05) simply by chance? Hint: Review the definition of the Type 1 error.
Exercise 11
Suppose you’re hired by the local government to estimate the proportion of residents that attend a religious service on a weekly basis. According to the guidelines, the estimate must have a margin of error no greater than 1% with 95% confidence. You have no idea what to expect for p . How many people would you have to sample to ensure that you are within the guidelines? Hint: Refer to your plot of the relationship between p and margin of error. This question does not require using a dataset.