###Practicals 5
#task 1
test.res<-chisq.test(c(10,25,18,6), p = rep(0.25, 4))
test.res
# Chi-squared test for given probabilities
# 
# data:  c(10, 25, 18, 6)
# X-squared = 14.559, df = 3, p-value = 0.002235

test.res$observed-test.res$expected
# [1] -4.75 10.25  3.25 -8.75

#task 2
chisq.test(c(125,60,50,12), p = c(9/16, 3/16, 3/16, 1/16))
# Chi-squared test for given probabilities
# 
# data:  c(125, 60, 50, 12)
# X-squared = 6.5025, df = 3, p-value = 0.08956

#task 3
pchisq(5.04, df=3, lower.tail = F )
# 0.1688915

1-pchisq(5.04, df=3, lower.tail = T )

#task 4
qchisq(0.05, 3, lower.tail = F)
# [1] 7.814728
qchisq(0.01, 3, lower.tail = F)
# [1] 11.34487

qchisq(0.05, 8, lower.tail = F)
# [1] 15.50731
qchisq(0.01, 8, lower.tail = F)
# [1] 20.09024

#task 5
chisq.test(c(6,4), p=c(0.5,0.5))
# 
# Chi-squared test for given probabilities
# 
# data:  c(6, 4)
# X-squared = 0.4, df = 1, p-value = 0.5271

chisq.test(c(60,40), p=c(0.5,0.5))
# Chi-squared test for given probabilities
# 
# data:  c(60, 40)
# X-squared = 4, df = 1, p-value = 0.0455

chisq.test(c(600,400), p=c(0.5,0.5))
# 
# Chi-squared test for given probabilities
# 
# data:  c(600, 400)
# X-squared = 40, df = 1, p-value = 2.54e-10
