#------------------ # Testovani hypotez #------------------ # Prvni priklad - chlapci # Nacteni dat load("cviceni3.RData") x <- data3$pr1$x n <- length(x) alpha <- 0.05 # prvni zpusob (ux <- (mean(x)-136.1)/6.4*sqrt(n)) (kvantil <- qnorm(1-alpha)) # druhy zpusob 1 - pnorm(mean(x),mean=136.1,sd=6.4/sqrt(n)) # treti zpusob (D <- mean(x) - kvantil*6.4/sqrt(n)) # ctvrty zpusob #install.packages("TeachingDemos",dependencies=T) library("TeachingDemos") z.test(x, mu = 136.1, alternative = "greater", sd = 6.4) # Druhy priklad - hnojiva # Nacteni dat load("cviceni3.RData") x <- data3$pr2$x y <- data3$pr2$y alpha <- 0.05 n1 <- length(x) n2 <- length(y) s1 <- sd(x) s2 <- sd(y) # a) (f <- (s1/s2)^2) (kvantil1 <- qf(1-alpha/2,n1-1,n2-1)) (kvantil2 <- 1/qf(1-alpha/2,n2-1,n1-1)) # b) 2*min(1-pf(var(x)/var(y),n1-1,n2-1),pf(var(x)/var(y),n1-1,n2-1)) # c) (D <- (s1/s2)^2/kvantil1) (H <- (s1/s2)^2/kvantil2) # d) var.test(x,y) # I prumer_x <- mean(x) prumer_y <- mean(y) s12 <- sqrt(((n1-1)*s1^2+(n2-1)*s2^2)/(n1+n2-2)) (kvantil <- qt(1-alpha/2,n1+n2-2)) (t <- (prumer_x - prumer_y)/s12*sqrt((n1*n2)/(n1+n2))) # II (p <- 2*(1-pt(t,n1+n2-2))) # III (D <- prumer_x - prumer_y - kvantil*s12*sqrt((n1+n2)/(n1*n2))) (H <- prumer_x - prumer_y + kvantil*s12*sqrt((n1+n2)/(n1*n2))) # IV t.test(x,y,var.equal=T) # Treti priklad - listy # Nacteni dat load("cviceni3.RData") x <- data3$pr3$x y <- data3$pr3$y z <- x - y alpha <- 0.05 n <- length(z) prumer <- mean(z) odchylka <- sd(z) kvantil <- qt(1-alpha/2,n-1) # I (t <- prumer/odchylka*sqrt(n)) kvantil # II (p <- 2*(1-pt(t,n-1))) # III (D <- prumer - kvantil*odchylka/sqrt(n)) (H <- prumer + kvantil*odchylka/sqrt(n)) # IV t.test(x,y,paired=T) # Ctvrty priklad - mince # Nacteni dat n <- 40 rub <- 22 lic <- n - rub alpha <- 0.05 # vypocet prumer <- rub/n odchylka <- sqrt(0.5*(1-0.5)) kvantil <- qnorm(1-alpha/2) # I (u <- (prumer - 0.5)*sqrt(n)/odchylka) kvantil # II (p <- 2*(1-pnorm(u))) # III (D <- prumer - kvantil*odchylka/sqrt(n)) (H <- prumer + kvantil*odchylka/sqrt(n)) # IV binom.test(rub,n) #-----------------------------------------------------------------------------------