setting working directory to file location

setwd(“C:/Users/Taiyyab Ali/Desktop/R language”)

store <- read.csv(paste("Store24.csv",sep=""))
View(store)

a quick summary of data - “store”

library(psych)
overview <- describe(store)[2:14,3:9]
round(overview, digits=2)
##                  mean        sd     median    trimmed       mad       min
## Sales      1205413.12 304531.31 1127332.00 1182031.25 288422.04 699306.00
## Profit      276313.61  89404.08  265014.00  270260.34  90532.00 122180.00
## MTenure         45.30     57.67      24.12      33.58     29.67      0.00
## CTenure         13.93     17.70       7.21      10.60      6.14      0.89
## Pop           9825.59   5911.67    8896.00    9366.07   7266.22   1046.00
## Comp             3.79      1.31       3.63       3.66      0.82      1.65
## Visibility       3.08      0.75       3.00       3.07      0.00      2.00
## PedCount         2.96      0.99       3.00       2.97      1.48      1.00
## Res              0.96      0.20       1.00       1.00      0.00      0.00
## Hours24          0.84      0.37       1.00       0.92      0.00      0.00
## CrewSkill        3.46      0.41       3.50       3.47      0.34      2.06
## MgrSkill         3.64      0.41       3.59       3.62      0.45      2.96
## ServQual        87.15     12.61      89.47      88.62     15.61     57.90
##                   max
## Sales      2113089.00
## Profit      518998.00
## MTenure        277.99
## CTenure        114.15
## Pop          26519.00
## Comp            11.13
## Visibility       5.00
## PedCount         5.00
## Res              1.00
## Hours24          1.00
## CrewSkill        4.64
## MgrSkill         4.62
## ServQual       100.00

summary of Profit,Mtenure,Ctenure column

describe(store)[3:5,3:4]
##              mean       sd
## Profit  276313.61 89404.08
## MTenure     45.30    57.67
## CTenure     13.93    17.70

arrannging data of mtcars

library(rio)
attach(mtcars)
View(mtcars)
newdata1 <- mtcars[order(mpg),] # in ascending order
View(newdata1)
newdata1[1:5, ]
##                      mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Cadillac Fleetwood  10.4   8  472 205 2.93 5.250 17.98  0  0    3    4
## Lincoln Continental 10.4   8  460 215 3.00 5.424 17.82  0  0    3    4
## Camaro Z28          13.3   8  350 245 3.73 3.840 15.41  0  0    3    4
## Duster 360          14.3   8  360 245 3.21 3.570 15.84  0  0    3    4
## Chrysler Imperial   14.7   8  440 230 3.23 5.345 17.42  0  0    3    4
newdata2 <- mtcars[order(-mpg),] # in decending order
View(newdata2)
detach(mtcars)

Top 10 most profitable stores

attach(store)
## The following object is masked _by_ .GlobalEnv:
## 
##     store
newdata <- store[order(-Profit),]
names(newdata)[1] <- "storeID"
View(newdata)
newdata[1:10,1:5]
##    storeID   Sales Profit   MTenure    CTenure
## 74      74 1782957 518998 171.09720  29.519510
## 7        7 1809256 476355  62.53080   7.326488
## 9        9 2113089 474725 108.99350   6.061602
## 6        6 1703140 469050 149.93590  11.351130
## 44      44 1807740 439781 182.23640 114.151900
## 2        2 1619874 424007  86.22219   6.636550
## 45      45 1602362 410149  47.64565   9.166325
## 18      18 1704826 394039 239.96980  33.774130
## 11      11 1583446 389886  44.81977   2.036961
## 47      47 1665657 387853  12.84790   6.636550

bottom 10 least profitable stores

attach(store)
## The following object is masked _by_ .GlobalEnv:
## 
##     store
## The following objects are masked from store (pos = 3):
## 
##     Comp, CrewSkill, CTenure, Hours24, MgrSkill, MTenure,
##     PedCount, Pop, Profit, Res, Sales, ServQual, store, Visibility
newdata3<- store[order(Profit),]
names(newdata3)[1] <- "storeID"
View(newdata3)
newdata3[1:10,1:5]
##    storeID   Sales Profit     MTenure   CTenure
## 57      57  699306 122180  24.3485700  2.956879
## 66      66  879581 146058 115.2039000  3.876797
## 41      41  744211 147327  14.9180200 11.926080
## 55      55  925744 147672   6.6703910 18.365500
## 32      32  828918 149033  36.0792600  6.636550
## 13      13  857843 152513   0.6571813  1.577002
## 54      54  811190 159792   6.6703910  3.876797
## 52      52 1073008 169201  24.1185600  3.416838
## 61      61  716589 177046  21.8184200 13.305950
## 37      37 1202917 187765  23.1985000  1.347023

