### 3. ZAKLADNI CISELNE CHARAKTERISTIKY

## 3.1 CISELNE CHARAKTERISTIKY PRO NOMINALNI ZNAKY
# 3.1
(data <- data.frame(absence = c(30,	56,	16),
                    small	= c(20,	37,	6),
                    large =	c(10,	17, 13), 
                    row.names = c('european', 'african', 'inuits')))

(nj <- apply(data, MARGIN = 1, FUN = sum))
(nj <- rowSums(data))

(n.k <- apply(data, MARGIN = 2, FUN = sum))
(n.k <- colSums(data))

# 3.2
#install.packages('lsr')
lsr::cramersV(data)


## 3.2 CISELNE CHARAKTERISTIKY PRO ORDINALNI ZNAKY
# 3.3
data <- read.delim('TO-DO', sep = '\t')
data <- 'TO-DO' # vynechani NA
data.F <- data['TO-DO']
'TO-DO' # dimenze souboru

# minimalni hodnota
edu <- data.F$edu.M
edu.sort <- sort(edu) # serazena data
n <- length(edu) 
min.e <- min(edu) 


# dolni kvartil
alpha <- 0.25
alpha * n # pokud neni cele cislo -> zaokrouhleni
n.alpha <- ceiling(alpha * n) 
edu.sort[n.alpha]                          
x0.25 <- quantile(edu, probs = 0.25, type = 2) 

# median
alpha <- 0.5
alpha * n                                       
x0.5 <- (edu.sort['TO-DO'] + edu.sort['TO-DO']) / 2            
x0.5 <- quantile('TO-DO', probs = 0.50, type = 2)  
x0.5 <- median(edu, type = 2)                  

# horni kvartil
alpha <- 'TO-DO'
alpha * n                                       
'TO-DO' # zaokrouhleni                              
x0.75 <- 'TO-DO'                          

# maximum
max.e <- max('TO-DO') 

# interkvartilove rozpeti (IQR)
IQR.e <- x0.75 - x0.25 
iqr.e <- IQR(edu, type = 2) #jiny zpusob

# alternativni zpusob vypoctu kvartilu v jednom radku
q.e <- quantile(edu, probs = c (0.25 , 0.50 , 0.75) , type = 2)
# potrebny kvartil potom vybiram pomoci []

# shrnuti
(tab <- data.frame(min = min.e, dolni.kv = x0.25, median = x0.5, 
                   horni.kv = x0.75, max = max.e, IQR = IQR.e))

# 3.4
boxplot('TO-DO', las = 1, col = 'darkolivegreen1', 
        border = 'chartreuse4', medcol = 'darkgreen', xlab = '') # xlab je nizko
mtext('vzdelani matky', side = 1, line = 1)

# 3.5
cor('TO-DO', 'TO-DO', method = 'spearman')

'TO-DO' # samostatne zkuste totez pro novorozence muzskeho pohlavi


## 3.2 CISELNE CHARAKTERISTIKY PRO INTERVALOVE ZNAKY
# 3.6
data <- 'TO-DO'
'TO-DO' # odstraneni NA 

skull.BM <- data['TO-DO', 'skull.B'] # vyber pouze muzi, promenna skull.B



m <- 'TO-DO' # prumer
n <- 'TO-DO' # pocet hodnot
s2 <- 1 / (n-1) * sum((skull.BM - m)^2) #rozptyl pomoci vzorce
s <- sqrt(s2) # 4.813461
var(skull.BM) # rozptyl
sd(skull.BM) # smerodatna odchylka


# minimum, maximum, kvartily, IQR
min.BM <- 'TO-DO'
max.BM <- 'TO-DO'
x0.25 <- quantile('TO-DO', probs = 'TO-DO', type = 2) 
x0.50 <- 'TO-DO'
x0.75 <- 'TO-DO'
IQR.BM <- 'TO-DO'

# sikmost, spicatost
# install.packages("e1071")
# library(e1071)
sikmost <- e1071::skewness(skull.BM, type = 3)    
spicatost <- e1071::kurtosis(skull.BM, type = 3)  

# pozn. sikmost a spicatost jsou take v knihovne "moments", 
# ale tam se pro vypocet spicatosti pouziva jiny vzorec

# shrnuti
tab <- data.frame(m, s, min = min.BM, dolni.kv = x0.25, median = x0.50, horni.kv = x0.75, 
                  max = max.BM, IQR = IQR.BM, sikmost, spicatost, row.names = c('muzi'))
(tab <- 'TO-DO'(tab, digits = 2)) # zaokrouhlete

# 3.7
skull.BM <- 'TO-DO'
skull.LM <- 'TO-DO'
cor('TO-DO', 'TO-DO', method = 'pearson')

# 3.8
plot('TO-DO', pch = 'TO-DO', col = 'TO-DO',
     xlab = 'nejvetsi sirka mozkovny (mm)', ylab = 'nejvetsi delka mozkovny (mm)', main = '', las = 1)


'TO-DO' # samostatne vypracujte priklady 3.6, 3.7 a 3.8 pro zeny