Introduction

Is there a statistically significant difference in the mean calorie content of menu items between McDonald’s and Subway?

This research project aims to determine whether there is a statistically significant difference in the mean calorie counts of menu items offered by two leading fast-food brands, McDonald’s and Subway. The data set I used for this analysis is called ‘fastfood.csv’ and includes 515 observations (rows) and 17 variables (columns), meeting the criterion of having at least 500 observations. Although the dataset includes several nutrition-related variables (such as total fat, sugar, and sodium), I used only two variables in this study, namely restaurant (categorical grouping variable) and calories (quantitative response variable).

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
#Load the dataset

data <- read.csv("fastfood.csv")

Data Analysis

In this part, I will analyze and compare the number of calories present in menu items of McDonald’s and Subway. Firstly, I will import the dataset and study its structure, dimensions, and summary statistics to gain knowledge about the data. Secondly, I will filter the data and consider only the menu items of McDonald’s and Subway. Thirdly, I will find out the number of menu items, mean, median, standard deviation, and maximum calories in each restaurant. Finally, I will generate a boxplot for both restaurants.

# Display the first six rows
head(data)
##   restaurant                                      item calories cal_fat
## 1  Mcdonalds          Artisan Grilled Chicken Sandwich      380      60
## 2  Mcdonalds            Single Bacon Smokehouse Burger      840     410
## 3  Mcdonalds            Double Bacon Smokehouse Burger     1130     600
## 4  Mcdonalds Grilled Bacon Smokehouse Chicken Sandwich      750     280
## 5  Mcdonalds  Crispy Bacon Smokehouse Chicken Sandwich      920     410
## 6  Mcdonalds                                   Big Mac      540     250
##   total_fat sat_fat trans_fat cholesterol sodium total_carb fiber sugar protein
## 1         7       2       0.0          95   1110         44     3    11      37
## 2        45      17       1.5         130   1580         62     2    18      46
## 3        67      27       3.0         220   1920         63     3    18      70
## 4        31      10       0.5         155   1940         62     2    18      55
## 5        45      12       0.5         120   1980         81     4    18      46
## 6        28      10       1.0          80    950         46     3     9      25
##   vit_a vit_c calcium salad
## 1     4    20      20 Other
## 2     6    20      20 Other
## 3    10    20      50 Other
## 4     6    25      20 Other
## 5     6    20      20 Other
## 6    10     2      15 Other
# Check the number of the rows and columns
dim(data)
## [1] 515  17
#Check the variable names and data types
str(data)
## 'data.frame':    515 obs. of  17 variables:
##  $ restaurant : chr  "Mcdonalds" "Mcdonalds" "Mcdonalds" "Mcdonalds" ...
##  $ item       : chr  "Artisan Grilled Chicken Sandwich" "Single Bacon Smokehouse Burger" "Double Bacon Smokehouse Burger" "Grilled Bacon Smokehouse Chicken Sandwich" ...
##  $ calories   : int  380 840 1130 750 920 540 300 510 430 770 ...
##  $ cal_fat    : int  60 410 600 280 410 250 100 210 190 400 ...
##  $ total_fat  : int  7 45 67 31 45 28 12 24 21 45 ...
##  $ sat_fat    : num  2 17 27 10 12 10 5 4 11 21 ...
##  $ trans_fat  : num  0 1.5 3 0.5 0.5 1 0.5 0 1 2.5 ...
##  $ cholesterol: int  95 130 220 155 120 80 40 65 85 175 ...
##  $ sodium     : int  1110 1580 1920 1940 1980 950 680 1040 1040 1290 ...
##  $ total_carb : int  44 62 63 62 81 46 33 49 35 42 ...
##  $ fiber      : int  3 2 3 2 4 3 2 3 2 3 ...
##  $ sugar      : int  11 18 18 18 18 9 7 6 7 10 ...
##  $ protein    : int  37 46 70 55 46 25 15 25 25 51 ...
##  $ vit_a      : int  4 6 10 6 6 10 10 0 20 20 ...
##  $ vit_c      : int  20 20 20 25 20 2 2 4 4 6 ...
##  $ calcium    : int  20 20 50 20 20 15 10 2 15 20 ...
##  $ salad      : chr  "Other" "Other" "Other" "Other" ...
#Get summary statistic
summary(data)
##      restaurant         item        calories         cal_fat      
##  Length   :515   Length   :515   Min.   :  20.0   Min.   :   0.0  
##  N.unique :  8   N.unique :505   1st Qu.: 330.0   1st Qu.: 120.0  
##  N.blank  :  0   N.blank  :  0   Median : 490.0   Median : 210.0  
##  Min.nchar:  5   Min.nchar:  5   Mean   : 530.9   Mean   : 238.8  
##  Max.nchar: 11   Max.nchar: 63   3rd Qu.: 690.0   3rd Qu.: 310.0  
##                                  Max.   :2430.0   Max.   :1270.0  
##                                                                   
##    total_fat         sat_fat         trans_fat      cholesterol    
##  Min.   :  0.00   Min.   : 0.000   Min.   :0.000   Min.   :  0.00  
##  1st Qu.: 14.00   1st Qu.: 4.000   1st Qu.:0.000   1st Qu.: 35.00  
##  Median : 23.00   Median : 7.000   Median :0.000   Median : 60.00  
##  Mean   : 26.59   Mean   : 8.153   Mean   :0.465   Mean   : 72.46  
##  3rd Qu.: 35.00   3rd Qu.:11.000   3rd Qu.:1.000   3rd Qu.: 95.00  
##  Max.   :141.00   Max.   :47.000   Max.   :8.000   Max.   :805.00  
##                                                                    
##      sodium       total_carb         fiber            sugar       
##  Min.   :  15   Min.   :  0.00   Min.   : 0.000   Min.   : 0.000  
##  1st Qu.: 800   1st Qu.: 28.50   1st Qu.: 2.000   1st Qu.: 3.000  
##  Median :1110   Median : 44.00   Median : 3.000   Median : 6.000  
##  Mean   :1247   Mean   : 45.66   Mean   : 4.137   Mean   : 7.262  
##  3rd Qu.:1550   3rd Qu.: 57.00   3rd Qu.: 5.000   3rd Qu.: 9.000  
##  Max.   :6080   Max.   :156.00   Max.   :17.000   Max.   :87.000  
##                                  NAs    :12                       
##     protein           vit_a            vit_c           calcium      
##  Min.   :  1.00   Min.   :  0.00   Min.   :  0.00   Min.   :  0.00  
##  1st Qu.: 16.00   1st Qu.:  4.00   1st Qu.:  4.00   1st Qu.:  8.00  
##  Median : 24.50   Median : 10.00   Median : 10.00   Median : 20.00  
##  Mean   : 27.89   Mean   : 18.86   Mean   : 20.17   Mean   : 24.85  
##  3rd Qu.: 36.00   3rd Qu.: 20.00   3rd Qu.: 30.00   3rd Qu.: 30.00  
##  Max.   :186.00   Max.   :180.00   Max.   :400.00   Max.   :290.00  
##  NAs    :1        NAs    :214      NAs    :210      NAs    :210     
##        salad    
##  Length   :515  
##  N.unique :  1  
##  N.blank  :  0  
##  Min.nchar:  5  
##  Max.nchar:  5  
##                 
## 
#Count the menu items for each restaurant
table(data$restaurant)
## 
##       Arbys Burger King Chick Fil-A Dairy Queen   Mcdonalds       Sonic 
##          55          70          27          42          57          53 
##      Subway   Taco Bell 
##          96         115
#filtering the dataset
mcd_sub_filtered <- data %>%
  filter(restaurant %in% c("Mcdonalds", "Subway"))

