#========================================================== # P R I K L A D 9.1 #========================================================== skull.BF <- c(133, 134, 132, 137, 135, 135, 136, 137, 135, 137, 137, 136, 139, 126, 130) sum(skull.BF) shapiro.test(skull.BF) # Data nepochazi z normalniho rozdeleni # Znamenkovy test library(PASWR) SIGN.test(skull.BF, md = 131, alt = 'two.sided') # test. statistika, IS, p-hodnota (n <- sum(skull.BF - 131 != 0)) # pocet nenulovych rozdilu # kriticky obor -> viz tabulky # Wilcoxonuv test wilcox.test(skull.BF, mu = 131, alternative = 'two.sided', conf.int = T, correct = F, exact = F ) # IS, p-hodnota, cast testovaci statistiky (S1 <- 109.5) (n <- sum(skull.BF -131 != 0)) # pocet nenulovych rozdilu (S2 <- n * (n+1)/2 - S1) (Sw <- min(S1, S2)) # testovaci statistika # kriticky obor -> viz tabulky #========================================================== # P R I K L A D 9.2 #========================================================== data <- read.delim('03-paired-means-clavicle2.txt') data <- na.omit(data) L <- data[data$sex == 'f', 'length.L'] R <- data[data$sex == 'f', 'length.R'] Z <- L - R # rozdily length(Z) nortest::lillie.test(Z) # Rozdily nepochazi z normalniho rozdeleni # Znamenkovy test SIGN.test(Z, md = 0, alternative = 'greater') # test. statistika, IS, p-hodnota (n <- sum(Z - 0 != 0)) # pocet nenulovych rozdilu # kriticky obor -> viz tabulky # Wilcoxonuv test wilcox.test(Z, mu = 0, alternative = 'greater', conf.int = T, correct = F, exact = F) # cast test. statistiky, IS, p-hodnota (S1 <- 628) (S2 <- n*(n+1)/2 - S1) (Sw <- min(S1, S2)) # test. statistika # kriticky obor -> viz tabulky #========================================================== # P R I K L A D 9.3 #========================================================== skull.BF <- c(133, 134, 132, 137, 135, 135, 136, 137, 135, 137, 137, 136, 139, 126, 130) skull.BM <- c(132, 132, 133, 130, 143, 132, 137) sum(skull.BM) shapiro.test(skull.BM) # Data pro muze nepochazi z normalniho rozdeleni shapiro.test(skull.BF) # Data pro zeny nepochazi z normalniho rozdeleni # Wilcoxonuv test wilcox.test(skull.BM, skull.BF, alt = 'two.sided', correct = F, exact = F, conf.int = T) # cast test. statistiky, IS, p-hondota n1 <- 7 n2 <- 15 (U1 <- 39.5) (U2 <- n1 * n2 - U1) (Uw <- min(U1, U2)) # testovaci statistika # kriticky obor -> viz tabulky #========================================================== # P R I K L A D 10.1 #========================================================== data <- data.frame( svetla = c(1768, 946, 115), kastan = c(807, 1387, 438), cerna = c(189, 746, 288), rezava = c(47, 53, 16), row.names = c('morda', 'zelena', 'hneda') ) round(chisq.test(data, correct = F)$expected, 1) # podminka dobre aproximace splnena chisq.test(data, correct = F) # test. statistika K, p-hodnota chisq.test(data, correct = F)$p.val # presna p-hodnota alpha <- 0.05 r <- 3 s <- 4 qchisq(1 - alpha, (r-1)*(s-1)) # kriticky obor lsr::cramersV(data, correct = T) # Crameruv koeficient - funkci K <- 1073.5 n <- 6800 m <- min(3,4) (V <- sqrt(K / (n * (m-1)))) # Crameruv koeficient - vzorcem #========================================================== # P R I K L A D 10.2 #========================================================== data <- data.frame(muzi = c(20, 30), zeny = c(30, 20), row.names = c('A', 'B')) fisher.test(data) # Fisheruv faktorialovy (presny test); p-hodnota #========================================================== # P R I K L A D 10.3 #========================================================== chisq.test(data, correct = F)$exp # podminka dobre aproximace a <- 20 b <- 30 c <- 30 d <- 20 (OR <- (a * d) / (b * c)) # podil sanci log(OR) # logaritmus podilu sanci (t0 <- log(OR) / sqrt(1/a + 1/b + 1/c + 1/d)) # testoaci statistika alpha <- 0.05 qnorm(alpha / 2) # kriticky obor qnorm(1 - alpha/2) # kriticky obor (dh <- log(OR) - sqrt(1/a + 1/b + 1/c + 1/d) * qnorm(1-alpha / 2)) # dolni hranice IS (hh <- log(OR) - sqrt(1/a + 1/b + 1/c + 1/d) * qnorm(alpha / 2)) # horni hranice IS 2 * min (pnorm(t0), 1 - pnorm(t0)) # p-hodnota 1/OR # 1/podil sanci (lepsi interpretace, protoze v tomto priklade vyslo OR < 1, kdezto 1/OR > 1) chisq.test(data, correct = F) # Pearsonuv test bez korekce (analogie rucniho vypoctu) chisq.test(data, correct = T) # Pearsonuv test s korekci (lepsi verze)