AE 07: Exam 01 review

Restaurant tips

Published

September 28, 2022

Important

Go to the course GitHub organization and locate your ae-07- to get started.

The AE is due on GitHub by Saturday, October 01 at 11:59pm.

Packages

library(tidyverse)
library(tidymodels)
library(knitr)

Restaurant tips

What factors are associated with the amount customers tip at a restaurant? To answer this question, we will use data collected in 2011 by a student at St. Olaf who worked at a local restaurant.1

The variables we’ll focus on for this analysis are

  • Tip: amount of the tip
  • Party: number of people in the party
  • Alcohol: whether alcohol was purchased with meal

View the data set to see the remaining variables.

tips <- read_csv("data/tip-data.csv")

Exploratory analysis

  1. Visualize, summarize, and describe the relationship between Party and Tip.
# add your code here

Modeling

Let’s start by fitting a model using Party to predict the Tip at this restaurant.

  1. Write the statistical model.

  2. Fit the regression line and write the regression equation. Name the model tips_fit and neatly display the results with 3 digits and the 95% confidence interval for the coefficients.

# add your code here
  1. Interpret the slope.

  2. Does it make sense to interpret the intercept? Explain your reasoning.

Inference

Inference for the slope

  1. The following code can be used to create a bootstrap distribution for the slope (and the intercept, though we’ll focus primarily on the slope in our inference). Describe what each line of code does, supplemented by any visualizations that might help with your description.
set.seed(1234)

boot_dist <- tips |>
  specify(Tip ~ Party) |>
  generate(reps = 100, type = "bootstrap") |>
  fit()
  1. Use the bootstrap distribution created in Exercise 6, boot_dist, to construct a 90% confidence interval for the slope using bootstrapping and the percentile method and interpret it in context of the data.
# add your code here
  1. Conduct a hypothesis test at the equivalent significance level using permutation with 100 reps. State the hypotheses and the significance level you’re using explicitly. Also include a visualization of the null distribution of the slope with the observed slope marked as a vertical line.
set.seed(1234)
# add your code here
  1. Check the relevant conditions for Exercises 7 and 8. Are there any violations in conditions that make you reconsider your inferential findings?
# add your code here
  1. Now repeat Exercises 7 and 8 using approaches based on mathematical models. You can reference output from previous exercises and/or write new code as needed.

  2. Check the relevant conditions for Exercise 10. Are there any violations in conditions that make you reconsider your inferential findings? You can reference previous graphs / conditions and add any new code as needed.

# add your code here

Inference for a prediction

  1. Based on your model, predict the tip for a party of 4.
# add your code here
  1. Suppose you’re asked to construct a confidence and a prediction interval for your finding in the previous exercise. Which one would you expect to be wider and why? In your answer clearly state the difference between these intervals.

  2. Now construct the intervals and comment on whether your guess is confirmed.

# add your code here

Multiple linear regression

  1. Make a plot to visualize the relationship between Party and Tip with the points colored by Alcohol. Describe any patterns that emerge.
# add your code here
  1. Fit a multiple linear regression model predicting Tip from Party and Alcohol. Display the results with kable() and three digits.
# add your code here
  1. Interpret the coefficients of Party and Alcohol.

  2. According to this model, is the rate of change in tip amount the same for various sizes of parties regardless of alcohol consumption or are they different? Explain your reasoning.

Important

To submit the AE:

  • Render the document to produce the PDF with all of your work from today’s class.
  • Push all your work to your ae-07- repo on GitHub. (You do not submit AEs on Gradescope).

Footnotes

  1. Dahlquist, Samantha, and Jin Dong. 2011. “The Effects of Credit Cards on Tipping.” Project for Statistics 212-Statistics for the Sciences, St. Olaf College.↩︎