Scatter plot Profit vs MTenure

attach(store)
## The following object is masked _by_ .GlobalEnv:
## 
##     store
## The following objects are masked from store (pos = 3):
## 
##     Comp, CrewSkill, CTenure, Hours24, MgrSkill, MTenure,
##     PedCount, Pop, Profit, Res, Sales, ServQual, store, Visibility
## The following objects are masked from store (pos = 4):
## 
##     Comp, CrewSkill, CTenure, Hours24, MgrSkill, MTenure,
##     PedCount, Pop, Profit, Res, Sales, ServQual, store, Visibility
   library(car)
## 
## Attaching package: 'car'
## The following object is masked from 'package:psych':
## 
##     logit
   scatterplot(MTenure, Profit,main="Profit vs MTenure")

# scatterplot Profit Vs Ctenure

attach(store)
## The following object is masked _by_ .GlobalEnv:
## 
##     store
## The following objects are masked from store (pos = 4):
## 
##     Comp, CrewSkill, CTenure, Hours24, MgrSkill, MTenure,
##     PedCount, Pop, Profit, Res, Sales, ServQual, store, Visibility
## The following objects are masked from store (pos = 5):
## 
##     Comp, CrewSkill, CTenure, Hours24, MgrSkill, MTenure,
##     PedCount, Pop, Profit, Res, Sales, ServQual, store, Visibility
## The following objects are masked from store (pos = 6):
## 
##     Comp, CrewSkill, CTenure, Hours24, MgrSkill, MTenure,
##     PedCount, Pop, Profit, Res, Sales, ServQual, store, Visibility
   library(car)
   scatterplot(CTenure, Profit,main="Profit vs CTenure")

# creating correlation matrix

CorMat <- cor(store)
round(CorMat, digits = 2)
##            store Sales Profit MTenure CTenure   Pop  Comp Visibility
## store       1.00 -0.23  -0.20   -0.06    0.02 -0.29  0.03      -0.03
## Sales      -0.23  1.00   0.92    0.45    0.25  0.40 -0.24       0.13
## Profit     -0.20  0.92   1.00    0.44    0.26  0.43 -0.33       0.14
## MTenure    -0.06  0.45   0.44    1.00    0.24 -0.06  0.18       0.16
## CTenure     0.02  0.25   0.26    0.24    1.00  0.00 -0.07       0.07
## Pop        -0.29  0.40   0.43   -0.06    0.00  1.00 -0.27      -0.05
## Comp        0.03 -0.24  -0.33    0.18   -0.07 -0.27  1.00       0.03
## Visibility -0.03  0.13   0.14    0.16    0.07 -0.05  0.03       1.00
## PedCount   -0.22  0.42   0.45    0.06   -0.08  0.61 -0.15      -0.14
## Res        -0.03 -0.17  -0.16   -0.06   -0.34 -0.24  0.22       0.02
## Hours24     0.03  0.06  -0.03   -0.17    0.07 -0.22  0.13       0.05
## CrewSkill   0.05  0.16   0.16    0.10    0.26  0.28 -0.04      -0.20
## MgrSkill   -0.07  0.31   0.32    0.23    0.12  0.08  0.22       0.07
## ServQual   -0.32  0.39   0.36    0.18    0.08  0.12  0.02       0.21
##            PedCount   Res Hours24 CrewSkill MgrSkill ServQual
## store         -0.22 -0.03    0.03      0.05    -0.07    -0.32
## Sales          0.42 -0.17    0.06      0.16     0.31     0.39
## Profit         0.45 -0.16   -0.03      0.16     0.32     0.36
## MTenure        0.06 -0.06   -0.17      0.10     0.23     0.18
## CTenure       -0.08 -0.34    0.07      0.26     0.12     0.08
## Pop            0.61 -0.24   -0.22      0.28     0.08     0.12
## Comp          -0.15  0.22    0.13     -0.04     0.22     0.02
## Visibility    -0.14  0.02    0.05     -0.20     0.07     0.21
## PedCount       1.00 -0.28   -0.28      0.21     0.09    -0.01
## Res           -0.28  1.00   -0.09     -0.15    -0.03     0.09
## Hours24       -0.28 -0.09    1.00      0.11    -0.04     0.06
## CrewSkill      0.21 -0.15    0.11      1.00    -0.02    -0.03
## MgrSkill       0.09 -0.03   -0.04     -0.02     1.00     0.36
## ServQual      -0.01  0.09    0.06     -0.03     0.36     1.00

Correlation between profit and MTenure and CTenute

 Cor1 <- cor(store$Profit,store$MTenure)
