$\$
In the following homework you will gain practice running hypothesis tests for more than two means and correlations. Please submit a compiled pdf with your answers to the exercises to Gradescope by 11pm on Sunday March 31st. Five points will be taken off if you do not mark the pages for each problem on Gradescope.
A list of functions we have used in class can be found on Canvas.You might also find the following symbols useful: $\mu$, $H_0$, $H_a$, $\rho$, $\ne$, and $\alpha$. For full credit on problems involving R, be sure to label all your figures and to "show your work" by making sure all values that are answers to questions are printed/visible in your R Markdown pdf.
As always, if you need help with any of the homework assignments, please attend the TA office hours which are listed on Canvas and/or ask questions on Ed Discussions forum. Also, if you have completed the homework, please help others out by answering questions on Ed Discussions. Finally, reviewing the class slides and videos will be helpful if you run into difficulties.
# download data and images needed for this homework SDS100::download_data("movies.Rda") SDS100::download_data('draft_lottery_data.Rda') download.file("https://raw.githubusercontent.com/emeyers/SDS100/master/ClassMaterial/images/Lock5_4_26.png", "Lock5_4_26.png", mode = "wb") download.file("https://raw.githubusercontent.com/emeyers/SDS100/master/ClassMaterial/images/1969_draft_lottery_photo.jpg", "1969_draft_lottery_photo.jpg", mode = "wb")
library(SDS100) library(knitr) options(scipen=999) set.seed(100)
$\$
Are movies that have particular Motion Picture Association of America (MPAA) ratings (i.e., G, PG, PG-13 or R) enjoyed more by movie critics? In the exercises below we will run hypothesis tests to examine this question using data from over 500 movies randomly selected from the Rotten Tomatoes website.
$\$
Exercise 1.0 (2 points):
The code below loads the movie data and creates two vectors. The first vector is called mpaa_rating
and has the MPAA rating for each movie (i.e., the vector contains categorical data with the levels of: G, PG, PG-13, and R). The second vector is called critics_score
and contains ratings critics gave to movies on a scale from 1 to 100. You will use these two vectors (mpaa_rating
and critics_score
) to examine whether the average (mean) movie scores differ depending on the rating MPAA rating level. If you are interested in learning more about this full data set a codebook describing the variables can be found on this website.
To start your analysis, report the sample size n for these two vectors using the length()
function.
# load the data load('movies.Rda') # only keep movies rated "G", "PG", "PG-13", "R" (you can ignore this) movies2 <- movies[movies$mpaa_rating %in% c("G", "PG", "PG-13", "R"), ] movies2$mpaa_rating <- droplevels(movies2$mpaa_rating) # get the MPAA ratings and the rotten tomatoes critic scores # you will only use these two vectors for the rest of these exercises mpaa_rating <- movies2$mpaa_rating critics_score <- movies2$critics_score # display the sample size of the two vectors you will use in your analyses
Answer [report the sample size of these vectors].
$\$
Exercise 1.1 (5 points): Let's now start our hypothesis test with step 1 by stating the null and alternative hypotheses in symbols and words. Also state the significance level ($\alpha$) that is most commonly used in hypothesis tests (i.e., if the p-value is less than $\alpha$, $H_0$ will be rejected).
Answers:
In words
In symbols
The significance level
$\$
Exercise 1.2a (5 points) Let's now visualize the data by creating a side-by-side boxplot comparing the critics' scores of the movie for each MPAA rating level. Does it appear that the critics' scores differ on average depending on the MPAA classification of the movie?
Answer:
$\$
Part 1.2b (4 points): Next let's use the MAD statistic that we discussed in class to compare the mean critic scores between the different MPAA rating levels. To do this we can use the get_MAD_stat(quantitative_data, grouping_data)
function from the SDS100 library. Save the MAD statistic value to an object called obs_stat
and report the value of this statistic below.
# Calculate the MAD statistic
Answer:
$\$
Exercise 1.3 (10 points): Now let's do step 3 of the hypothesis test by creating a null distribution. Then plot the null distribution along with a red vertical line at the real MAD statistic value. Based on looking at this null distribution, what do you think the p-value is and does there appear to be a difference between between the critics' scores depending on the MPAA rating?
# create the null distribution # plot the null distribution with a red vertical line for the statistic value
Answers
$\$
Exercise 1.4 (4 points): Let's do step 4 of the hypothesis test by calculating the p-value using the SDS100 pnull
function. Report what the p-value is. Is this close to what you estimated by looking at the null distribution above?
Answers
$\$
Exercise 1.5 (4 points): Now complete step 5 of hypothesis testing by making a judgment. Are you able to reject the null hypothesis? What do you conclude?
Answer
$\$
The exercise in part 2 is based on a question from the Lock5 textbook. For additional practice problems please see the textbook.
$\$
Exercise 2.1: Mercury Levels in Fish (12 points) Figure 1 shows a scatter plot of the acidity (pH) for a sample of n = 53 Florida lakes vs the average mercury level (ppm) found in fish taken from each lake (the full data set, called FloridaLakes, can be obtained from the Lock5 website at: http://www.lock5stat.com/datapage.html). There appears to be a negative trend in the scatter plot, and we wish to test whether there is significant evidence of a negative association between pH and mercury levels.
a. What are the null and alternative hypotheses in symbols and words?
b. For these data, a statistical software package produced the following output: r = -0.575 and a p-value = 0.000017
Use the p-value to give the conclusion of the test. Include an assessment of the strength of evidence and state your results in terms of rejecting or failing to reject $H_0$ and in terms of pH and mercury.
c. Is the evidence convincing that low pH causes the average mercury level in fish to increase? Why or why not?
$\$
Answers
a.
b.
c.
$\$
In 1969, the United States Selective Service conducted a lottery to decide which young men would be drafted into the armed forces. Each of the 366 birthdays in a year (including February 29) was assigned a draft number. Young men born on days that were assigned low draft numbers were drafted.
If the draft was completely fair, there should be no correlation between the draft number and the date someone was born. In the following set of exercises we will use hypothesis testing to assess whether there was indeed no correlation.
$\$
Exercise 3.1 (4 points): Let's start by doing step 1 of our null hypothesis significance tests (NHSTs) by stating the null and alternative hypotheses in symbols and in words, and state the conventional significance level.
Answer:
$\$
Part 3.2a (5 points): Now that we've stated the null and alternative hypothesis, let's visualize the data. The code below extracts two vectors that we can use to assess whether there is a correlation between the dates some one was born on and their draft number. In particular, the vector sequential_date
contains the numbers for the sequential dates of the year (i.e., January 1st is 1, January 2nd is 2, etc.), and the vector draft_number
contains the draft number for each sequential date. Using these two vectors, create a scatter plot of the draft number as a function of the sequential date. Does there appear to be any trend in the data?
# load the data into R load('draft_lottery_data.Rda') sequential_date <- draft_lottery_data$Sequential_Date draft_number <- draft_lottery_data$Draft_Number # plot the data
Answer:
$\$
Part 3.2b (4 points): Next let's do step 2 of hypothesis testing by calculating the statistic of interest and saving it to an object called obs_stat
. Describe what this statistic means as clearly as you can (e.g., if the statistic is negative what does that mean in terms of dates and draft numbers?).
Answer:
$\$
Part 3.3 (10 points): Now let's do step 3 of hypothesis testing by creating a null distribution. You can calculate one point in the null distribution by shuffling the draft_numbers
(using the SDS100 shuffle()
function) and then calculating the correlation. Use the do_it()
to repeat this process 10,000 times to generate the full null distribution. Plot a histogram of the null distribution, put a red vertical line on it at the value of the observed statistic, and describe the null distribution's shape. Is the center of the null distribution at a value that makes sense to you? Also, report what you expect the p-value to be.
Answer:
$\$
Part 3.4 (7 points): Now use the pnull()
function to calculate the p-value by seeing the proportion of points in the null distribution that are as extreme or more extreme than the observed statistic. Is this p-value consistent with there being no correlation between draft numbers and sequential dates?
Answer:
$\$
Part 3.5 (5 points): Make a judgment call as to whether you believe the draft lottery was fair. Make sure to justify your answer.
Answer:
$\$
The Lock5 textbook describes a study by Frank and Gilovich (1988) that examined a possible relationship between the perceived malevolence of a team's uniforms and penalties called against the team. In this exercise we are going to examine the data collected by this study related to uniforms from the National Hockey League (NHL).
In the study by Frank and Gilovich (1988), participants with no knowledge of the teams rated the jerseys on characteristics such as timid/aggressive, nice/mean, and good/bad. The averages of these responses produced a "malevolence index" with higher scores signifying impressions of more malevolent (evil-looking) uniforms. To measure aggressiveness, the authors used the amount of penalties (hockey penalty minutes) converted to z-scores and averaged for each team over the seasons from 1970 to 1986. We are interested in whether teams with more malevolent uniforms get more penalties.
$\$
Exercise 4.1: (16 points) The code below loads data from this study. In particular, it creates an object called uniform_malevolence
which has the "malevolence index" for each uniform, and an object called z_penalty_mins
which has the z-score of the number of penalty minutes each team had.
Using this data, please run the 5 steps of a hypothesis test to examine whether there is a statistically significant relationship between perceived malevolence of a team's uniforms and penalties called against the team using a significance level of $\alpha$ = 0.05. Fill in your results from each step of the hypothesis test in the answer section below and for step 2 be sure to also plot the data.
# load the data MalevolentUniformsNHL <- read.csv('https://www.lock5stat.com/datasets3e/MalevolentUniformsNHL.csv') MalevolentUniformsNHL <- MalevolentUniformsNHL[1:21, ] # get rid of the last few entries which contain NAs # create the two objects you will need to do your analysis uniform_malevolence <- MalevolentUniformsNHL$NHL_Malevolence z_penalty_mins <- MalevolentUniformsNHL$ZPenMin # do your analysis here... # step 2 # step 3 # step 4
Answers:
$\$
Please reflect on how the homework went by going to Canvas, going to the Quizzes link, and clicking on Reflection on homework 7.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.