# A Step-by-Step Guide to Data Analysis for Pizza Restaurants with R

In this guide, we invite you to join us on a data analysis adventure centered around the delightful world of pizza. Together, we'll explore a dataset that provides insights into the inner workings of a pizza restaurant. By harnessing the capabilities of the R programming language and utilizing various libraries, we will meticulously unravel the data. Our goal is to gain a profound understanding of the pizza industry's nuances and uncover valuable insights. To achieve this, we've broken down the entire analysis into manageable blocks, each serving a specific purpose. So, let's embark on this flavorful journey and dissect the code used for this analysis, step by step. Whether you're a data enthusiast or a pizza lover, you're sure to find this exploration both educational and mouthwatering.

## Pizza Data Analysis with R

Explore our comprehensive guide on data analysis with R for pizza restaurants. Whether you're a restaurateur looking to optimize operations or a data enthusiast, our resource can help with your R assignment by providing valuable insights and real-world examples for restaurant success. Dive into the world of pizza data analytics and discover how this knowledge can drive better decision-making, enhance customer experiences, and boost your pizzeria's profitability. Join us on this journey to harness the full potential of your pizza business with data analysis.

``````R library(tidyverse) library(lm.beta) pizza <- read_csv('pizza.csv') ``` ```
• In this block, the code loads necessary libraries, including `tidyverse` and `lm.beta`, which are widely used for data manipulation and linear modeling.
• It then reads a CSV file named 'pizza.csv' and stores the data in the 'pizza' variable.

## Block 2: Calculate Correlation - Q1

``````R Q1 <- cor(pizza[c("temperature", "bill", "pizzas", "got_wine")]) Q1 <- round(Q1, 2) Q1 ``` ```
• This block calculates the correlation (Q1) between 'temperature,' 'bill,' 'pizzas,' and 'got_wine' columns of the dataset.
• It rounds the correlation values to two decimal places.
• The result (Q1) is displayed.

## Block 3: Filter Data and Calculate Correlation - Q2

``````R new_data <- pizza %>% filter(operator == "Laura" & branch == "East") Q2 <- cor(new_data[c("time", "temperature", "bill", "pizzas")]) Q2 <- round(Q2, 2) Q2 ``` ```
• This block filters the 'pizza' dataset to only include records where 'operator' is 'Laura' and 'branch' is 'East,' and stores the result in 'new_data.'
• It then calculates the correlation (Q2) between 'time,' 'temperature,' 'bill,' and 'pizzas' in the filtered dataset.
• The correlation values are rounded to two decimal places, and the result (Q2) is displayed.

## Block 4: Logistic Regression Model - Q3

``````R lm_model_fit <- glm(got_wine ~ temperature + bill + pizzas, pizza, family = "binomial") Q3 <- summary(lm_model_fit) Q3 <- Q3\$coefficients Q3 <- round(Q3, 2) Q3 ``` ```
• This block fits a logistic regression model using the 'glm' function. The model predicts 'got_wine' based on 'temperature,' 'bill,' and 'pizzas.'
• It retrieves the summary of the model, extracts the coefficient information, rounds the coefficients to two decimal places, and displays the result (Q3).

## Block 5: Linear Regression Model - Q4 and AIC Calculation - Q5

``````R lm_model_fit2 <- lm(bill ~ temperature + pizzas + got_wine, pizza) summary_object = summary(lm_model_fit2) Q4 = lm.beta(lm_model_fit2) Q4 = Q4\$standardized.coefficients lm_model_fit3 <- lm(bill ~ temperature + pizzas + got_wine + operator, pizza) AIC_Ob = AIC(lm_model_fit3, lm_model_fit2) Q5 = min(AIC_Ob\$AIC) ``` ```
• This block fits a linear regression model to predict 'bill' based on 'temperature,' 'pizzas,' and 'got_wine.'
• It calculates standardized coefficients using the 'lm.beta' function and stores them in 'Q4.'
• It fits another linear regression model that includes 'operator' as a predictor for 'bill.'
• It calculates AIC (Akaike Information Criterion) to compare model fits and stores the minimum AIC value in 'Q5.'

## Block 6: Additional Data Analysis

``````R library(tidyverse) pizza <- read_csv('pizza.csv') Q1 <- pizza %>% filter(free_wine == 1 & discount_customer == 1 & pizzas > 4) %>% select(driver) Q1 <- data.frame(Q1) Q1 Q2 = pizza %>% mutate("ratio" = bill/pizzas) temp = mean(Q2\$ratio) Q2 = round(temp,2) Q2 Q3 <- pizza %>% group_by(day) %>% summarise("var_pizzas" = var(pizzas)) %>% select(day, var_pizzas) var_pizzas = Q3 var_pizzas Q4 <- pizza %>% group_by(operator) %>% summarise("mean_bill" = mean(bill)) %>% arrange(desc(mean_bill)) %>% head(1) %>% select(operator) Q4 new_data <- pizza %>% group_by(day, driver) %>% summarise("n" = sum(free_wine)) %>% arrange(desc(n)) Q5 = new_data[1,] Q5\$n <- as.integer(Q5\$n) Q5 ``` ```
• In this block, the code reloads the 'pizza' dataset.
• It performs various data analysis tasks such as filtering data based on specific conditions, calculating the mean 'ratio' of 'bill' to 'pizzas,' calculating the variance of 'pizzas' by day, finding the operator with the highest mean 'bill,' and more.
• The results of these analyses are stored in variables Q1, Q2, Q3, Q4, and Q5, and they are displayed.

## Conclusion

In conclusion, this data analysis journey through the world of pizza using R has shed light on the multifaceted aspects of running a pizza restaurant. By breaking down the process into distinct blocks, we've uncovered valuable insights, ranging from customer preferences and operational efficiencies to predictive modeling for optimizing sales and customer experience. This guide provides a comprehensive understanding of how data analysis can enhance decision-making in the pizza industry, making it a valuable resource for restaurateurs and data enthusiasts alike. So, armed with the knowledge gained here, let's continue to savor the success of the pizza business, one delicious insight at a time.