library(nortest) # ukol 1 #nagenerovane datove soubory n=30 set.seed(1235) x1=runif(n,-5,5) x2=rlogis(n) x3=c(rexp(15,3),-rexp(15,3)) x3=sample(x3,n) x4=rt(n,3) x5=rnorm(n) x6=rcauchy(n) x7=rchisq(n,5)-5 x8=log(rexp(n,1)) x9=c(rnorm(n-3),rcauchy(3)) x9=sample(x9,n) x10=c(rnorm(n-2),-3,3) x10=sample(x10,n) #(a) par(mfrow=c(1,2)) hist(x1,freq=FALSE) curve(dnorm(x,mean=mean(x1),sd=sd(x1)),col=2,add=TRUE) plot(density(x1),ylim=c(0,0.15)) curve(dnorm(x,mean=mean(x1),sd=sd(x1)),col=2,add=TRUE) boxplot(x1) #(b) qqnorm(x1) qqline(x1) #(c) plot(ppoints(n,0),pnorm((sort(x1) - mean(x1))/sd(x1))) abline(0,1) #(d) shapiro.test(x1) lillie.test(x1) pearson.test(x1) # ukol 2 n=50 zam=0 zam2=0 zam3=0 pval=0 pval2=0 pval3=0 set.seed(1234) for (i in 1:10000){ x=rnorm(n) #x=rexp(n) pval[i]=ks.test(x,"pnorm",0,1)$p.value if (pval[i]<0.05) zam=zam+1 pval2[i]=ks.test(x,"pnorm",mean(x),sd(x))$p.value if (pval2[i]<0.05) zam2=zam2+1 pval3[i]=lillie.test(x)$p.value if (pval3[i]<0.05) zam3=zam3+1 } par(mfrow=c(3,1)) hist(pval, main="Zname parametry") hist(pval2, main="Odhadnute parametry") hist(pval3, main="Lillieforsova varianta") print(c("Empiricka hladina vyznamnosti pro K-S test se znamymi parametry v procentech:",zam/100)) print(c("Empiricka hladina vyznamnosti pro K-S test s odhadnutymi parametry v procentech:",zam2/100)) print(c("Empiricka hladina vyznamnosti pro Lillieforsovu variantu K-S testu v procentech:",zam3/100))