Introduction

In this project I will use the McDonald’s menu to observe the overall calorie value of different menu item combinations. I will analyze the composition of the various combinations that will allow an average person to stay within a certain calorie threshold.

Brief History of the McDonald’s Corporation

The McDonald’s Corporation started as a single restaurant owned by the brothers Dick and Mac McDonald. Ray Kroc was a paper cup and Multimixer salesman who visited the brothers’ restaurant after they made a large Multimixer purchase. The brothers expressed to Ray Kroc interest in obtaining a new franchise agent. Ray Kroc took the opportunity and formed a partnership with the brothers and founded McDonald’s System incorporated in 1955. In 1960, the company was renamed McDonald’s Corporation.

Question

What would be the composition of a combo meal that an average person could order at McDonald’s while staying under their maintenance calorie threshold? How would the composition of a combo change if the average person wanted to eat McDonald’s while they were trying to lose ten percent of their body weight in six months?

The calorie count in is this project was calculated by using Body Weight Planner calculator provided by the National Institute of Diabetes and Digestive and Kidney Diseases. The average height and weight measurements for males and females were acquired through the Centers for Disease Control and Prevention. The activity levels for leisure time will be set to Moderate since 53% of adults age eighteen and over met the physical activity guidelines for aerobic physical activity according to the Centers for Disease Control and Prevention. The activity levels for work or school will be set to Very Light. The age will be set to 30 years old.

Average Male Age: 30 Height: 5ft 9in Weight: 199.8lb Activity at work or school: Very Light Activity at leisure time: Moderate Maintenance Calories: 2,973 Calories/day Drop 10% in 6 months: 2,431 Calories/day

Average Female Age: 30 Height: 5ft 4in Weight: 170.8lb Activity at work or school: Very Light Activity at leisure time: Moderate Maintenance Calories: 2,370 Calories/day Drop 10% in 6 months: 1,908 Calories/day

Required Libraries

#Load required packages
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.0.5
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.1.1     v dplyr   1.0.6
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## Warning: package 'tibble' was built under R version 4.0.5
## Warning: package 'tidyr' was built under R version 4.0.5
## Warning: package 'stringr' was built under R version 4.0.4
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()

Setup Workstation

#Setup work directory
setwd("C:/Users/mivul/OneDrive/Desktop/Data 110/Datasets")
#Upload McDonald menu csv file
mcd <-read.csv("menu.csv")

Dataset

The McDonanld’s menu dataset was acquired from https://www.kaggle.com/mcdonalds/nutrition-facts.

Data Description

The McDonald’s menu dataset consists of 25 variables and 260 observations. The observations are the individual menu items offered at the restaurant. The variables are the nutritional information for each item.

#Observe dataset structure
str(mcd)
## 'data.frame':    260 obs. of  24 variables:
##  $ Category                     : chr  "Breakfast" "Breakfast" "Breakfast" "Breakfast" ...
##  $ Item                         : chr  "Egg McMuffin" "Egg White Delight" "Sausage McMuffin" "Sausage McMuffin with Egg" ...
##  $ Serving.Size                 : chr  "4.8 oz (136 g)" "4.8 oz (135 g)" "3.9 oz (111 g)" "5.7 oz (161 g)" ...
##  $ Calories                     : int  300 250 370 450 400 430 460 520 410 470 ...
##  $ Calories.from.Fat            : int  120 70 200 250 210 210 230 270 180 220 ...
##  $ Total.Fat                    : num  13 8 23 28 23 23 26 30 20 25 ...
##  $ Total.Fat....Daily.Value.    : int  20 12 35 43 35 36 40 47 32 38 ...
##  $ Saturated.Fat                : num  5 3 8 10 8 9 13 14 11 12 ...
##  $ Saturated.Fat....Daily.Value.: int  25 15 42 52 42 46 65 68 56 59 ...
##  $ Trans.Fat                    : num  0 0 0 0 0 1 0 0 0 0 ...
##  $ Cholesterol                  : int  260 25 45 285 50 300 250 250 35 35 ...
##  $ Cholesterol....Daily.Value.  : int  87 8 15 95 16 100 83 83 11 11 ...
##  $ Sodium                       : int  750 770 780 860 880 960 1300 1410 1300 1420 ...
##  $ Sodium....Daily.Value.       : int  31 32 33 36 37 40 54 59 54 59 ...
##  $ Carbohydrates                : int  31 30 29 30 30 31 38 43 36 42 ...
##  $ Carbohydrates....Daily.Value.: int  10 10 10 10 10 10 13 14 12 14 ...
##  $ Dietary.Fiber                : int  4 4 4 4 4 4 2 3 2 3 ...
##  $ Dietary.Fiber....Daily.Value.: int  17 17 17 17 17 18 7 12 7 12 ...
##  $ Sugars                       : int  3 3 2 2 2 3 3 4 3 4 ...
##  $ Protein                      : int  17 18 14 21 21 26 19 19 20 20 ...
##  $ Vitamin.A....Daily.Value.    : int  10 6 8 15 6 15 10 15 2 6 ...
##  $ Vitamin.C....Daily.Value.    : int  0 0 0 0 0 2 8 8 8 8 ...
##  $ Calcium....Daily.Value.      : int  25 25 25 30 25 30 15 20 15 15 ...
##  $ Iron....Daily.Value.         : int  15 8 10 15 10 20 15 20 10 15 ...

Variable Description

Category: Food category food item is assigned

Item: Name of food item

Serving Size: Food item serving size measured in ounces or fluid ounces

Calories: Amount of calories in kilocalories in food item

Calories from Fat: Amount of calories from fat in kilocalories in food item

Total Fat: Amount of total fat in grams in food item

Total Fat (% Daily Value): Level of total fat in a standard serving of food in relation to the Food and Drug Administration’s (FDA) approximate requirement for daily fat intake.

