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.
df <- read.csv("https://raw.githubusercontent.com/Bakti-Siregar/dataset/master/treatment.csv")
table(df$treatment, df$improvement)
##
## improved not-improved
## not-treated 26 29
## treated 35 15
chisq.test(df$treatment, df$improvement, correct=FALSE)
##
## Pearson's Chi-squared test
##
## data: df$treatment and df$improvement
## X-squared = 5.5569, df = 1, p-value = 0.01841
from the calculation above we have a chi-squared value of 5.55. Since we get a p-Value less than the significance level of 0.05, we reject the null hypothesis and conclude that the two variables are dependent.
7.2 Exercice 2
Find out if the cyl and carb variables in mtcars dataset are dependent or not.
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
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
from the calculation above We have a high chi-squared value and a p-value of less that 0.05 significance level. So we reject the null hypothesis and we can conclude that cyl and carb have a significant relationship.
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.