round(Cor1, digits = 2)
## [1] 0.44
Cor2 <- cor(store$Profit,store$CTenure)
round(Cor2, digits = 2)
## [1] 0.26

Profit has higher correlation with MTenure(0.44) than with CTenure(0.26)

  library(corrgram)
library(ellipse)
## 
## Attaching package: 'ellipse'
## The following object is masked from 'package:car':
## 
##     ellipse
corrgram(store, upper.panel=panel.pie,main= "Corrgram of store variables" )

A postive correlation exists between profit and MTenure, profit and pop, profit and PedCount(the dark blue one in profit row). A weak postive correlation exists between Profit and CTenure, profit and CrewSkill ,profit and MgrSkill and profit and ServQual(light blue one profit row). A negative correlation exists between profit and Comp,Res and Hours24(red one in profit row).

Correlation between profit and MTenure is stronger than the correlation between profit and CTenure. So keeping this in mind, decisions can be taken accordingly to extend tenure in order to improve store performance or not.But before making any decision also note that correlation is not the cause so as a manager our task should be to find root cause of this correlation before making any decision.

pearson’s correlation test between Profit and MTenure

cor.test(store$Profit,store$MTenure)
## 
##  Pearson's product-moment correlation
## 
## data:  store$Profit and store$MTenure
## t = 4.1731, df = 73, p-value = 8.193e-05
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.2353497 0.6055175
## sample estimates:
##       cor 
## 0.4388692

Pearson test p-value = 8.19e-05 #pearson’s correlation test between Profit and CTenure

cor.test(store$Profit,store$CTenure)
## 
##  Pearson's product-moment correlation
## 
## data:  store$Profit and store$CTenure
## t = 2.2786, df = 73, p-value = 0.02562
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.03262507 0.45786339
## sample estimates:
##       cor 
## 0.2576789

Pearson test p-value = 0.026

fit <- lm(Profit ~ MTenure + CTenure + Comp + Pop + PedCount + Res + Hours24 + Visibility,data = store )
summary(fit)
## 
## Call:
## lm(formula = Profit ~ MTenure + CTenure + Comp + Pop + PedCount + 
##     Res + Hours24 + Visibility, data = store)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -105789  -35946   -7069   33780  112390 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   7610.041  66821.994   0.114 0.909674    
## MTenure        760.993    127.086   5.988 9.72e-08 ***
## CTenure        944.978    421.687   2.241 0.028400 *  
## Comp        -25286.887   5491.937  -4.604 1.94e-05 ***
## Pop              3.667      1.466   2.501 0.014890 *  
## PedCount     34087.359   9073.196   3.757 0.000366 ***
## Res          91584.675  39231.283   2.334 0.022623 *  
## Hours24      63233.307  19641.114   3.219 0.001994 ** 
## Visibility   12625.447   9087.620   1.389 0.169411    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 56970 on 66 degrees of freedom
## Multiple R-squared:  0.6379, Adjusted R-squared:  0.594 
## F-statistic: 14.53 on 8 and 66 DF,  p-value: 5.382e-12

Explanatory variables whose beta-coefficient are statistically significant(p-value<0.05) : MTenure,CTenure,Comp,Pop,PedCount,Res,Hours24. Explanatory variables whose beta-coefficient are not statistically significant(p-value>0.05): Visibility (does not matter, Ahh!)

Expected increase in Profit by increasing Manager’s tenure by one month in Store24: 760.993 Expected increase in Profit by increasing Crew’s tenure by one month in Store24: 944.978 (it’s surprising that correlation between profit and MTenure is higher than Profit and CTenure but beta value of MTenure less than CTenure)

Executive summary

From the above analysis and regression, In Store24, mean sale = 1205413.12 and median sale = 1227332.0, not to much diffrence in mean and median, so there is possiblity that data is uniformly distributed(not to much outliers). One of the explaination for CTenure has higher beta-coefficient with profit than MTtenure is it’s standard deviation is 17.7 which is less than MTenure’s standard deviation = 57.67. If we see the corrgram plot, we find higher correlation between profit and Manager’s Tenure, Population and Pedesterian Count while Visibility of store have negative correlation and also not statistically significant, which is very surprising and need a real world analysis to find root cause of occurance. R-square(coefficient of determination) is more than 50%, which means all the variables taken to explain variation in profit are significant.While adjusted R-square is less than R-square, so adding more variable is not right way to reduce error.May be there is some other factors that are affecting sales. F-statistic value is not so high so taking 8 variable all together is not fruitful inspite of that indivisual analysis need to done. Opening store for 24 hours is profitable for stores. Although p-value of visibility is statistically significant but beta coefficient is high so it really matter for sales.