#1) library(MASS) #exponencialni model lambda<-fitdistr(data, "exponential")$estimate[1] #normalni model mu<-fitdistr(data, "normal")$estimate[1] sigma<-fitdistr(data, "normal")$estimate[2] #lognormalni model muL<-fitdistr(data, "lognormal")$estimate[1] sigmaL<-fitdistr(data, "lognormal")$estimate[2] #logisticky model loc<-fitdistr(data, "logistic")$estimate[1] scale<-fitdistr(data, "logistic")$estimate[2] #a) x1<-100000 1-ecdf(data)(x1) 1-pexp(x1,lambda) 1-pnorm(x1,mu,sigma) 1-plnorm(x1,muL,sigmaL) 1-plogis(x1,loc,scale) #b) x2<-1000000 1-ecdf(data)(x2) 1-pexp(x2,lambda) 1-pnorm(x2,mu,sigma) 1-plnorm(x2,muL,sigmaL) 1-plogis(x2,loc,scale) #c) q1<-0.999 quantile(data,q1) qexp(q1,lambda) qnorm(q1,mu,sigma) qlnorm(q1,muL,sigmaL) qlogis(q1,loc,scale) #d) q2<-0.9999 quantile(data,q2) qexp(q2,lambda) qnorm(q2,mu,sigma) qlnorm(q2,muL,sigmaL) qlogis(q2,loc,scale) #2.) data<-c(rep(0,4),rep(1,6),rep(2,6),rep(3,8),rep(4,3),6,6,10) n<-length(data) table(data)/n lambda<-fitdistr(data,"Poisson")$estimate[1] lambda #a) x<-(0:10) #graf relativnich cetnosti a odhadnute pravd. funkce plot(table(data)/n, type='p',ylim=c(0,0.3),ylab='pravdepodobnost') points(dpois(x,lambda)~x,col=2,type='h') #graf empiricke a odhadnute distribucni funkce plot(ecdf(data),main="Empiricka distribucni funkce") curve(ppois(x,lambda),col=2,add=TRUE) #graf rozdilu obou funkci D<-function(x){ D<-ecdf(data)(x)- ppois(x,lambda) } curve(D,0,15,col=2,ylim=c(-0.07,0.07),ylab="D(x)") abline(h=0) #b) #spocitame ocekavane cetnosti pro hodnoty 0-10 dpois(x,lambda)*n #musime nektere hodnoty sloucit: 0,1,2,3,4,5+ k<-6 #pocet trid prob<-c(dpois(c(0,1,2,3,4),lambda),1-ppois(4,lambda)) #teoreticke pravdepodobnosti hk<-c(4,6,6,8,3,3) #pozorovane cetnosti #porovnani ocekavanych a pozorovanych cetnosti n*prob hk chisq.test(hk,p=prob) #test pouzijeme jen pro vypocet testove statistiky (nesedi stupne volnosti)) X2<-chisq.test(hk,p=prob)$statistic 1-pchisq(X2,k-2) #hledana p-hodnota