Answer 1: 4792 students claim that they did not text and drive within the past 30 days. 925 students texted 1-2 days, 493 students texted 3-5 days, 311 students texted 6-9 days, 373 students texted 10-19 days, and 298 students texted 20-29 days. 827 students texted and drove all of the past 30 days while 4646 students did not drive at all.
Exercise 2: What is the proportion of people who have texted while driving every day in the past 30 days and never wear helmets?
# 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>
Answer 2: The propotion of people who have texted while driving every day in the past 30 days and never wear helmets is 0.071.
Exercise 3: 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?
Exercise 4: 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.
yrbss
# A tibble: 13,583 × 13
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,573 more rows
# ℹ 5 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>
yrbss |>group_by(gender) |>count()
# A tibble: 3 × 2
# Groups: gender [3]
gender n
<chr> <int>
1 female 6621
2 male 6950
3 <NA> 12
# A tibble: 6 × 14
age gender grade hispanic race height weight helmet_12m
<int> <chr> <chr> <chr> <chr> <dbl> <dbl> <chr>
1 15 female 9 hispanic Native Hawaiian or Other… 1.73 84.4 never
2 12 female 9 hispanic Black or African American 1.8 90.7 did not r…
3 17 female 11 hispanic <NA> 1.68 86.2 did not r…
4 12 male 12 hispanic White NA NA never
5 18 male 12 hispanic <NA> 1.65 72.6 never
6 15 male 10 hispanic Black or African American 1.78 68.5 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>, female_hispanic <chr>
Answer 4 part i): The confidence intervals for being both female and hispanic are 0.474 and 0.507.
se <- boot |>summarize(se =sd(stat)) |>pull()se
[1] 0.008243454
me <-1.96*seme
[1] 0.01615717
Answer 4 part ii): The margin of error is 0.017.
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")
Answer 5: The margin of error seems to increase as the population proportion increases. However, once the population proportion reaches 50 % (maximum margin of error) the margin of error starts to decrease.