Saturated Fat: Amount of saturated fat in grams in food item

Saturated Fat (% Daily Value): Level of saturated fat in a standard serving of food relation to the FDA’s approximate requirement for daily saturated fat intake.

Trans Fat: Amount of trans fat in grams in food item

Cholesterol: Amount of cholesterol in milligrams in food item

Cholesterol (% Daily Value): Level of cholesterol in a standard serving of food in relation to the FDA’s approximate requirement for daily cholesterol intake.

Sodium: Amount of sodium in milligrams in food item

Sodium (% Daily Value):Level of sodium in a standard serving of food in relation to the FDA’s approximate requirement for daily sodium intake.

Carbohydrates: Amount of carbohydrates in grams in food item

Carbohydrates (% Daily Value): Level of carbohydrates in a standard serving of food in relation to the FDA’s approximate requirement for daily carbohydrate intake.

Dietary Fiber: Amount of dietary fiber in grams in food item

Dietary Fiber (% Daily Value):Level of dietary fiber in a standard serving of food in relation to the FDA’s approximate requirement for daily dietary fiber intake.

Sugars: Amount of sugar in grams in food item

Protein: Amount of protein in grams in food item

Vitamin A (% Daily Value): Level of vitamin A in a standard serving of food in relation to the FDA’s requirement for it.

Vitamin C (% Daily Value): Level of vitamin C in a standard serving of food in relation to the FDA’s approximate requirement for it.

Calcium (% Daily Value): Level of calcium in a standard serving of food in relation to the FDA’s approximate requirement for it.

Iron (% Daily Value): Level of iron in a standard serving of food in relation to the FDA’s approximate requirement for it.

The percent daily value definitions were obtained from the National Institutes of Health. The unit measurements for the variables were obtained from a nutritional fact sheet from McDonald’s USA.

Data Preperation

To analyze combinations of menu items, We will use the dataset to conduct simulations of possible orders consisting of three distinct menu items. Due to McDonald’s currently suspending all day breakfast service, we will create two separate tables for the breakfast menu and the dinner menu.

#Create tibble with only breakfast items
breakfast <- mcd %>%
  #filter to remove categories not offered during breakfast
  filter(Category != "Beef & Pork") %>%
  filter(Category != "Chicken & Fish") %>%
  filter(Category != "Salads") %>%
  #filter to remove menu items not offered during breakfast which are in categories with breakfast items
  filter(!Item %in% c("Chipotle BBQ Snack Wrap (Crispy Chicken)", "Chipotle BBQ Snack Wrap (Grilled Chicken)", "Honey Mustard Snack Wrap (Crispy Chicken)", "Honey Mustard Snack Wrap (Grilled Chicken)",
"Ranch Snack Wrap (Crispy Chicken)",
"Ranch Snack Wrap (Grilled Chicken)",
"Small French Fries",
"Medium French Fries",
"Large French Fries",
"Kids French Fries",
"Side Salad",
"Fruit 'n Yogurt Parfait", "Kids Ice Cream Cone",
"Hot Fudge Sundae",
"Hot Caramel Sundae",
"Strawberry Sundae",
"Vanilla Shake (Small)",
"Vanilla Shake (Medium)",
"Vanilla Shake (Large)",
"Strawberry Shake (Small)",
"Strawberry Shake (Medium)",
"Strawberry Shake (Large)",
"Chocolate Shake (Small)",
"Chocolate Shake (Medium)",
"Chocolate Shake (Large)",
"Shamrock Shake (Medium)",
"Shamrock Shake (Large)",
"McFlurry with M&M’s Candies (Small)",
"McFlurry with M&M’s Candies (Medium)",
"McFlurry with M&M’s Candies (Snack)",
"McFlurry with Oreo Cookies (Small)",
"McFlurry with Oreo Cookies (Medium)",
"McFlurry with Oreo Cookies (Snack)",
"McFlurry with Reese's Peanut Butter Cups (Medium)",
"McFlurry with Reese's Peanut Butter Cups (Snack)"))
  
#Create tibble with only dinner items
dinner <- mcd %>%
  filter(Category != "Breakfast")

A tibble was created without the category variable. The tibble will be used to conduct an inner join with the combination tibble to append the nutritional information values for each combination.

#Create table to conduct join to acquire nutritional information
mcd_cal_item<- mcd%>%
  select(!Category)

The combination function is utilized on the dinner and breakfast tibbles to create orders consisting of three items.

memory.limit(size = 5600)
## Warning in memory.limit(size = 5600): cannot decrease memory limit: ignored
## [1] 16134
#Conduct dinner combinations of m number of values from the item vector 
dinner_combo <- combn(m=3,x=dinner$Item)


#Transpose matrix to align combinations by row instead of columns
t_dinner_combo <- t(dinner_combo)

#convert matrix to a tibble
df_dinner_combo <- as_tibble(t_dinner_combo)
## Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if `.name_repair` is omitted as of tibble 2.0.0.
## Using compatibility `.name_repair`.
#Conduct inner join to append the nutritional variables for each item in the menu tibble
dinner_menu<- df_dinner_combo %>%
inner_join(mcd_cal_item, by = c( "V1"= "Item")) %>%
  inner_join(mcd_cal_item, by = c( "V2"= "Item")) %>%
  inner_join(mcd_cal_item, by = c( "V3" = "Item"))

#Calculate the total nutritional variables for each combination
dinner_menu_calories <-dinner_menu %>%
  group_by(V1, V2, V3) %>%
  summarise(total_calories = Calories.x + Calories.y + Calories, total_sugar = Sugars.x + Sugars.y + Sugars, total_sodium = Sodium.x + Sodium.y + Sodium, total_fat = Total.Fat.x + Total.Fat.y + Total.Fat, total_cholesterol =  Cholesterol.x + Cholesterol.y + Cholesterol, total_carbohydrates = Carbohydrates.x + Carbohydrates.y + Carbohydrates, total_protein= Protein.x + Protein.y + Protein, total_dietary_fiber = Dietary.Fiber.x + Dietary.Fiber.y + Dietary.Fiber)
