# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
n = 50
sample_unif = runif(n, 0, 1)
sample_norm = rnorm(n, 0.5, sqrt(1/12))
print(sample_norm)
print(sample_unif)


ks.test(sample_norm, sample_unif)

sample_joined = c(sample_norm, sample_unif)
ecdf(sample_joined)

hist(sample_unif, breaks = seq(0, 1, 0.2), col = 'coral1')
par(new = T)
hist(sample_norm, breaks = seq(min(sample_norm), max(sample_norm), diff(range(sample_norm))/5), col = 'deepskyblue')
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
me = 3.55
samp = c(4.8, 4.0, 3.8, 4.3, 3.9, 4.6, 3.1, 3.7)

tt = abs(length(samp[samp < 3.55]) - 4)
print(tt)

dbinom(8, 8, 1/2)
dbinom(0, 8, 1/2)

rank(c(1, 5, 2, 3, 9, 10))
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
q_score = 28
samp = c(51, 53, 43, 36, 55, 55, 39, 43, 45, 27, 21, 26, 22, 43)
hist(samp, breaks = seq(min(samp), max(samp), diff(range(samp))/5))

wilcox.test(samp)

Tt = sum(rank(abs(samp - q_score)))
n = length(samp)
m = n*(n + 1)/4
d = n*(n + 1)*(2*n + 1)/24
x = (Tt - m)/sqrt(d)

1 - pnorm(x)
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
sampA = c(10854, 9106, 10325, 11627, 10051, 10001, 10000, 13720, 11632, 11222)
sampB = c(11000, 11072, 8851, 10245, 11000, 10030, 11197, 10959, 9157, 11513, 9540, 10856)

par(mfrow = 1:2)
hist(sampA, col = 'coral1')
hist(sampB, col = 'deepskyblue')

wilcox.test(sampA, sampB, paired = FALSE)
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
mat = matrix(nrow = 2, ncol = 2, data = c(168, 73, 42, 26), byrow = T)
mat = as.table(mat)
dimnames(mat) = list(vk = c("da", "ne"), proizvodnja = c("da", "ne"))
print(mat)
chisq.test(mat)
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=