Chi square test
##Chi Square test
library(readxl)
## Warning: package 'readxl' was built under R version 3.5.2
Bahaman <- read_excel(file.choose()) # Bahaman.xls
View(Bahaman)
attach(Bahaman)
table(Country, Defective)
## Defective
## Country 0 1
## Bangladesh 183 17
## China 179 21
## India 175 25
## Srilanka 178 22
chisq.test(table(Country,Defective))
##
## Pearson's Chi-squared test
##
## data: table(Country, Defective)
## X-squared = 1.7244, df = 3, p-value = 0.6315
# P - value = 0.6315 > 0.05 => accept null hypothesis
# => All countries have equal proportions
Proportinal T test
Johnytalkers <- read_excel(file.choose())
View(Johnytalkers)
attach(Johnytalkers)
table(Icecream,Person)
## Person
## Icecream Adults Children
## Did Not Purchase 422 588
## Purchased 58 152
table1 <- table(Icecream,Person)
View(table1)
table1
## Person
## Icecream Adults Children
## Did Not Purchase 422 588
## Purchased 58 152
prop.test(x=c(58,152),n=c(480,740),conf.level = 0.95,correct = FALSE,alternative = "two.side")
##
## 2-sample test for equality of proportions without continuity
## correction
##
## data: c(58, 152) out of c(480, 740)
## X-squared = 14.613, df = 1, p-value = 0.000132
## alternative hypothesis: two.sided
## 95 percent confidence interval:
## -0.1257722 -0.0433719
## sample estimates:
## prop 1 prop 2
## 0.1208333 0.2054054
prop.test(x=c(58,152),n=c(480,740),conf.level = 0.95,correct = FALSE,alternative = "less")
##
## 2-sample test for equality of proportions without continuity
## correction
##
## data: c(58, 152) out of c(480, 740)
## X-squared = 14.613, df = 1, p-value = 6.599e-05
## alternative hypothesis: less
## 95 percent confidence interval:
## -1.0000000 -0.0499958
## sample estimates:
## prop 1 prop 2
## 0.1208333 0.2054054
#two.sided -> means checking for equal proportions of adults and childern under purchased
# p-value = 6.261e-05 < 0.05 accept alternative hypothesis i.e.
# unequal proportions
# Ha -> proportions of Adults > Porportions of children
# H0 -> Proportions of childeren > Proportions of adults
# p-value = 0.999 > 0.05 accept null hypothesis
# so proportion of childern > proportion of children
# Do not launch the ice cream shop