reading data

test.df = read.csv("SubAdvData.csv")
attach(test.df)

Q.1a Write R code to display the following output regarding the number of restaurants

tab1 <- table(adType,restaurantType)
addmargins(tab1,c(1,2))
##           restaurantType
## adType     chain independent   Sum
##   Curr Ads  2023        2972  4995
##   New Ads   1958        3010  4968
##   No Ads    2003        3034  5037
##   Sum       5984        9016 15000

Q.1b Write R code to display the following output regarding the percentages of restaurants

prop_table <- prop.table(tab1)
round(prop_table,2)
##           restaurantType
## adType     chain independent
##   Curr Ads  0.13        0.20
##   New Ads   0.13        0.20
##   No Ads    0.13        0.20

Q.1c Write R code to display the following output regarding average number of reservations

aggregate(reservations, by= list(restaurantType),mean)
##       Group.1        x
## 1       chain 42.58205
## 2 independent 32.50688

Q.1d Write R code to display the following output regarding average number of reservations

aggregate(reservations, by= list(adType),mean)
##    Group.1        x
## 1 Curr Ads 34.03283
## 2  New Ads 41.62762
## 3   No Ads 33.96724

Q 2a

cor(reservations, phoneCalls, method ="pearson")
## [1] 0.6516813
cor(reservations, phoneCalls, method ="spearman")
## [1] 0.6628822

Q 2b

cor.test(reservations, phoneCalls, method = "pearson")
## 
##  Pearson's product-moment correlation
## 
## data:  reservations and phoneCalls
## t = 105.22, df = 14998, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.6423774 0.6607932
## sample estimates:
##       cor 
## 0.6516813

Q 2c

prop.test(x = 4995 , n = 15000 ,p = 0.4, correct = FALSE)
## 
##  1-sample proportions test without continuity correction
## 
## data:  4995 out of 15000, null probability 0.4
## X-squared = 280.56, df = 1, p-value < 2.2e-16
## alternative hypothesis: true p is not equal to 0.4
## 95 percent confidence interval:
##  0.3255016 0.3405839
## sample estimates:
##     p 
## 0.333

Q 2d

res <-t.test(reservations, mu = 40.00)
res
## 
##  One Sample t-test
## 
## data:  reservations
## t = -53.711, df = 14999, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 40
## 95 percent confidence interval:
##  36.39943 36.65297
## sample estimates:
## mean of x 
##   36.5262

Q 2 e

ReservationChain <- subset(test.df, 
                            restaurantType=="chain",select = reservations)
ReservationIndependent <- subset(test.df, 
                            restaurantType=="independent",select = reservations)
tst <- t.test(ReservationChain, ReservationIndependent, var.equal = TRUE)
tst
## 
##  Two Sample t-test
## 
## data:  ReservationChain and ReservationIndependent
## t = 97.503, df = 14998, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   9.872633 10.277718
## sample estimates:
## mean of x mean of y 
##  42.58205  32.50688