Assignment 7 is due by midnight NEXT WEDNESDAY (1 week lab) See here I PROVIDE HELP UNTIL THE END OF NEXT WEEK’S LAB. After next week’s lab (All of Wed evening) is for your own finishing up.
By the end of this week’s lab, you will be able to:
There is a TEAMS discussion for lab help CLICK HERE. Remember to include a screenshot of the issue and a short description of the problem. Also try googling the error first.
Step A: Create a new project for Lab 7. If you are stuck, see previous labs or Tutorial 2.1.
Step B: Copy your lab template to your lab 7 folder, rename as STAT-462_Lab7_EMAILID.Rmd
and open (e.g.STAT-462_Lab6_hlg5155.Rmd). This should have your theme, your table of contents and your headings.
Step C: In the library section, add a new code chunk and use this code to load the libraries below.
If some don’t exist on your computer or on the cloud, use Tutorial 2.3 to install/download them first. NEVER put install.packages in your code chunk, run it in the console.
To make sure they loaded OK, run the code chunk TWICE. The second time any welcome text will disappear unless there are errors.
Sometimes you might need an extra package later in the lab. Install it using the instructions above and add the library commands to your library code chunk.
# Load libraries
library("tidyverse") # Lots of data processing commands
library("knitr") # Helps make good output files
library("ggplot2") # Output plots
library("rmarkdown") # Helps make good output files
library("lattice") # Makes nice plots
library("RColorBrewer") # Makes nice color-scales
library("skimr") # Summary statistics
library("Stat2Data") # Regression specific commands
library("corrplot") # correlation plots
library("GGally") # correlation plots
library("ggpubr") # QQplots
library("olsrr") # Regression specific commands
library("plotly") # Interactive plots
library("readxl") # Read from excel files
library("equatiomatic") # extract equations
library("ggstatsplot")
library("MASS")
## you may need additional libraries. Just add them to this list if you get errors.
Step D: Finally, press knit to check the html works and your theme works.
There is no code showcase this week so you have more time for revision etc.
You are an analyst for a Hollywood studio. The studio wants to understand how well a movie will perform on the review website Rotten Tomatoes. They have paid you to build a model to predict the movie’s Rotten Tomatoes score.
Download the two files from Canvas which contain the data.
Imagine this is a formal report you are submitting to the Studio. You will be graded on the professionality of your final report. In all of your answers below, I expect good formatting, appropriate units and full sentences to explain your answers. Please also make sure that you use headings, sub-headings and the spell check to make your lab easier to follow and grade.
Think about using any/all of the markdown features we have learned so far, for example equations, text formatting, pictures, code-chunk options or anything else that makes your report look more professional.
The headings in the template are guidelines. If it helps to use your own or to tweak them, this is OK.
Follow the instructions below to answer their questions.
Step 1: If you skipped it, go back and read the brief above. Seriously, it will save you time. If you skipped making/copying/using the lab report template, go back and do it - or these instructions will not make sense Tutorial 5.
Step 2: Read the data into R. In the Data Description
and Study Aim
sections, use the first part of the teaching notes to help you write about the following:
There are also guidelines in the template. You do NOT need to repeat yourself, so ignore/delete any prompts you have already done or refer to it in your answers e.g. “As shown in the histogram above….”.
Step 3: Under Exploratory Analysis | Response Variable
in your report, explore your response variable and describe it in the report, working through page 4-6 of the teaching notes (Step 2) and commenting on all the questions. E.g. if there are no outliers, SAY there are no outliers (Step 2).
Again, there are additional hints in the template - you do not need to answer things twice.
Hint: There is DEFINITELY something wrong with this data that needs addressing.
Hint: For full marks, plots like histograms should have proper x and y axis labels and titles. All the tutorial examples in Tutorial 7 can be copy/pasted, why not choose a more sophisticated one..
Step 4: Download/Install theggcorrplot
package and add it to your library code chunk (remember to re-run!). Inside
Exploratory analysis, make a new sub-section called
Correlation. Use the
ggcorrmat` command to create a plot https://indrajeetpatil.github.io/ggstatsplot/articles/web_only/ggcorrmat.html. The most common errors here are that you are missing another package. If so, install that package, and re-run. Repeat for each package needed until the error goes away. Note, look at the help file and online tutorials for loads of color and style options.
Step 5: Use the correlation plot to describe the relationship between your response variable and each of your predictors. Which predictors do you think will have the strongest impact on a movie’s Rotten Tomatoes score. If it helps to make individual scatterplots with your response to see the relationship, feel free!
Step 6: Set up a multiple regression model. Under Model 1:
Fit a full multiple regression model to the data, with RottenTomatoes as your response and ALL of the other variables as your predictors. Hint, if you haven’t already done this, first remove the TEST_TEST movie row from the excel file and re-run.
Show the model summary
Use equatiomatic or any other method to formally write out the equation and coefficients.
Clearly interpret each of the estimated model parameters (slope & intercept)/model summary-statistics in the the context of the problem, in a way that would be understandable to your customer.
By this I mean explain what the slopes and intercept means in term of Rotten Tomatoes scores, highlighting if this is useful or nonsensical (like knowing weight of someone with zero height is not useful).
State the percentage of variability in Rotten Tomatoes score is explained by your model, and exactly which statistic you chose for this.
Step 7: Under Model Validity
, use Tutorial 12 to help you formally assess each LINE assumption for model 1. Comment if it meets the requirements for simple linear regression, referring back to your plots. Remember this is the same as for a simple linear model!
Step 8: Use Tutorial 14 on outliers to assess if any movie appears to be an influential outlier. If a movie does fit the criteria of influential outlier, do not remove anything from the dataset. Instead, in your write-up, please provide its name and justify why you think it is influential.
Step 9: Write a hypothesis test using the F-Statistic/ANOVA to test whether our model contains at least one predictor useful in predicting Rotten Tomatoes score.
Step 10: Partial Slopes
“The test-results for partial slopes” is a fancy way of saying “look at the T-test result and corresponding p-value of each variable in the model summary”. Essentially, they are the likelihood of that variable being an important part of the model IF EVERYTHING ELSE WAS HELD CONSTANT.
By looking at the test results for the partial slopes (at a 10% level of significance), identify any predictor variable/s you would like to drop/delete from your model. Provide reasons for your choice(s). Does this meet your expectations from the correlation matrix? You do not have to write down any steps for hypothesis testing here, but you do need to justify your decision.
Note, there might be quite a few things you decide to drop..
Step 11: Let’s make a better model. Under Model 2:
Step 12: Compare Model 1 and Model 2 using \(AdjR^2\) and AIC. Which model do you consider to be a better fit and why?
Step 13: The studio has just trialed a new movie with details:
Variable Name | Value |
---|---|
Name | “Hunt of the Killer Cactus” |
AudienceScore | 59% |
TheatersOpenWeek | 15 cinemas |
BOAverageOpenWeek | $5200 |
Budget | 43 Million |
DomesticGross | 16.38 million USD |
Profitability | 150% of the budget recovered in profits |
Under prediction (or the appropriate subheading in model 2), estimate this new movie’s Rotten Tomatoes score? Show the 99% range of uncertainty on your estimate.
Hint, this is similar code to Tutorial 13 on confidence/prediction intervals. To see a worked example and code for multiple regression, see here. https://online.stat.psu.edu/stat501/lesson/r-help-7-mlr-estimation-prediction-model-assumptions
Step 14: Find the “optimum”/“best model. There are many models/combinations of predictors that we could use to predict our response variable. We want to find the best model possible, but we also don’t want to overfit.
So far, we manually compared two models. In fact there is a way to compare all the combinations of predictors. This is using the ols_step_best_subset()
command. Run this on your ORIGINAL linear model fit (Model1, the one including all the variables). e.g. ols_step_best_subset(mymodel)
.
Describe what the “best subset” method is doing. Hint, we will go over this in lectures, but also https://online.stat.psu.edu/stat501/lesson/10/10.3
Use the subset method to assess the optimal fit using at least 3 goodness of fit measures. Which model is your final favourite. Fit the model and take a quick look at LINE assumptions but you don’t need to find a new model if it’s not valid (just talk about what you find)
Why are there suddenly variables in your “best” model that you would have dropped from your original model in Step 10.
No show me something new so you can focus on revision/exams.
Remember to save your work throughout and to spell check your writing (next to the save button).
Now, press the knit button for the final time.
If you have not made any mistakes in the code then R should create a html file in your lab 7 folder which includes your answers. If you look at your lab 7 folder, you should see this there - complete with a very recent time-stamp. In that folder, double click on the html file. This will open it in your browser. CHECK THAT THIS IS WHAT YOU WANT TO SUBMIT.
If you are on R studio cloud, see Tutorial 1 for how to download your files Now go to Canvas and submit BOTH your html and your .Rmd file in Lab 7.
See the table below for what this means - 100% is hard to get!
HTML FILE SUBMISSION - 10 marks
RMD CODE SUBMISSION - 5 marks
Professional report 15 MARKS
Full marks for a report that I would take into a job interview. You have done things like fully labeled plots using words, tried more sophisticated plots than just the basics, written full paragraphs/sentences, used equation formats, sub-headings, used spell check, explained results in clear language, included units, used a theme and table of contents.. Lose marks for each thing that makes it look non-professional.
Describe the data and EDA - 10 MARKS
You have explored the data using the guide, conducted quality control where you removed the observation that was clearly wrong and written up your results clearly. You have created the correlation matrix plot and sensitively described the relationship between your response and your predictors.
First model - 10 MARKS
You created the model correctly. In your write up you have summarised the model equation (including the coefficients as numbers) & summarising units afterwards. You have produced a model summary and written how much variability in the Rotten Tomatoes score is explained by your model.
LINE and outliers- 10 MARKS
You have clearly assessed whether the model meets LINE assumptions (2 for each). You have assessed whether there are outliers and whether they are influential. You have identified any movies which are influential.
Model Fit - 10 MARKS
You have correctly conducted a hypothesis test to assess model fit. You have assessed which variables do not add to the model using partial slopes.
New model, making the model - 10 MARKS
You have correctly refitted and interpreted the model. You have compared the models using 3 goodness of fit metrics
Prediction - 10 MARKS
You have correctly predicted the rotten tomatoes score of Hunt of the killer cactus.
Stepwise - 10 MARKS
You have found the “optimal model” and commented on what the best subset command is doing,.
See above
[100 marks total]
Overall, here is what your lab should correspond to: