MIS40970 Assignment 1: Orange Juice Sales
Sutaraj Dutta
14200091
[Link]@[Link]
1) Command:
> OJ <- [Link]("[Link]")
Output:
The Data is successfully loaded in the environment.
2) Command:
> dim(OJ)
Output:
[1] 28947 17
3) Command:
> mean(OJ$price)
Output:-
[1] 2.282488
> sd(OJ$price)
[1] 0.6480007
> range(OJ$price)
[1] 0.52 3.87
4) Command:
> median(OJ$logmove)
Output:
[1] 9.03408
5) Command:
> unique(OJ$brand)
Output:
[1] tropicana [Link] dominicks
Levels: dominicks [Link] tropicana
6) Command:
> hist(OJ$price[OJ$brand=="tropicana"], col=rgb(1,0,0,0.5),xlim=c(0,5), ylim=c(0,4000
), main="Frequency of Price BrandWise (Tropicana)",xlab = "Price")
> hist(OJ$price[OJ$brand=="[Link]"], col=rgb(0.8,0.8,0.8,0.5),xlim=c(0,5), ylim=
c(0,4000), main="Frequency of Price BrandWise (Minute Maid)",xlab = "Price")
> hist(OJ$price[OJ$brand=="dominicks"], col=rgb(0.8,1,0.8,1),xlim=c(0,5), ylim=c(0,40
00), main="Frequency of Price BrandWise (Dominicks)",xlab = "Price")
Output:
7) Command:-
> boxplot(price~brand, data=OJ, main="Brand Wise Boxplot")
Output:-
8) Command:-
Almost 50% of all the Tropicana’s sold are costly than the other two brands, whereas almost 50% of all the Minute
Maid sold are costly than 75th percentile of Dominicks. 75th percentile of Minute Maid converges with 25th percentile
of Tropicana’s price, similarly 75th percentile of Dominicks converges with 25th percentile of Minute Maid price.
Tropicana have fewer outlier than Dominicks and Minute Maid, with respect to the price as per in the given dataset.
9) Command:-
> plot(OJ$logmove, OJ$price,col = c("red", "green3","blue")[unclass(OJ$brand)],ylab =
"Price",xlab = "Logmove",main="Price V/s Logmove (Brand Wise)")
legend("topright",c("tropicana","[Link]","dominicks"),col=c("blue",
"green3", "red"),pch = 21,cex = 0.5)
Output:-
10) Command:
Tropicana and Minute Maid has consistent sales figure and it ranges between roughly 6 to 12 units sold. However
the prices of Tropicana’s units sold are higher than Minute Maid.
Though, the price of Dominicks is significantly low but the units sold varies over a wide range.
11) Comamnd:-
> priceWeekWise <- aggregate(OJ$price, list(OJ$week), mean)
> plot(priceWeekWise,type = "o",col="green3",xlab="Week",ylab = "Mean Weekly Price")
Output:-
12) Command:-
> tapply(OJ$price,INDEX=list(OJ$week,OJ$brand),FUN = mean)
Output:-
dominicks [Link] tropicana
40 1.590000 2.890000 3.509315
41 2.447015 1.990000 3.514627
42 2.461940 2.911343 3.536567
43 2.452597 2.892597 3.517792
44 2.463506 2.590000 3.534156
45 2.467838 2.908649 3.541486
46 2.471053 2.913158 3.547500
47 2.086800 2.390000 3.534000
48 2.086883 2.907013 3.540000
49 2.086842 1.990000 3.545000
50 2.083924 2.911392 3.539114
51 1.889000 2.921625 3.552375
52 1.888987 2.913797 3.243544
53 1.888987 2.192025 3.243544
54 1.790000 2.908765 3.245062
55 1.779610 2.909481 3.542857
56 1.790000 2.909114 3.169114
57 2.469000 1.990000 3.170375
58 1.202469 2.657160 3.250494
59 1.590000 2.912375 3.432375
60 1.590000 1.979367 3.431772
61 1.290000 2.914304 3.431519
62 0.990000 1.990000 3.547778
63 1.590000 1.990000 2.981951
64 2.414938 2.913951 2.980123
65 2.219877 1.990000 3.284321
66 1.390000 1.990000 3.281852
67 2.217073 1.990000 2.390000
68 2.229737 1.990000 2.390000
69 2.226962 1.990000 3.247975
70 0.990000 2.401500 2.590000
71 2.230488 2.401707 2.590000
72 2.230988 1.988889 3.276914
73 1.490000 2.386829 3.275854
74 1.490000 2.318313 2.490000
75 2.242099 2.323210 3.278642
76 2.237654 2.318642 3.275432
77 1.938889 1.989012 3.278642
78 1.037683 2.386829 3.270244
79 2.248701 2.393377 3.278052
80 2.227632 1.725000 3.241579
81 1.590000 1.723086 1.603086
82 1.590000 2.387949 3.274359
83 1.590000 2.048000 1.987500
84 0.990000 2.048519 3.275432
85 2.237073 2.049024 1.990000
86 2.233250 2.049750 1.990000
87 2.245325 1.390000 3.282468
88 2.248025 2.206420 2.290000
89 1.590000 2.200533 3.279600
90 1.590000 2.204487 3.286410
91 2.114000 2.214933 1.990000
92 1.380854 1.660854 1.990000
93 1.255802 2.144074 3.300494
94 1.814810 1.688481 3.143544
95 1.820519 1.701429 1.990000
96 1.590000 2.223462 1.990000
97 1.595921 2.211974 2.038026
98 1.753671 2.217089 3.189241
99 0.990000 2.210390 2.189870
100 1.026265 2.218193 2.229157
101 1.486709 2.082152 3.314810
102 1.476829 1.286341 3.312683
103 1.389870 2.214156 3.315195
104 1.389875 2.195750 1.988750
105 1.403049 1.974634 3.237805
106 1.583750 1.960000 2.556750
107 1.583614 1.868193 3.271205
108 1.567273 1.790000 3.012078
109 1.545823 1.820127 2.956329
110 1.571625 1.690000 2.960875
111 1.677683 2.205732 2.957439
112 1.649880 1.489759 2.959036
113 1.617927 2.205854 2.966951
114 1.630854 2.157805 3.021463
115 1.687654 1.974321 1.990000
116 1.548293 1.971098 2.866463
117 1.576463 1.984756 3.025854
118 1.588795 2.218795 3.024940
119 1.590244 2.175244 2.900610
120 1.617470 1.974819 2.384699
121 1.605732 1.972561 2.362927
122 1.625556 2.026420 2.273580
123 1.643614 2.462651 2.337711
124 1.541205 2.455422 2.994699
125 1.466829 2.478049 2.994878
126 1.491707 2.484268 2.992073
127 1.522892 1.982651 1.990000
128 1.557308 1.971026 2.990769
129 1.533659 2.018171 1.982683
130 1.505732 2.469512 1.803902
131 1.530120 1.988916 1.788916
132 1.583735 2.016024 1.860120
133 1.603659 2.413415 2.902195
134 1.688675 1.978916 2.500000
135 1.528293 2.033171 2.534756
136 1.290000 2.600976 2.987561
137 1.329398 1.960000 2.832530
138 1.860964 2.619036 2.240120
139 1.870123 2.618025 2.991235
140 1.965244 2.605732 2.992439
141 1.689880 1.960120 2.991205
142 1.689615 2.622436 2.989103
143 1.701538 2.686154 2.490000
144 1.956543 2.678889 2.381481
145 1.957662 2.661429 1.990000
146 1.910000 2.545750 2.977250
147 1.852099 2.010247 2.673210
148 1.327051 2.242692 2.983590
149 1.885309 2.680123 2.990617
150 1.693250 2.278750 2.986375
151 1.483544 2.677089 2.997342
152 1.869747 2.619620 2.908987
153 1.933247 1.988701 3.009481
154 1.587051 1.966923 2.774615
155 1.273590 1.689615 2.892051
156 1.959610 1.716234 2.490000
157 1.975316 1.966709 2.535823
158 1.860000 2.622875 3.000625
159 1.489877 2.513704 2.783210
160 1.880000 2.182500 2.973250
13) Command:-
> OJBrandmean <- aggregate(OJ$price,list(OJ$week),mean)
> OJBrandWeekmean <- aggregate(OJ$price,list(OJ$week,OJ$brand),mean)
> plot(OJBrandmean,type = "o",col="green3",xlab="Week",ylab = "Mean Weekly Price",yli
m = c(0,4), lwd=2.5)
There were 24 warnings (use warnings() to see them)
> par(new = TRUE)
> plot(x = OJBrandWeekmean$Group.1[OJBrandWeekmean$Group.2 == "dominicks"], y = OJBra
ndWeekmean$x[OJBrandWeekmean$Group.2 == "dominicks"] , type = "o", col="red",xlab="We
ek",ylab = "Mean Weekly Price",ylim = c(0,4),lwd = 1)
> par(new = TRUE)
> plot(x = OJBrandWeekmean$Group.1[OJBrandWeekmean$Group.2 == "[Link]"], y = OJB
randWeekmean$x[OJBrandWeekmean$Group.2 == "[Link]"] , type = "o", col="blue",xla
b="Week",ylab = "Mean Weekly Price",ylim = c(0,4),lwd = 1)
> par(new = TRUE)
> plot(x = OJBrandWeekmean$Group.1[OJBrandWeekmean$Group.2 == "tropicana"], y = OJBra
ndWeekmean$x[OJBrandWeekmean$Group.2 == "tropicana"] , type = "o", col="brown",xlab="
Week",ylab = "Mean Weekly Price",ylim = c(0,4),lwd = 1)
> legend("bottomright", c("All Brand Mean","Tropicana Mean","[Link] Mean","Domin
icks Mean"), lty=c(1,1,1,1), lwd=c(2.5,1,1,1),col=c("green3","brown","blue","red"),ce
x = 0.5)
Output:
14) Command:-
> advertisement.f <- factor(OJ$feat, labels = c("No Advert", "Advert"))
> tapply(OJ$logmove,list(advertisement.f),sum)
Output:-
No Advert Advert
195685.4 69696.8
15) Command:-
> comboOJweekwise <- aggregate(OJ$logmove,list(OJ$week,OJ$brand,OJ$feat),mean)
> comboOJweekwisemean <- aggregate(comboOJweekwise$x,list(comboOJweekwise$Group.1,com
boOJweekwise$Group.3),mean)
> plot(x=comboOJweekwisemean$Group.1[comboOJweekwisemean$Group.2 == 0],y=comboOJweekw
isemean$x[comboOJweekwisemean$Group.2 == 0],type="o",col="red",xlab="Week",ylab="Mean
Weekly Units Sold",ylim = c(5,14),lwd = 2.5)
> par(new=TRUE)
> plot(x=comboOJweekwisemean$Group.1[comboOJweekwisemean$Group.2 == 1],y=comboOJweekw
isemean$x[comboOJweekwisemean$Group.2 == 1],type="o",col="green3",xlab="Week",ylab="M
ean Weekly Units Sold",ylim = c(5,14),lwd = 2.5)
> legend("bottomright", c("Without Advert","With Advert"), lty=c(1,1), lwd=c(2.5,2.5)
,col=c("green3","red"),cex = 0.75)
Output:-
The interesting thing about this plot is even if the total volume of units sold without advert is more, the weekly
average unit sold with advert remains higher. Hence, the advertisement did have an positive impact on the sales.