Assignment 5 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 5. If you are stuck, see previous labs or Tutorial 2.1.
Step B: Copy your lab template to your lab 4 folder, rename as STAT-462_Lab5_EMAILID.Rmd
and open (e.g.STAT-462_Lab5_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 command 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
## 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.
IF YOU IGNORED THE STEPS ABOVE GO BACK AND DO THEM! You lose marks for things like no theme, poor headings (remember there is a space between the # and the text), or accidentally printing out package loading text.
Step 1: Describe the LINE assumptions for your client in plain language and why each is important.
Step 2: Go to https://stephenturner.github.io/drawmydata/. Create and save 3 datasets into your Lab 5 folder. Read all of them into R and assign to testdata1, testdata2 and testdata3. Consider making a scatterplot… (hint, if your column names have messed up, think about what we did in Lab 4 to adjust them)
To make life easy for yourself, think about how many data points makes a reasonable regression (e.g. as we are modelling our response, how many would you need for a reasonable histogram..). Too few points will make your job impossible.
Step 3: Use NEW TUTORIAL, [Tutorial 12](Tutorial 12, and https://online.stat.psu.edu/stat501/lesson/4 to assess the LINE assumptions for your three datasets. For independence especially, you do not have to run every plot, you can simply talk about if you are concerned about this.
Imagine this is a real report you are submitting to an advertising company. 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.
Houseplants are now very popular. You have been hired by an advertising executive who has been collecting data on how well their marketing campaigns have been running.
They have run 200 marketing campaigns over the last few years. For each one, they recorded:
The company wish to know which type of advertising campaigns are the most effective.
Follow the instructions below to answer their questions.
IF YOU ARE AN HONORS STUDENT USE YOUR OWN DATA FROM THE FIRST PART OF THE SEMESTER. Choose who you are writing your report for, your dataset and response, then work through
Step 1: If you skipped it, go back and read the brief above. Seriously, it will save you time.
Step 2: 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 3: 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 anything you have already done or refer to it in your answers e.g. “As shown in the histogram above….”.
Step 4: 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: 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 5: Under Exploratory analysis
, make a new sub-section called Correlation
. Make a correlation plot of the variables against your response See Tutorial 6.4.
CLARIFICATION: Which predictor has the smallest and largest correlation vs your response?
IF YOU ARE AN HONORS STUDENT, choose two likely predictor variables for your response and make your two models for those
Your client wishes to know which advertising campaign is the most effective out of.
To do this, we are going to create and compare TWO models. Adjust your report headings to look like this
Step 6: FOR BOTH MODELS, under model fitting
use Tutorial 8 and Tutorial 9 to help you:
Step 7: Use the NEW TUTORIAL, Tutorial 12 to help you assess each LINE assumption for BOTH model 1 and model 2. For each model, comment if it meets the requirements for simple linear regression, referring back to the diagnostic plots.
Step 8: Under Comparing models
, refer to your analysis (or do new analysis as appropriate) to answer the following questions.
Out of model 1 and model 2, where do you see the greatest increase in sales if you increase the advertising budget?
Provide evidence to justify your answer (thinking about uncertainties on your estimate).
Which model explains the most variability in the sales data? Provide evidence to justify your answer.
Step 9: Under Customer questions
, refer to your analysis (or do new analysis as appropriate) to answer the following questions.
Peace lily dilemma: Your customer has a client who needs to sell 8000 “peace lily” plants but hates newspapers. Conduct an hypothesis test to assess whether you typically sell less than 8000 plants in a situation where you spend zero-money on newspaper advertising. You are happy to be wrong one time in 25. Advise the company whether is OK to stop advertising in newspapers. (Monday’s lecture notes and worked example here: https://online.stat.psu.edu/stat501/lesson/2/2.12)
TV fears: Another client is skeptical of TV. Use the ANOVA table output to conduct a hypothesis test to examine if there is evidence to suggest a relationship between TV advertising and plant sales, with a critical significance of 1%. (Fridays lecture or see a worked example here: https://online.stat.psu.edu/stat501/lesson/2/2.7). See Tutorial 9.3 for the ANOVA code or Monday’s lecture..
Best day ever: A new client has approached the company with a brand new plant!!! (the rainbow-monstera-fig). This is very popular. The magazine “Plants Daily” rates its popularity at 70%!
Thinking about the plant popularity independently of advertising type, what is the predicted range of sales for your new campaign? (at a 99% confidence level). Note, you may need to make a section for a new model… NEW TUTORIAL - Tutorial 13 Confidence and Prediction intervals (Also Friday’s lecture or worked example here. https://online.stat.psu.edu/stat501/lesson/3).
If you are stuck on 3, think about the difference between a confidence interval and a prediction interval using the resources or google (or Lab 4..)
IF YOU ARE AN HONORS STUDENT, for step 9:
a) Conduct a hypothesis test on either the intercept or the slope against a value that would be appropriate.
b) Conduct an F test using the ANOVA table on either model 1 or model 2. c) Create a prediction interval for a new data point
Step 10: Under Conclusions
, summarise for the customer what you have learned. Explain how multiple regression might have allowed you to conduct a better analysis.
Remember that an A is 94%, so you can ignore this section and still easily get an A. But here is your time to shine. Also, if you are struggling in another part of the lab, you can use this to gain back points.
To get the final 5 marks in the lab, you need to show me something new, e.g. you need to go above and beyond the lab questions in some way.
Here are some ideas:
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 5 folder which includes your answers. If you look at your lab 5 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 5.
See the table below for what this means - 100% is hard to get!
HTML FILE SUBMISSION - 10 marks
RMD CODE SUBMISSION - 10 marks
CODE SHOWCASE 30 MARKS
HOUSEPLANT DATA 1: 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.
HOUSEPLANT DATA 2: Exploratory Analysis and Study Aim 10 MARKS
You have clearly and neatly explored and written up your study aim and exploratory data analysis
HOUSEPLANT DATA 3: Making models Aim 10 MARKS
You have successfully completed steps 6 - 8
HOUSEPLANT DATA 4: Answering questions 15 MARKS
You have managed to answer each of the questions in step 9 (5 for each)
SHOW ME SOMETHING NEW: 5 MARKS
See above
[100 marks total]
Overall, here is what your lab should correspond to: