abc.ci(bigcity, corr, conf=c(0.90,0.95)) #parameteres bootstrap #a klima mukodesi idejere air.fun <- function(data) { ybar <- mean(data$hours) para <- c(log(ybar),mean(log(data$hours))) ll <- function(k) { if (k <= 0) out <- 1e200 # not NA else out <- lgamma(k)-k*(log(k)-1-para[1]+para[2]) out } khat <- nlm(ll,ybar^2/var(data$hours))$estimate c(ybar, khat) } air.rg <- function(data, mle) # Function to generate random exponential variates. mle will contain # the mean of the original data { out <- data out$hours <- rexp(nrow(out), 1/mle) out } air.boot <- boot(aircondit, air.fun, R=999, sim="parametric", ran.gen=air.rg, mle=mean(aircondit$hours)) # The bootstrap p-value can then be approximated by sum(abs(air.boot$t[,2]-1) > abs(air.boot$t0[2]-1))/(1+air.boot$R) 0.468 #azaz H0 elfogadhato air.rg <- function(data, mle) rexp(length(data), 1/mle) air.boot <- boot(aircondit$hours, mean, R=999, sim="parametric", ran.gen=air.rg, mle=mean(aircondit$hours)) plot(air.boot) # In the difference ####irjunk sajatot #3 reteg, retegenkent 100-200-300 megf # mas es mas ve-vel es szorassal ##### mu=c(10,10+rnorm(1),10+rnorm(1)) sig=c(1,1.5,2) xdat1=rnorm(100,mu[1],sig[1]) xdat2=rnorm(200,mu[2],sig[2]) xdat3=rnorm(300,mu[3],sig[3]) xdat=c(xdat1,xdat2,xdat3) m=mean(xdat) par(mfrow=c(1,3)) hist(xdat1) hist(xdat2) hist(xdat3) xdat=c(xdat1,xdat2,xdat3) #boot1 #pop veletlen, fix elemek N=500 ered=rep(0,times=N) for (i in 1:N) {b=trunc(3*runif(3)+1) ix=rbind(c(1,100),c(101,300),c(301,600)) e=0 for(j in 1:3) e=c(e,xdat[ix[b[j],1]:ix[b[j],2]]) e=e[2:length(e)] ered[i]=mean(e) } hist(ered) #boot2 #pop fix, veletlen elemek N=500 ered2=rep(0,times=N) for (i in 1:N) {e=0 for(j in 1:3) {e=c(e,xdat[ix[j,1]+sample(100*j,replace=T)-1]) e=e[2:length(e)] } ered2[i]=mean(e) } hist(ered2) #boot3 #pop veletlen, veletlen elemek N=500 ered3=rep(0,times=N) for (i in 1:N) {b=trunc(3*runif(3)+1) ix=rbind(c(1,100),c(101,300),c(301,600)) e=0 for(j in 1:3) { e=c(e,xdat[ix[b[j],1]+sample(100*b[j],replace=T)-1]) } e=e[2:length(e)] ered3[i]=mean(e) } hist(ered3) #szoras-proba for (i in 1:100) {mu=c(10,10+rnorm(1),10+rnorm(1)) sig=c(1,1.5,2) xdat4=rnorm(100,mu[3],sig[3]) xdat3=c(xdat3,xdat4)} var(xdat3) #szoras az egeszre ee=rep(0,times=500) for (i in 1:500) { mu=c(10,10+rnorm(1),10+rnorm(1)) sig=c(1,1.5,2) xdat1=rnorm(100,mu[1],sig[1]) xdat2=rnorm(200,mu[2],sig[2]) xdat3=rnorm(300,mu[3],sig[3]) xdat=c(xdat1,xdat2,xdat3) ee[i]=mean(xdat) } par(mfrow=c(1,1)) hist(ee) m=mean(xdat)