## `summarise()` has grouped output by 'V1', 'V2'. You can override using the `.groups` argument.
#Conduct breakfast combinations of m number of values from the item vector 
breakfast_combo <- combn(m=3,x=breakfast$Item)


#Transpose matrix to align combinations by row instead of columns
t_breakfast_combo <- t(breakfast_combo)

#convert matrix to a tibble
df_breakfast_combo <- as_tibble(t_breakfast_combo)

#Conduct inner join to append the nutritional variables values for each item in the menu tibble
breakfast_menu<- df_breakfast_combo %>%
inner_join(mcd_cal_item, by = c( "V1"= "Item")) %>%
  inner_join(mcd_cal_item, by = c( "V2"= "Item")) %>%
  inner_join(mcd_cal_item, by = c( "V3" = "Item"))

#Calculate the total nutritional variables for each combination
breakfast_menu_calories <-breakfast_menu %>%
  group_by(V1, V2, V3) %>%
  summarise(total_calories = Calories.x + Calories.y + Calories, total_sugar = Sugars.x + Sugars.y + Sugars, total_sodium = Sodium.x + Sodium.y + Sodium, total_fat = Total.Fat.x + Total.Fat.y + Total.Fat, total_cholesterol =  Cholesterol.x + Cholesterol.y + Cholesterol, total_carbohydrates = Carbohydrates.x + Carbohydrates.y + Carbohydrates, total_protein= Protein.x + Protein.y + Protein, total_dietary_fiber = Dietary.Fiber.x + Dietary.Fiber.y + Dietary.Fiber)
## `summarise()` has grouped output by 'V1', 'V2'. You can override using the `.groups` argument.

Data Exploration

The dinner and breakfast simulations resulted in 1,703,016 and 908,600 unique combinations, respectively. The equation used to calculate the combinations without replacement of an item is n!/r!(n-r)! with n equaling 218 and 177 for the number of menu items and r equaling 3 the number of items in the combination.

#Select table to view observations
dinner_menu_calories %>%
  #count number of observations
  nrow()
## [1] 1703016
#Select table to view observations
breakfast_menu_calories %>%
  #count number of observations
  nrow()
## [1] 908600

Sixty-two percent of breakfast combinations were less than or equal to 1000 calories, and fifty-three percent of dinner combinations were less than or equal to 1000 calories.

breakfast_menu_calories %>%
  #filter for meals with calories  less than or equal to 1000
  filter(total_calories <=1000) %>%
  #calculate percentage of combinations less than 1000 calories
  nrow()/908600*100
## [1] 62.04832
dinner_menu_calories %>%
  #filter for meals with calories  less than or equal to 1000
  filter(total_calories <=1000) %>%
  #calculate percentage of combinations less than 1000 calories
  nrow()/1703016*100
## [1] 53.10338

Sugar and Carbohydrates are the two highest nutritional variables for the combinations of dinner and breakfast options. The median and upper fence for fat, protein, sugar, and carbohydrates were higher for dinner combinations compared to breakfast combinations. The median level of dietary fiber was the same between dinner and breakfast combinations, but the upper fence for breakfast combinations was higher than it was for dinner combinations.

dinner_menu_calories %>%
  #transform table to move nutritional variables under the summary column and values under measurement
  pivot_longer(cols = 4:11, names_to = "summary", values_to = "measurement")%>%
  #remove variables from summary column
  filter(!summary %in% c("total_calories","total_sodium", "total_cholesterol")) %>%
  #create interactive boxplot
  ggplot(aes(x=summary, y=measurement, color = summary))+
  geom_boxplot()+
  #set labels for x-axis, y-axis, and title in layout
  xlab("Nutritional Variables")+
  ylab("Total Grams")+
  ggtitle("Dinner Nutritional Distribution")+
  theme_classic()+
  theme(legend.position = "none")

breakfast_menu_calories %>%
    #transform table to move nutritional variables under the summary column and values under measurement
  pivot_longer(cols = 4:11, names_to = "summary", values_to = "measurement")%>%
  #remove variables from summary column
  filter(!summary %in% c("total_calories", "total_sodium", "total_cholesterol")) %>%
 #create interactive boxplot
  ggplot(aes(x=summary, y=measurement, color = summary))+
  geom_boxplot()+
  #set labels for x-axis, y-axis, and title in layout
  xlab("Nutritional Variables")+
  ylab("Total Grams")+
  ggtitle("Breakfast Nutritional Distribution")+
  theme_classic()+
  theme(legend.position = "none")

The median levels for sodium and cholesterol are higher in dinner combinations, but the upper fence is higher for breakfast combinations.

dinner_menu_calories %>%
   #transform table to move nutritional variables under the summary column and values under measurement
  pivot_longer(cols = 4:11, names_to = "summary", values_to = "measurement")%>%
  #filter for selected variables 
  filter(summary %in% c("total_sodium","total_cholesterol")) %>%
 #create interactive boxplot
  ggplot(aes(x=summary, y=measurement, color = summary))+
  geom_boxplot()+
  #set labels for x-axis, y-axis, and title in layout
  xlab("Nutritional Variables")+
  ylab("Total Milligrams")+
  ggtitle("Dinner Nutritional Distribution")+
  theme_classic()+
  theme(legend.position = "none")

breakfast_menu_calories %>%
   #transform table to move nutritional variables under the summary column and values under measurement
  pivot_longer(cols = 4:11, names_to = "summary", values_to = "measurement")%>%
  #filter for selected variables 
  filter(summary %in% c("total_sodium","total_cholesterol")) %>%
    #create interactive boxplot
 #create interactive boxplot
  ggplot(aes(x=summary, y=measurement, color = summary))+
  geom_boxplot()+
  #set labels for x-axis, y-axis, and title in layout
  xlab("Nutritional Variables")+
  ylab("Total Milligrams")+
  ggtitle("Breakfast Nutritional Distribution")+
  theme_classic()+
  theme(legend.position = "none")

