##7 Exercise

#7.1 Exercice 1 Please work out in R by doing a chi-squared test on the treatment (X) and improvement (Y) columns in treatment.csv

data_frame <- read.csv("treatment.csv")

table(data_frame$treatment, data_frame$improvement)
##              
##               improved not-improved
##   not-treated       26           29
##   treated           35           15
#chi-sq test
chisq.test(data_frame$treatment, data_frame$improvement, correct=FALSE)
## 
##  Pearson's Chi-squared test
## 
## data:  data_frame$treatment and data_frame$improvement
## X-squared = 5.5569, df = 1, p-value = 0.01841

*We have a chi-squared value of 5.5569. Since we get a p-Value less than the significance level of 0.05.

#7.2 Exercice 2 Find out if the cyl and carb variables in mtcars dataset are dependent or not.

data(mtcars)
table(mtcars$carb, mtcars$cyl)
##    
##     4 6 8
##   1 5 2 0
##   2 6 0 4
##   3 0 0 3
##   4 0 4 6
##   6 0 1 0
##   8 0 0 1
#chi-sq tes
chisq.test(mtcars$carb, mtcars$cyl)
## Warning in chisq.test(mtcars$carb, mtcars$cyl): Chi-squared approximation may be
## incorrect
## 
##  Pearson's Chi-squared test
## 
## data:  mtcars$carb and mtcars$cyl
## X-squared = 24.389, df = 10, p-value = 0.006632

*We have a high chi-squared value and a p-value of less than 0.05 significance level. So we reject the null hypothesis and conclude that carb and cyl have a significant relationship. So the cyl and carb variables in mtcars dataset are independent

#7.3 Exercise 3 256 visual artists were surveyed to find out their zodiac sign. The results were: Aries (29), Taurus (24), Gemini (22), Cancer (19), Leo (21), Virgo (18), Libra (19), Scorpio (20), Sagittarius (23), Capricorn (18), Aquarius (20), Pisces (23). Test the hypothesis that zodiac signs are evenly distributed across visual artists. (Reference)

#Here we input the data as data frame
Births <- c(29, 24, 22, 19, 21, 18, 19, 20, 23, 18, 20, 23)

#The simple method
chisq.test(Births)
## 
##  Chi-squared test for given probabilities
## 
## data:  Births
## X-squared = 5.0938, df = 11, p-value = 0.9265

*p-value=0.9265, if the p-value is greater than significant. Then h0 was accepted, where h0 indicated that the zodiac signs were evenly distributed across visual artists.