# Two-way ANOVA test using Icecream data set.
# Store the data in the variable mydata
mydata2 <- read.csv('icecream.csv')
# Research Question:Is there an association between gender and preference for ice cream flavor?
#H0 = two variables are independent
#H1 = two variables are related
# Generate frequency table. If values in all cells are same, then have a balanced design.
cam <- table(mydata2$Gender, mydata2$Flavor)
#chisquare test
#the p-value is extremely low, then there is a lot of tilt to the
#stacks (the counts are not likely to be from chance).
chisq.test(cam)
##
## Pearson's Chi-squared test
##
## data: cam
## X-squared = 28.362, df = 2, p-value = 6.938e-07
#critical value
#Chi Square value >= Critical Value, reject the null hypothesis that means accepting two variables
#are related
qchisq(0.95,2)
## [1] 5.991465