The median and upper fence calorie value is higher for dinner combinations compared to breakfast combinations.

dinner_menu_calories %>%
  #transform table to move nutritional variables under the summary column and values under measurement
  pivot_longer(cols = 4:11, names_to = "summary", values_to = "measurement")%>%
  #filter for selected variables
  filter(summary == "total_calories") %>%
  #create interactive boxplot
 #create interactive boxplot
  ggplot(aes(x=summary, y=measurement, color = summary))+
  geom_boxplot()+
  #set labels for x-axis, y-axis, and title in layout
  xlab("Nutritional Variable")+
  ylab("Total Kilocalories")+
  ggtitle("Dinner Nutritional Distribution")+
  theme_classic()+
  theme(legend.position = "none")

breakfast_menu_calories %>%
  #transform table to move nutritional variables under the summary column and values under measurement
  pivot_longer(cols = 4:11, names_to = "summary", values_to = "measurement")%>%
  #filter for selected variables
   filter(summary == "total_calories") %>%
 #create interactive boxplot
  ggplot(aes(x=summary, y=measurement, color = summary))+
  geom_boxplot()+
  #set labels for x-axis, y-axis, and title in layout
  xlab("Nutritional Variable")+
  ylab("Total Kilocalories")+
  ggtitle("Breakfast Nutritional Distribution")+
  theme_classic()+
  theme(legend.position = "none")

A correlation analysis on the breakfast menu items showed a strong positive correlation between total calories, total fat, total carbohydrates and total protein. As the measurements of total calories increase, the measurements for total fat, total carbohydrates, and total protein increase.

I decided to do a multiple linear regression with total calories as the dependent variable and total fat, total carbohydrates and total protein as the independent variables. Due to total fat having a strong correlation with total protein levels, total protein was dropped from the model. The adjusted r squared is 0.9885, which is the variance of the model. Ninety-eight percent of the variation in the total calorie variable can be explained by variation in the total fat and total carbohydrates using the model.The residual graphs display the linear model is a good fit for the data.

#correlation matrix
cor(breakfast_menu_calories[c(4:11)])
##                     total_calories total_sugar total_sodium  total_fat
## total_calories           1.0000000   0.2011762    0.7645462  0.8965022
## total_sugar              0.2011762   1.0000000   -0.4109193 -0.1849721
## total_sodium             0.7645462  -0.4109193    1.0000000  0.8695403
## total_fat                0.8965022  -0.1849721    0.8695403  1.0000000
## total_cholesterol        0.6487673  -0.2132928    0.6764707  0.7476628
## total_carbohydrates      0.7971326   0.7038868    0.3134331  0.4645340
## total_protein            0.8208561  -0.1174048    0.8373570  0.7821765
## total_dietary_fiber      0.6778362  -0.1725065    0.7184265  0.6380064
##                     total_cholesterol total_carbohydrates total_protein
## total_calories              0.6487673           0.7971326     0.8208561
## total_sugar                -0.2132928           0.7038868    -0.1174048
## total_sodium                0.6764707           0.3134331     0.8373570
## total_fat                   0.7476628           0.4645340     0.7821765
## total_cholesterol           1.0000000           0.2858632     0.6398571
## total_carbohydrates         0.2858632           1.0000000     0.4795977
## total_protein               0.6398571           0.4795977     1.0000000
## total_dietary_fiber         0.4948336           0.4506196     0.6885836
##                     total_dietary_fiber
## total_calories                0.6778362
## total_sugar                  -0.1725065
## total_sodium                  0.7184265
## total_fat                     0.6380064
## total_cholesterol             0.4948336
## total_carbohydrates           0.4506196
## total_protein                 0.6885836
## total_dietary_fiber           1.0000000
#create linear model
model <- lm(total_calories ~ total_carbohydrates+total_fat, data = breakfast_menu_calories)

#view model stats
summary(model)
## 
## Call:
## lm(formula = total_calories ~ total_carbohydrates + total_fat, 
##     data = breakfast_menu_calories)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -141.729  -27.071   -0.756   26.412  159.461 
## 
## Coefficients:
##                      Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         23.721007   0.132925   178.5   <2e-16 ***
## total_carbohydrates  4.163116   0.001089  3822.2   <2e-16 ***
## total_fat           10.983483   0.002079  5283.5   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 38.92 on 908597 degrees of freedom
## Multiple R-squared:  0.9885, Adjusted R-squared:  0.9885 
## F-statistic: 3.908e+07 on 2 and 908597 DF,  p-value: < 2.2e-16
#plot model
plot(model)

Analysis

Male

The top categories are similar between the maintenance and weight loss charts. The top 3 categories for composition of the breakfast menu combinations are coffee and tea, breakfast and beverages categories. The top 3 categories for composition of the dinner menu combinations are chicken and fish, coffee and tea, and beverages.

#Filter breakfast combinations below threshold for maintenance
bfood<-breakfast_menu_calories %>%
  filter(total_calories <= 991) 

#conduct semi join on Mcdonald's menu to filter for results in the first menu option
bfood2 <-mcd %>%
  semi_join(bfood, by = c("Item" = "V1"))

#conduct semi join on Mcdonald's menu to filter for results in the second menu option
bfood3 <- mcd%>%
  semi_join(bfood, by = c("Item" = "V2")) 

#conduct semi join on Mcdonald's menu to filter for results in the third menu option
bfood4 <-mcd %>%
  semi_join(bfood, by = c("Item" = "V3")) 

