#========================================================================================= # Pr. 11.4 -- CVICENI 11 -- Test podilem sanci #========================================================================================= data <- data.frame(muzi = c(20, 30), zeny = c(30, 20), row.names = c('A', 'B')) chisq.test(data)$expected # podminka dobre aproximace a <- 20 b <- 30 c <- 30 d <- 20 (OR <- (a/c) / (b/d)) # podil sanci log(OR) # logaritmus podilu sanci (t0 <- log(OR) / sqrt(1/a + 1/b + 1/c + 1/d)) # testovaci statistika alpha <- 0.05 qnorm(alpha/2) # kriticky obor cast 1 qnorm(1 - alpha/2) # kriticky obor cast 2 (dh <- log(OR) - sqrt(1/a + 1/b + 1/c + 1/d) * qnorm(1 - alpha/2)) # IS dolni hranice (hh <- log(OR) - sqrt(1/a + 1/b + 1/c + 1/d) * qnorm(alpha/2)) # IS horni hranice #========================================================================================= # Priklad 12.1 #========================================================================================= X <- c(6, 7, 1, 8, 4, 2.5, 9, 12, 10, 2.5, 5, 11) # poradi odborniku Y <- c(4, 5, 2, 10, 6, 1.0, 7, 11, 8, 3.0, 12, 9) # poradi antropologu cor(X,Y, method='spearman') # Spearmanuv korelacni koeficient library(car) # Test dvourozmerne normality -- graficky -- elipsa spolehlivosti dataEllipse(X, Y, level = 0.95, xlim = c(-7, 20), ylim = c(-7, 20)) #1. exaktni test n <- length(X) (RS <- cor(X, Y, method = 'spearman')) # Spearmanuv korelacni koeficient # kriticky obor; hledame v tabulkach # 2. asymptoticky test (t0 <- RS*sqrt(n-2)/sqrt(1-RS^2)) # testovaci statistika alpha <- 0.05 qt(1 - alpha/2, n - 2) # kriticky obor cast 1 qt(alpha/2, n - 2) # kriticky obor cast 2 2 * min(pt(t0, n - 2), 1 - pt(t0, n - 2)) # p-hdonota #========================================================================================= # Priklad 12.2 #========================================================================================= X <- c(40, 64, 34, 15, 57, 45) # mnozstvi kys. mlecne v krvi matky Y <- c(33, 46, 23, 12, 56, 40) # mnozstvi kys. mlecne v krvi ditete cor(X, Y, method = 'pearson' ) # Pearsonuv korelacni koeficient # Test dvourozmerne normality -- graficky -- elipsa spolehlivosti dataEllipse(X, Y, xlim = c(-20, 100), ylim = c(-20, 100), level = 0.95) #------------------------------------------------------------------------------------- # 1. Exaktni test n <- length(X) R12 <- cor(X, Y, method = 'pearson' ) # Pearsonuv korelacni koeficient (t0 <- R12 / sqrt(1 - R12^2) * sqrt(n - 2)) # testovaci statistika alpha <- 0.05 qt(1 - alpha / 2, n - 2) # kriticky obor cast 1 qt(alpha / 2, n - 2) # kriticky obor cast 2 (dh <- qt(alpha/2, n - 2) / sqrt(qt(alpha/2, n - 2) ^ 2 + n - 2)) # IS - dolni hranice (hh <- qt(1 - alpha/2, n - 2) / sqrt(qt(1 - alpha/2, n - 2) ^ 2 + n - 2)) # IS - horni hranice 2 * min(pt(t0, n - 2), 1 - pt(t0, n - 2)) # p-hodnota #2. Asymptoticky interval spolehlivosti Z <- 1 / 2 * log((1 + R12) / (1 - R12)) # Z-transformace koeficientu R12 DH <- Z - qnorm(1 - alpha/2) / sqrt(n - 3) # dolni hranice IS pro Z-transformaci HH <- Z + qnorm(1 - alpha/2) / sqrt(n - 3) # horni hranice IS pro Z-transformaci tanh(DH) # hyperbolicky tangens dolni hranice -> zpetna transformace IS do skaly korelacniho koeficientu R12 tanh(HH) # hyperbolicky tangens horni hranice -> zpetna transformace IS do skaly korelacniho koeficientu R12