# 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 14 female 9 not Black or African American NA NA never
3 15 female 9 hispanic Native Hawaiian or Other… 1.73 84.4 never
4 15 female 9 not Black or African American 1.6 55.8 never
5 15 female 9 not Black or African American 1.5 46.7 did not r…
6 15 female 9 not Black or African American 1.57 67.1 did not r…
# ℹ 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>, physical_3plus <chr>
##Exercise 3: Make a side-by-side violin plots of physical_3plus and weight. Is there a relationship between these two variables? What did you expect and why?
ggplot(data = yrbss1, aes(x = physical_3plus, y = weight)) +geom_violin()
Warning: Removed 1004 rows containing non-finite outside the scale range
(`stat_ydensity()`).
There doesn’t appear to be much of a difference between each of these plots. I would have expected those who were not physically active to weigh more than those who are.
# A tibble: 2 × 2
physical_3plus mean_weight
<chr> <dbl>
1 no 66.7
2 yes 68.4
##Exercise 4: Are all conditions necessary for inference satisfied? Comment on each. You can compute the group sizes with the summarize command above by defining a new variable with the definition n().
The conditions necessary for inference: 1. the distribution of the statistic is reasonably symmetric and bell-shaped 2. the sample size is reasonably large 3. the sample was representative of the population These conditions are met.
Excercise 5: Write the hypotheses for testing if the average weights are different for those who exercise at least times a week and those who don’t.
Ho = There is no difference in the average weights of those who exercise at least 3 times a week and those who do not.
Ha = There is a difference in the average weights of those who exercise at least 3 times a week and those who do not.
obs_diff <- yrbss2 %>%specify(weight ~ physical_3plus) %>%calculate(stat ="diff in means", order =c("yes", "no"))
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
##Exercise 6: Add a vertical red line to the plot above, demonstrating where the observed difference in means (obs_diff) falls on the distribution.
##Exercise 7: How many of these null_dist permutations have a difference at least as large (or larger) as obs_diff?
None of these seem to have a difference of this size.
null_dist %>%get_p_value(obs_stat = obs_diff, direction ="two_sided")
Warning: Please be cautious in reporting a p-value of 0. This result is an approximation
based on the number of `reps` chosen in the `generate()` step.
ℹ See `get_p_value()` (`?infer::get_p_value()`) for more information.
# A tibble: 1 × 1
p_value
<dbl>
1 0
##Exercise 8: What warning message do you get? Why do you think you get this warning message?
The warning I got was “Please be cautious in reporting a p-value of 0. This result is an approximation based on the number of reps chosen in the generate() step.” I think that I got this warning because there is never truly a 0% chance that the Ha is true, and it seems like a very unlikely p value to R.
##Exercise 9: Construct and record a confidence interval for the difference between the weights of those who exercise at least three times a week and those who don’t, and interpret this interval in context of the data.
We are 95% confident that the true population difference in means for those who exercise 3 or more days a week and those who do not is between -.618 and 0.660.
##Excercise 10: Calculate a 95% confidence interval for the average height in meters (height) and interpret it in context.
We are 95% confident that the true population mean height is between 1.689 and 1.693.
##Exercise 11: Calculate a new confidence interval for the same parameter at the 90% confidence level. Comment on the width of this interval versus the one obtained in the previous exercise.
confint(l.model, level=0.90)
5 % 95 %
(Intercept) 1.689705 1.692777
The width of this confidence interval is smaller than the previous example, as it leaves out more possibilities so we are less confident that the true population mean is contained within it.
##Exercise 12: Conduct a hypothesis test evaluating whether the average height is different for those who exercise at least three times a week and those who don’t.
null_dist1 <- yrbss2 %>%specify(height ~ physical_3plus) %>%hypothesize(null ="independence") %>%generate(reps =1000, type ="permute") %>%calculate(stat ="diff in means", order =c("yes", "no"))
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
From the histogram, it looks like the results are not independent as there are barely any here the difference is as large as the one observed. We reject the null hypothesis that there is no mean height difference between those who do exercise 3 or more times a week and those who do not.
##Exercise 13: Now, a non-inference task: Determine the number of different options there are in the dataset for the hours_tv_per_school_day there are.
possible <-unique(yrbss$hours_tv_per_school_day)possible
[1] "5+" "2" "3" "do not watch" "<1"
[6] "4" "1" NA
There are 8 options. Which are do not watch, <1 ,1,2,3,4,5+, and NA.
##Exercise 14: Come up with a research question evaluating the relationship between height or weight and sleep. Formulate the question in a way that it can be answered using a hypothesis test and/or a confidence interval. Report the statistical results, and also provide an explanation in plain language. Be sure to check all assumptions, state your αlevel, and conclude in context
Do high schoolers who sleep less than 6 hours a night weigh more?
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
null_dist2 %>%get_p_value(obs_stat = obs_diff, direction ="two_sided")
Warning: Please be cautious in reporting a p-value of 0. This result is an approximation
based on the number of `reps` chosen in the `generate()` step.
ℹ See `get_p_value()` (`?infer::get_p_value()`) for more information.
# A tibble: 1 × 1
p_value
<dbl>
1 0
Because the p value is so low, we can reject the null hypothesis that there is not a difference in the average weight of those students who do get less than 6 hours of sleep on a school night and those who do not.