bfood2 %>%
  #unit table by rows
  rbind(bfood3)%>%
  #unit table by rows
  rbind(bfood4) %>%
  distinct(Category,Item) %>%
  count(Category)%>%
  #calculate percentage of categories
  mutate(percent = n/sum(n))%>%
  ggplot(aes(x=Category,y = percent, fill = Category))+
  #plot bar graph
  geom_bar(stat = "identity")+
   coord_flip()+
  ylab("Percentage")+
  ggtitle("Male Breakfast Maintance Composition")+
  theme_classic()

#Filter dinner combinations below threshold for maintenance
dfood<-dinner_menu_calories %>%
  filter(total_calories <= 991) 

#conduct semi join on Mcdonald's menu to filter for results in the first menu option
dfood2 <-mcd %>%
  semi_join(dfood, by = c("Item" = "V1"))

#conduct semi join on Mcdonald's menu to filter for results in the second menu option
dfood3 <-mcd %>%
  semi_join(dfood, by = c("Item" = "V2")) 

#conduct semi join on Mcdonald's menu to filter for results in the third menu option
dfood4 <-mcd %>%
  semi_join(dfood, by = c("Item" = "V3")) 

dfood2 %>%
  #unit table by rows
  rbind(dfood3)%>%
  #unit table by rows
  rbind(dfood4) %>%
  count(Category)%>%
  #calculate percentage of categories
  mutate(percent = n/sum(n))%>%
  ggplot(aes(x=Category,y = percent, fill = Category))+
  #plot bar graph
  geom_bar(stat = "identity")+
   coord_flip()+
  ylab("Percentage")+
  ggtitle("Male Dinner Maintance Composition")+
  theme_classic()

#Filter breakfast combinations below threshold for weight loss
bfood5<-breakfast_menu_calories %>%
  filter(total_calories <= 810) 

#conduct semi join on Mcdonald's menu to filter for results in the first menu option
bfood6 <-mcd %>%
  semi_join(bfood5, by = c("Item" = "V1"))

#conduct semi join on Mcdonald's menu to filter for results in the second menu option
bfood7 <- mcd%>%
  semi_join(bfood5, by = c("Item" = "V2")) 

#conduct semi join on Mcdonald's menu to filter for results in the third menu option
bfood8 <-mcd %>%
  semi_join(bfood5, by = c("Item" = "V3")) 

bfood6 %>%
  #unit table by rows
  rbind(bfood7)%>%
  #unit table by rows
  rbind(bfood8) %>%
  distinct(Category,Item) %>%
  count(Category)%>%
  #calculate percentage of categories
  mutate(percent = n/sum(n))%>%
  ggplot(aes(x=Category,y = percent, fill = Category))+
  #plot bar graph
  geom_bar(stat = "identity")+
   coord_flip()+
  ylab("Percentage")+
  ggtitle("Male Breakfast Weight Loss Composition")+
  theme_classic()

#Filter dinner combinations below threshold for weight loss
dfood5<-dinner_menu_calories %>%
  filter(total_calories <= 810) 

#conduct semi join on Mcdonald's menu to filter for results in the first menu option
dfood6 <-mcd %>%
  semi_join(dfood5, by = c("Item" = "V1"))

#conduct semi join on Mcdonald's menu to filter for results in the second menu option
dfood7 <-mcd %>%
  semi_join(dfood5, by = c("Item" = "V2")) 

#conduct semi join on Mcdonald's menu to filter for results in the third menu option
dfood8 <-mcd %>%
  semi_join(dfood5, by = c("Item" = "V3")) 

dfood6 %>%
  #unit table by rows
  rbind(dfood7)%>%
  #unit table by rows
  rbind(dfood8) %>%
  count(Category)%>%
  #calculate percentage of categories
  mutate(percent = n/sum(n))%>%
  ggplot(aes(x=Category,y = percent, fill = Category))+
  #plot bar graph
  geom_bar(stat = "identity")+
   coord_flip()+
  ylab("Percentage")+
  ggtitle("Male Dinner Weight Loss Composition")+
  theme_classic()

Three of the breakfast items were excluded because they could not be combined with any other item to come below the weight maintenance calorie threshold. The average calories of these items was 1097. Four of the breakfast items were excluded because they could not be combined with any other item to come below the weight loss calorie threshold. The average calories of these items was 1070. The Big Breakfast with Hotcakes meals had the highest representation.

One of the dinner items was excluded because it could not be combined with any other item to come below the weight maintenance calorie threshold. This item had 1880 calories. Seven of the dinner items were excluded because they could not be combined with any other item to come below the weight loss calorie threshold. The average calories of these items was 1013. The shakes and chicken nuggets had the highest representation.

#breakfast weight maintenance tables
a<-bfood2 %>%
  #unit tables by rows
  rbind(bfood3)%>%
  #unit tables by rows
  rbind(bfood4)

#dinner weight maintenance tables
b<-dfood2 %>%
  #unit tables by rows
  rbind(dfood3)%>%
   #unit tables by rows
  rbind(dfood4)
  
#breakfast weight loss tables
c<-bfood6%>%
  #unit tables by rows
  rbind(bfood7)%>%
  #unit tables by rows
  rbind(bfood8)

#dinner weight loss tables
d<-dfood6%>%
  #unit tables by rows
  rbind(dfood7)%>%
  #unit tables by rows
  rbind(dfood8)


#breakfast items to avoid for weight maintenance 
breakfast%>%
  #remove items from breakfast table that are in table a
  anti_join(a, by = "Item")%>%
  select(Category,Item)
##    Category                                                       Item
## 1 Breakfast              Big Breakfast with Hotcakes (Regular Biscuit)
## 2 Breakfast                Big Breakfast with Hotcakes (Large Biscuit)
## 3 Breakfast Big Breakfast with Hotcakes and Egg Whites (Large Biscuit)
#breakfast items to avoid for weight maintenance 
breakfast%>%
  #remove items from breakfast table that are in table a
  anti_join(a, by = "Item") %>%
  #calculate average calories
  summarise(mean(Calories))
##   mean(Calories)
## 1       1096.667
#breakfast items to avoid for weight loss 
breakfast%>%
  #remove items from breakfast table that are in table c
  anti_join(c, by = "Item")%>%
  select(Category,Item)
##    Category                                                         Item
## 1 Breakfast                Big Breakfast with Hotcakes (Regular Biscuit)
## 2 Breakfast                  Big Breakfast with Hotcakes (Large Biscuit)
## 3 Breakfast Big Breakfast with Hotcakes and Egg Whites (Regular Biscuit)
## 4 Breakfast   Big Breakfast with Hotcakes and Egg Whites (Large Biscuit)
#breakfast items to avoid for weight loss 
breakfast%>%
  #remove items from breakfast table that are in table c
  anti_join(c, by = "Item")%>%
  #calculate average calories
  summarise(mean(Calories))
##   mean(Calories)
## 1           1070
#dinner items to avoid for weight maintenance 
dinner%>%
  #remove items from dinner table that are in table b
  anti_join(b, by = "Item")%>%
  select(Category,Item)
##         Category                         Item
## 1 Chicken & Fish Chicken McNuggets (40 piece)
#dinner items to avoid for weight maintenance 
dinner%>%
  #remove items from dinner table that are in table b
  anti_join(b, by = "Item")%>%
  #calculate average calories
  summarise(mean(Calories))
##   mean(Calories)
## 1           1880
#dinner items to avoid for weight loss 
dinner%>%
  #remove items from dinner table that are in table d
  anti_join(d, by = "Item")%>%
  select(Category,Item)
##             Category                                   Item
## 1     Chicken & Fish           Chicken McNuggets (20 piece)
## 2     Chicken & Fish           Chicken McNuggets (40 piece)
## 3 Smoothies & Shakes                  Vanilla Shake (Large)
## 4 Smoothies & Shakes               Strawberry Shake (Large)
## 5 Smoothies & Shakes                Chocolate Shake (Large)
## 6 Smoothies & Shakes                 Shamrock Shake (Large)
## 7 Smoothies & Shakes McFlurry with M&Mâ\200\231s Candies (Medium)
#dinner items to avoid for weight loss 
dinner%>%
  #remove items from dinner table that are in table d
  anti_join(d, by = "Item")%>%
  #calculate average calories
  summarise(mean(Calories))
##   mean(Calories)
## 1       1012.857

Female

The top categories of compositions of the breakfast menu combinations are similar between the maintenance and weight loss charts for the the breakfast menu. The top 3 categories for compositions of the breakfast menu combinations are coffee and tea, breakfast and beverages categories. The top 3 categories for compositions of the dinner menu combinations are chicken and fish, coffee and tea, and beverages to maintain weight. The top 3 categories for compositions of the dinner menu combinations to lose weight are coffee and tea, snacks and sides, and beverages.

#Filter breakfast combinations below threshold for maintenance
bfood9<-breakfast_menu_calories %>%
  filter(total_calories <= 790) 

#conduct semi join on Mcdonald's menu to filter for results in the first menu option
bfood10<- mcd %>%
  semi_join(bfood9, by = c("Item" = "V1"))

#conduct semi join on Mcdonald's menu to filter for results in the second menu option
bfood11<- mcd %>%
  semi_join(bfood9, by = c("Item" = "V2"))

#conduct semi join on Mcdonald's menu to filter for results in the third menu option
bfood12<- mcd %>%
  semi_join(bfood9, by = c("Item" = "V3"))

bfood10 %>%
  #unit table by rows
  rbind(bfood11)%>%
 #unit table by rows
  rbind(bfood12) %>%
  count(Category)%>%
   #calculate percentage of categories
  mutate(percent = n/sum(n))%>%
  ggplot(aes(x=Category,y = percent, fill = Category))+
  #plot bar graph
  geom_bar(stat = "identity")+
   coord_flip()+
  ylab("Percentage")+
  ggtitle("Female Breakfast Weight Maintenance Composition")+
  theme_classic()

#Filter dinner combinations below threshold for maintenance
dfood9<-dinner_menu_calories %>%
  filter(total_calories <= 790) 

#conduct semi join on Mcdonald's menu to filter for results in the first menu option
dfood10<-mcd %>%
  semi_join(dfood9, by = c("Item" = "V1")) 

#conduct semi join on Mcdonald's menu to filter for results in the second menu option
dfood11<-mcd %>%
  semi_join(dfood9, by = c("Item" = "V2")) 

#conduct semi join on Mcdonald's menu to filter for results in the third menu option
dfood12<-mcd %>%
  semi_join(dfood9, by = c("Item" = "V3")) 

dfood10 %>%
  #unit table by rows
  rbind(dfood11)%>%
  #unit table by rows
  rbind(dfood12) %>%
  count(Category)%>%
   #calculate percentage of categories
  mutate(percent = n/sum(n))%>%
  ggplot(aes(x=Category,y = percent, fill = Category))+
  #plot bar graph
  geom_bar(stat = "identity")+
   coord_flip()+
  ylab("Percentage")+
  ggtitle("Female Dinner Weight Maintenance Composition")+
  theme_classic()

#Filter breakfast combinations below threshold for weight loss
bfood13<-breakfast_menu_calories %>%
  filter(total_calories <= 636) 

#conduct semi join on Mcdonald's menu to filter for results in the first menu option
bfood14<- mcd %>%
  semi_join(bfood13, by = c("Item" = "V1"))

#conduct semi join on Mcdonald's menu to filter for results in the second menu option
bfood15<- mcd %>%
  semi_join(bfood13, by = c("Item" = "V2"))

#conduct semi join on Mcdonald's menu to filter for results in the third menu option
bfood16<- mcd %>%
  semi_join(bfood13, by = c("Item" = "V3"))

bfood14 %>%
   #unit table by rows
  rbind(bfood15)%>%
   #unit table by rows
  rbind(bfood16) %>%
  count(Category)%>%
   #calculate percentage of categories
  mutate(percent = n/sum(n))%>%
  ggplot(aes(x=Category,y = percent, fill = Category))+
  #plot bar graph
  geom_bar(stat = "identity")+
   coord_flip()+
  ylab("Percentage")+
  ggtitle("Female Breakfast Weight loss Composition")+
  theme_classic()

#Filter dinner combinations below threshold for weight loss
dfood13<-dinner_menu_calories %>%
  filter(total_calories <= 636) 

#conduct semi join on Mcdonald's menu to filter for results in the first menu option
dfood14<-mcd %>%
  semi_join(dfood13, by = c("Item" = "V1")) 

#conduct semi join on Mcdonald's menu to filter for results in the second menu option
dfood15<-mcd %>%
  semi_join(dfood13, by = c("Item" = "V2")) 

#conduct semi join on Mcdonald's menu to filter for results in the third menu option
dfood16<-mcd %>%
  semi_join(dfood13, by = c("Item" = "V3")) 


dfood14 %>%
   #unit table by rows
  rbind(dfood15)%>%
   #unit table by rows
  rbind(dfood16) %>%
  count(Category)%>%
  #calculate percentage of categories
  mutate(percent = n/sum(n))%>%
  ggplot(aes(x=Category,y = percent, fill = Category))+
  #plot bar graph
  geom_bar(stat = "identity")+
   coord_flip()+
  ylab("Percentage")+
  ggtitle("Female Dinner Weight loss Composition")+
  theme_classic()

Five of the breakfast items were excluded because they could not be combined with any other item to come below the weight maintenance calorie threshold. The average calories of these items was 1016. Twelve of the breakfast items were excluded because they could not be combined with any other item to come below the weight loss calorie threshold. The average calories of these items was 827. The Big Breakfast meals and Frappés had the highest representation.

Eight of the dinner items were excluded because they could not be combined with any other item to come below the weight maintenance calorie threshold. The average calories of the items was 988. Twenty-two of the dinner items were excluded because they could not be combined with any other item to come below the weight loss calorie threshold. The average calories of these items was 800. The shakes and McFlurries had the highest representation.

#breakfast weight maintenance tables
e<-bfood10 %>%
  #unit table by rows
  rbind(bfood11)%>%
  #unit table by rows
  rbind(bfood12)

#dinner weight maintenance tables
f<-dfood10 %>%
  #unit table by rows
  rbind(dfood11)%>%
  #unit table by rows
  rbind(dfood12)
  
#breakfast weight loss tables
g<-bfood14%>%
  #unit table by rows
  rbind(bfood15)%>%
  #unit table by rows
  rbind(bfood16)

#dinner weight loss tables
h<-dfood14%>%
  #unit table by rows
  rbind(dfood15)%>%
  #unit table by rows
  rbind(dfood16)


#breakfast items to avoid for weight maintenance 
breakfast%>%
  #remove items from breakfast table that are in table e
  anti_join(e, by = "Item")%>%
  select(Category,Item)
##    Category                                                         Item
## 1 Breakfast                                Big Breakfast (Large Biscuit)
## 2 Breakfast                Big Breakfast with Hotcakes (Regular Biscuit)
## 3 Breakfast                  Big Breakfast with Hotcakes (Large Biscuit)
## 4 Breakfast Big Breakfast with Hotcakes and Egg Whites (Regular Biscuit)
## 5 Breakfast   Big Breakfast with Hotcakes and Egg Whites (Large Biscuit)
#breakfast items to avoid for weight maintenance 
breakfast%>%
  #remove items from breakfast table that are in table e
  anti_join(e, by = "Item")%>%
  #calculate average calories
  summarise(mean(Calories))
##   mean(Calories)
## 1           1016
#breakfast items to avoid for weight loss 
breakfast%>%
  #remove items from breakfast table that are in table g
  anti_join(g, by = "Item")%>%
  select(Category,Item)
##        Category                                                         Item
## 1     Breakfast                                    Steak, Egg & Cheese Bagel
## 2     Breakfast                              Big Breakfast (Regular Biscuit)
## 3     Breakfast                                Big Breakfast (Large Biscuit)
## 4     Breakfast              Big Breakfast with Egg Whites (Regular Biscuit)
## 5     Breakfast                Big Breakfast with Egg Whites (Large Biscuit)
## 6     Breakfast                Big Breakfast with Hotcakes (Regular Biscuit)
## 7     Breakfast                  Big Breakfast with Hotcakes (Large Biscuit)
## 8     Breakfast Big Breakfast with Hotcakes and Egg Whites (Regular Biscuit)
## 9     Breakfast   Big Breakfast with Hotcakes and Egg Whites (Large Biscuit)
## 10 Coffee & Tea                                        Frappé Mocha (Large)
## 11 Coffee & Tea                                      Frappé Caramel (Large)
## 12 Coffee & Tea                               Frappé Chocolate Chip (Large)
#breakfast items to avoid for weight loss 
breakfast%>%
  #remove items from breakfast table that are in table g
  anti_join(g, by = "Item")%>%
  #calculate average calories
  summarise(mean(Calories))
##   mean(Calories)
## 1       826.6667
#dinner items to avoid for weight maintenance 
dinner%>%
  #remove items from dinner table that are in table f
  anti_join(f, by = "Item")%>%
  select(Category,Item)
