# Nezavislost nahodnych velicin # 1. priklad rm(list=ls()) load("cviceni12.RData") tab <- data12$pr1 attach(tab) tab # vytvoreni kontingencni tabulky (ct <- xtabs(count~type+social)) #mosaicplot(t(ct)) # Pearsonuv test dobre shody (test <- chisq.test(ct)) # Crameruv koeficient n <- sum(ct) m <- min(dim(ct)) K <- test$statistic (Cramer <- sqrt(K/(n*(m-1)))) detach(tab) #-------------------------------- # 2. priklad tab <- data12$pr2 attach(tab) alpha <- 0.05 tab # vytvoreni kontingencni tabulky (ct <- xtabs(pocty~prijeti+dojem)) #mosaicplot(t(ct)) # Interval spolehlivosti a <- ct[1,1] b <- ct[1,2] c <- ct[2,1] d <- ct[2,2] lnOR <- log(a*d/(b*c)) lnD <- lnOR - sqrt(1/a+1/b+1/c+1/d)*qnorm(1-alpha/2) lnH <- lnOR + sqrt(1/a+1/b+1/c+1/d)*qnorm(1-alpha/2) exp(c(lnD,lnH)) # Pomoci klasicke kontingencni tabulky # Pearsonuv test dobre shody (test <- chisq.test(ct)) # Crameruv koeficient n <- sum(ct) m <- min(dim(ct)) K <- test$statistic (Cramer <- sqrt(K/(n*(m-1)))) detach(tab) #----------------------------------------------------- # 3. priklad tab <- data12$pr3 tab library(Hmisc) analyza <- rcorr(tab,type="spearman") (Spearmanuv_koeficient <- analyza$r[1,2]) (p_hodnota <- analyza$P[1,2]) #----------------------------------------------------- # 4. priklad tab <- data12$pr4 tab x <- tab[,1] y <- tab[,2] (analyza <- cor.test(x,y,alternative="greater")) #----------------------------------------------------- # 5. priklad R <- 0.85 c <- 0.9 alpha <- 0.05 n <- 600 Z <- 1/2*log((1+R)/(1-R)) (U <- (Z - 1/2*log((1+c)/(1-c)) - c/(2*(n-1)))*sqrt(n-3)) (obor_prijeti <- c(-qnorm(1-alpha/2),qnorm(1-alpha/2))) #----------------------------------------------------- # 6. priklad R1 <- 0.65 R2 <- 0.37 alpha <- 0.05 n1 <- 100 n2 <- 142 Z1 <- 1/2*log((1+R1)/(1-R1)) Z2 <- 1/2*log((1+R2)/(1-R2)) (U <- (Z1 - Z2)/sqrt(1/(n1-3)+1/(n2-3))) (obor_prijeti <- c(-qnorm(1-alpha/2),qnorm(1-alpha/2))) #----------------------------------------------------- # 7. priklad tab <- data12$pr7 tab x <- tab[,1] y <- tab[,2] (analyza <- cor.test(x,y)) R <- cor(x,y) alpha <- 0.05 n <- 10 Z <- 1/2*log((1+R)/(1-R)) (U <- tanh(c(Z - qnorm(1-alpha/2)/sqrt(n-3),Z + qnorm(1-alpha/2)/sqrt(n-3)))) #-------------------------------------------------------------------------------