# Prvni priklad - ANOVA # nacteni dat rm(list=ls()) load("cviceni8.RData") brambory <- data8$pr1 skup<-factor(rep(c("A","B","C","D"),times=c(4,3,5,3))) attach(brambory) y <- c(A,B,C,D) model <- lm(y~skup) anova(model) # Scheffeho test install.packages("agricolae") library(agricolae) (scheffe.test(model,"skup")) # pripadne Kruskal - Wallisuv test (kruskal(y,skup)) # posouzeni homogenity rozptylu x11(12,9) plot(skup,y,xlab="odrudy",ylab="hmotnost") # graficky library(car) leveneTest(y~skup) # levenuv test bartlett.test(y~skup) # bartlettuv test # posouzeni normality # KS test ks.test((A-mean(A))/sd(A),"pnorm") ks.test((B-mean(B))/sd(B),"pnorm") ks.test((C-mean(C))/sd(C),"pnorm") ks.test((D-mean(D))/sd(D),"pnorm") # Shapiro-Wilk shapiro.test(A) shapiro.test(B) shapiro.test(C) shapiro.test(D) detach(brambory) # Druhy priklad # nacteni dat rm(list=ls()) load("cviceni8.RData") nj <- data8$pr2$nj pj <- data8$pr2$pj source("anovabinom.R") (anovabinom(nj,pj)) # Treti priklad # nacteni dat rm(list=ls()) load("cviceni8.RData") x <- data8$pr3$x y <- data8$pr3$y mod3 <- lm(y~1+x+I(x^2)+I(x^3)) mod2 <- lm(y~1+x+I(x^2)) mod1 <- lm(y~1+x) anova(mod3,mod2) anova(mod2,mod1) x11(width=8,height=5) plot(x,y) curve(predict(mod3,data.frame(x=x)),add=T,col="red") curve(predict(mod2,data.frame(x=x)),add=T,col="green") curve(predict(mod1,data.frame(x=x)),add=T,col="cyan") legend("bottomright",legend=c("M3","M2","M1"),col=c("red","green","cyan"),lty=c(1,1,1)) #----------------------------------------------------------------------------------------