##             Category                                              Item
## 1     Chicken & Fish                      Chicken McNuggets (20 piece)
## 2     Chicken & Fish                      Chicken McNuggets (40 piece)
## 3 Smoothies & Shakes                             Vanilla Shake (Large)
## 4 Smoothies & Shakes                          Strawberry Shake (Large)
## 5 Smoothies & Shakes                           Chocolate Shake (Large)
## 6 Smoothies & Shakes                            Shamrock Shake (Large)
## 7 Smoothies & Shakes            McFlurry with M&Mâ\200\231s Candies (Medium)
## 8 Smoothies & Shakes McFlurry with Reese's Peanut Butter Cups (Medium)
#dinner items to avoid for weight maintenance 
dinner%>%
  #remove items from dinner table that are in table f
  anti_join(f, by = "Item")%>%
  #calculate average calories
  summarise(mean(Calories))
##   mean(Calories)
## 1          987.5
#dinner items to avoid for weight loss 
dinner%>%
  #remove items from dinner table that are in table h
  anti_join(h, by = "Item")%>%
  select(Category,Item)
##              Category                                              Item
## 1         Beef & Pork                Double Quarter Pounder with Cheese
## 2         Beef & Pork                            Bacon Clubhouse Burger
## 3      Chicken & Fish              Premium Crispy Chicken Club Sandwich
## 4      Chicken & Fish           Bacon Clubhouse Crispy Chicken Sandwich
## 5      Chicken & Fish Premium McWrap Southwest Chicken (Crispy Chicken)
## 6      Chicken & Fish                      Chicken McNuggets (20 piece)
## 7      Chicken & Fish                      Chicken McNuggets (40 piece)
## 8        Coffee & Tea                             Frappé Mocha (Large)
## 9        Coffee & Tea                           Frappé Caramel (Large)
## 10       Coffee & Tea                    Frappé Chocolate Chip (Large)
## 11 Smoothies & Shakes                            Vanilla Shake (Medium)
## 12 Smoothies & Shakes                             Vanilla Shake (Large)
## 13 Smoothies & Shakes                         Strawberry Shake (Medium)
## 14 Smoothies & Shakes                          Strawberry Shake (Large)
## 15 Smoothies & Shakes                          Chocolate Shake (Medium)
## 16 Smoothies & Shakes                           Chocolate Shake (Large)
## 17 Smoothies & Shakes                           Shamrock Shake (Medium)
## 18 Smoothies & Shakes                            Shamrock Shake (Large)
## 19 Smoothies & Shakes             McFlurry with M&Mâ\200\231s Candies (Small)
## 20 Smoothies & Shakes            McFlurry with M&Mâ\200\231s Candies (Medium)
## 21 Smoothies & Shakes               McFlurry with Oreo Cookies (Medium)
## 22 Smoothies & Shakes McFlurry with Reese's Peanut Butter Cups (Medium)
#dinner items to avoid for weight loss 
dinner%>%
  #remove items from dinner table that are in table h
  anti_join(h, by = "Item")%>%
  #calculate average calories
  summarise(mean(Calories))
##   mean(Calories)
## 1       800.4545

linear model

The graphs display the influence of fat and carbohydrates on the calories an item contains. Monitoring fat and carbohydrates is important to controlling weight. Consumers must be aware when reviewing nutritional content that meals like Big Breakfast and Hot Cakes are high in fat and carbohydrates, which lead to higher calories. People sometimes only focus on how many calories an item may have, but it is also important to review the factors affecting those calories.

#create tibble ro conduct prediction for linear model
explanatory_data1 <-tibble(
  total_carbohydrates = breakfast_menu_calories$total_carbohydrates, total_fat = breakfast_menu_calories$total_fat)
  

prediction1 <- explanatory_data1  %>%
  #Conduct prediction for linear model
  mutate(total_calories = predict(model,explanatory_data1))

breakfast_menu_calories%>%
  ggplot(aes(x=total_carbohydrates,y = total_calories))+
  #Insert linear model in chart
 geom_smooth(data = prediction1, method = "lm", se = FALSE,  size = 0.8)+
  ggtitle("Variable Influence on Calories")+
  #select theme
  theme_classic()+
  xlab("Total Carbohydrates (g) + Total Fat (g)")+
  ylab("Total Calories (Kcal)")
## `geom_smooth()` using formula 'y ~ x'

Conclusion

The dinner menu had greater number of available combinations than the breakfast menu, but the breakfast menu had a higher percentage of combinations under 1000 calories. Eighty-seven percent of the menu items in the McDonald’s dataset seem to fit within maintenance and weight loss calorie thresholds for males and females. The four main categories of food in the combo meals were coffee and tea, beverages, chicken and fish, and breakfast. The data suggest that to control calorie intake, it would be better to select chicken or fish options because they offer a person greater combination options compared to meat and pork options. The 20- and 40-piece chicken nugget are an exception because they came up as a food to avoid due their high calorie value. Coffee or tea would a good low-calorie option for a beverage, excluding Frappés. Calorie counting is an important aspect of weight control. However, the linear model demonstrates the importance of people being informed of the other nutritional values in food items. A food item high in calories could be high in nutritional values like carbohydrate and fats.

References

McDonald’s Corporation. (n.d.). Our History: Ray Kroc & The McDonalds Brothers. https://www.mcdonalds.com/us/en-us/about-us/our-history.html.

McDonald’s Corporation. (2011, June 3). McDonald’s USA Nutrition Facts for Popular Menu It. nutritionfacts.pdf. McDonald’s USA Nutrition Facts for Popular Menu It.

Centers for Disease Control and Prevention. (2021, January 14). FastStats - Body Measurements. Centers for Disease Control and Prevention. https://www.cdc.gov/nchs/fastats/body-measurements.htm.

U.S. Department of Health and Human Services. (n.d.). Body Weight Planner. National Institute of Diabetes and Digestive and Kidney Diseases. https://www.niddk.nih.gov/bwp.

U.S. Department of Health and Human Services. (n.d.). Daily Values (DVs). NIH Office of Dietary Supplements. https://ods.od.nih.gov/HealthInformation/dailyvalues.aspx#:~:text=DVs%20were%20developed%20by%20the,their%20approximate%20requirement%20for%20it.