Komputasi Statistika

~ Tugas 5 ~


Kontak : \(\downarrow\)
Email
Instagram https://www.instagram.com/diasary_nm/
RPubs https://rpubs.com/diyasarya/

Exercise 1

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

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

Answer 1

Hypothesis
H0 : Treatment dan Improvement tidak terdapat hubungan (Independent).
H1 : Treatment dan Improvement terdapat hubungan (Dependent).

table(tr$treatment, tr$improvement)
##              
##               improved not-improved
##   not-treated       26           29
##   treated           35           15
chisq.test(tr$treatment, tr$improvement)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  tr$treatment and tr$improvement
## X-squared = 4.6626, df = 1, p-value = 0.03083

Didapat dari output diatas χ2 = 4.6626 dengan level signifikan 0.05 dan degree of freedom 1 didapat p-value = 0.03083. Yang dimana p-value < 0.05 artinya H0 ditolak atau “Treatment dan Improvement terdapat hubungan (Dependent)”.


Noted : df = (nrow-1)(ncol-1) = (2-1)(2-1)

Exercise 2

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

DT::datatable(mtcars)

Answer 2

Hypothesis
H0 : variabel cyl dan variabel carb tidak terdapat hubungan (Independent).
H1 : variabel cyl dan variabel carb terdapat hubungan (Dependent).

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

Didapat dari output diatas χ2 = 24.389 dengan level signifikan 0.05 dan degree of freedom 10 didapat p-value = 0.006632. Yang dimana p-value < 0.05 artinya H0 ditolak atau “variabel cyl dan variabel terdapat hubungan (Dependent)”.


Noted : df = (nrow-1)(ncol-1) = (3-1)(6-1)

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)

Answer 3

Hypothesis
H0 : zodiak didistribusikan secara merata di seluruh seniman visual.
H1 : zodiak tidak didistribusikan secara merata di seluruh seniman visual.

n = 12
O <- c(29, 24, 22, 19, 21, 18, 19, 20, 23, 18, 20, 23)
E <- rep(256/12, 12)

x = sum((O - E)^2/E)
p = pchisq(x, n-1, lower.tail = F)
cat("x.square =", x, 
    "df =", n-1, 
    "p-value =", p)
## x.square = 5.09375 df = 11 p-value = 0.9265414

Didapat dari output diatas χ2 = 5.09375 dengan level signifikan 0.05 dan degree of freedom 11 didapat p-value = 0.9265414. Yang dimana p-value > 0.05 artinya H0 diterima atau “zodiak didistribusikan secara merata di seluruh seniman visual”.