#Calculate summary statistics
calorie_summary <- mcd_sub_filtered |>
  group_by(restaurant) |>
  summarize(
    count = n(),
    mean_calories = round(mean(calories,na.rm = TRUE),1),
    median_calories = round(median(calories, na.rm = TRUE),1),
    sd_calories = round(sd(calories,na.rm = TRUE),1),
    max_calories = round(max(calories, na.rm = TRUE),1)
  )

print(calorie_summary)
## # A tibble: 2 × 6
##   restaurant count mean_calories median_calories sd_calories max_calories
##   <chr>      <int>         <dbl>           <dbl>       <dbl>        <dbl>
## 1 Mcdonalds     57          640.             540        411.         2430
## 2 Subway        96          503              460        282.         1160

Statistical Analysis

In this statistical analysis, the objective is to find out whether there is any significant difference in the mean calorie count of food served by McDonald’s and Subway restaurants. An independent two-sample t-test will be used for comparison, as the two samples being compared are independent of each other.

The hypotheses are:

Null hypothesis (H₀): The mean calorie content of McDonald’s and Subway menu items is equal.

Alternative hypothesis (Hₐ): The mean calorie content of McDonald’s and Subway menu items is different.

library(ggplot2)
ggplot(mcd_sub_filtered,aes(x= restaurant, y = calories, fill = restaurant)) +
  geom_boxplot() +
  labs(
    title = "Comparison of Calories: McDonald's vs. Subway", 
    x = "Restaurant",
    y = "Calories"
   ) +
  theme_minimal()

# # Perform the independent two-sample t-test
t.test(calories ~ restaurant, data = mcd_sub_filtered)
## 
##  Welch Two Sample t-test
## 
## data:  calories by restaurant
## t = 2.2311, df = 87.739, p-value = 0.02823
## alternative hypothesis: true difference in means between group Mcdonalds and group Subway is not equal to 0
## 95 percent confidence interval:
##   15.00054 259.65954
## sample estimates:
## mean in group Mcdonalds    mean in group Subway 
##                640.3509                503.0208

Conclusion

Based on the independent two-sample t-test, we obtained a test statistic of \(t = 2.2311\) with degrees of freedom \(87.739\) and a \(p\)-value of \(0.02823\). Because the \(p\)-value is less than the standard significance level of \(\alpha = 0.05\), we reject the null hypothesis (\(H_0\)). Specifically, McDonald’s has a higher sample mean (\(\approx 640.35\) calories) compared to Subway (\(\approx 503.02\) calories).

References

OpenIntro Dataset. https://www.openintro.org/data/index.php?data=fastfood