Sei sulla pagina 1di 13

McD-Assignment.utf8.

md Page 1 of 13

Answer 1 - As is evident from the below summary that


highest varieties and lowest varieties belong to Coffee &
Tea and Salads respectively.
Coffee & Tea = 95 Salads = 6 —

setwd("E:/PGP - BABI/Statistical Methods for Decision Making/Assignment#1")


McD = read.csv("Mcdonald .csv")
Category = table(McD$Category)
library(ggplot2)
ggplot(McD, aes(x=factor(Category), fill = Category)) + geom_bar()

summary(McD$Category)

## Beef & Pork Beverages Breakfast


## 15 27 42
## Chicken & Fish Coffee & Tea Desserts
## 27 95 7
## Salads Smoothies & Shakes Snacks & Sides
## 6 28 13

Answer - 3
As is evident from the correlation matrix, there are many variables having highly positive correlation
with each other. One thing to note however is the correlation of a variable with its daily value which
increases as the original variable increase(Complete positive correlation).

Corr = cor(McD[4:21])
library(ggcorrplot)
ggcorrplot(Corr,hc.order = TRUE, type = "lower", lab = TRUE)

file:///E:/PGP%20-%20BABI/Statistical%20Methods%20for%20Decision%20Makin... 10-09-2019
McD-Assignment.utf8.md Page 2 of 13

###Answer 2 - Almost every variable have an outlier present in them except for Saturated Fat &
Dietary Fiber. The most prominent outliers are present in % Daily Value(Vitamin A and C)

attach(McD)

## The following object is masked _by_ .GlobalEnv:


##
## Category

boxplot(McD$Calories, main = "Calories Boxplot", xlab = "Unit",col = "Blue",


horizontal = TRUE)

file:///E:/PGP%20-%20BABI/Statistical%20Methods%20for%20Decision%20Makin... 10-09-2019
McD-Assignment.utf8.md Page 3 of 13

boxplot(McD$Calories.from.Fat, main = "Calories from Fat Boxplot", xlab = "U


nit",col = "Blue",horizontal = TRUE)

file:///E:/PGP%20-%20BABI/Statistical%20Methods%20for%20Decision%20Makin... 10-09-2019
McD-Assignment.utf8.md Page 4 of 13

boxplot(Total.Fat, main = "Total Fat Boxplot", xlab = "Unit",col = "Blue", h


orizontal = TRUE)

boxplot(Saturated.Fat, main = "Saturated Fat Boxplot", xlab = "Unit",col =


"Blue",horizontal = TRUE)

file:///E:/PGP%20-%20BABI/Statistical%20Methods%20for%20Decision%20Makin... 10-09-2019
McD-Assignment.utf8.md Page 5 of 13

boxplot(Trans.Fat, main = "Trans Fat Boxplot", xlab = "Unit",horizontal = TR


UE)

file:///E:/PGP%20-%20BABI/Statistical%20Methods%20for%20Decision%20Makin... 10-09-2019
McD-Assignment.utf8.md Page 6 of 13

boxplot(Cholesterol, main = "Cholestrol Boxplot", xlab = "Unit",col = "Blu


e",horizontal = TRUE)

boxplot(Sodium, main = "Sodium Boxplot", xlab = "Unit",col = "Blue",horizont


al = TRUE)

file:///E:/PGP%20-%20BABI/Statistical%20Methods%20for%20Decision%20Makin... 10-09-2019
McD-Assignment.utf8.md Page 7 of 13

boxplot(Carbohydrates, main = "Carbohydrates Boxplot", xlab = "Unit",col =


"Blue",horizontal = TRUE)

file:///E:/PGP%20-%20BABI/Statistical%20Methods%20for%20Decision%20Makin... 10-09-2019
McD-Assignment.utf8.md Page 8 of 13

boxplot(Dietary.Fiber, main = "Dietary Fiber Boxplot", xlab = "Unit",col =


"Blue",horizontal = TRUE)

boxplot(Sugars, main = "Sugars Boxplot", xlab = "Unit",col = "Blue",horizont


al = TRUE)

file:///E:/PGP%20-%20BABI/Statistical%20Methods%20for%20Decision%20Makin... 10-09-2019
McD-Assignment.utf8.md Page 9 of 13

boxplot(Protein, main = "Protein Boxplot", xlab = "Unit",col = "Blue",horizo


ntal = TRUE)

file:///E:/PGP%20-%20BABI/Statistical%20Methods%20for%20Decision%20Makin... 10-09-2019
McD-Assignment.utf8.md Page 10 of 13

boxplot(Vitamin.A....Daily.Value., main = "Vitamin A(% Daily Value) Boxplo


t", xlab = "Unit",col = "Blue",horizontal = TRUE)

boxplot(Vitamin.C....Daily.Value., main = "Vitamin C(% Daily Value) Boxplo


t", xlab = "Unit",col = "Blue",horizontal = TRUE)

file:///E:/PGP%20-%20BABI/Statistical%20Methods%20for%20Decision%20Makin... 10-09-2019
McD-Assignment.utf8.md Page 11 of 13

boxplot(Calcium....Daily.Value., main = "Calcium(% Daily Value) Boxplot", xl


ab = "Unit",col = "Blue",horizontal = TRUE)

file:///E:/PGP%20-%20BABI/Statistical%20Methods%20for%20Decision%20Makin... 10-09-2019
McD-Assignment.utf8.md Page 12 of 13

boxplot(Iron....Daily.Value., main = "Iron(% Daily Value) Boxplot", xlab =


"Unit",col = "Blue",horizontal = TRUE)

sum(McD[McD$Category == 'Breakfast',][,12])

## [1] 2140

sum(McD[McD$Category == 'Beef & Pork',][,12])

## [1] 434

sum(McD[McD$Category == 'Beverages',][,12])

## [1] 5

sum(McD[McD$Category == 'Chicken & Fish',][,12])

## [1] 681

sum(McD[McD$Category == 'Coffee & Tea',][,12])

file:///E:/PGP%20-%20BABI/Statistical%20Methods%20for%20Decision%20Makin... 10-09-2019
McD-Assignment.utf8.md Page 13 of 13

## [1] 891

sum(McD[McD$Category == 'Desserts',][,12])

## [1] 34

sum(McD[McD$Category == 'Smoothies & Shakes',][,12])

## [1] 412

sum(McD[McD$Category == 'Salads',][,12])

## [1] 104

sum(McD[McD$Category == 'Snacks & Sides',][,12])

## [1] 81

Sod_max = which.max(Sodium)
McD$Item[Sod_max]

## [1] Chicken McNuggets (40 piece)


## 260 Levels: 1% Low Fat Milk Jug ... Vanilla Shake (Small)

library(plyr)
Saturated = head(arrange(McD, desc(Saturated.Fat)), n = 4)
Saturated$Item

## [1] Big Breakfast with Hotcakes (Large Biscuit)


## [2] Chicken McNuggets (40 piece)
## [3] Frappé Chocolate Chip (Large)
## [4] McFlurry with M&Mâ\200\231s Candies (Medium)
## 260 Levels: 1% Low Fat Milk Jug ... Vanilla Shake (Small)

file:///E:/PGP%20-%20BABI/Statistical%20Methods%20for%20Decision%20Makin... 10-09-2019