##Construir la banda de confianza para Fn a partir de la desigualdad DKV

n<-100
alfa=0.05
x<-rnorm(n)
eps=sqrt(1/(2*n)*log(2/alfa))

Fn<-ecdf(x)
t<-seq(min(x),max(x),by=0.01)
L=pmax(Fn(t)-eps,0)
U=pmin(Fn(t)+eps,1)

plot(Fn, do.points=FALSE)
lines(t,L,col="green",type="s")
lines(t,U,col="green", type="s")
lines(pnorm(t)~t,col="blue",lwd=2)


## Construcción de las bandas de confianza a partir de la
# distribución límite

# Con F

L2<-pmax(Fn(t)-qnorm(1-alfa/2)*sqrt(pnorm(t)*(1-pnorm(t))/n),0)
U2<-pmin(Fn(t)+qnorm(1-alfa/2)*sqrt(pnorm(t)*(1-pnorm(t))/n),1)

plot(Fn, do.points=FALSE)
lines(t,L2,col="green",type="s")
lines(t,U2,col="green", type="s")
lines(pnorm(t)~t,col="blue",lwd=2)

# Con Fn

L3<-pmax(Fn(t)-qnorm(1-alfa/2)*sqrt(Fn(t)*(1-Fn(t))/n),0)
U3<-pmin(Fn(t)+qnorm(1-alfa/2)*sqrt(Fn(t)*(1-Fn(t))/n),1)
windows()
plot(Fn, do.points=FALSE)
lines(t,L3,col="green",type="s")
lines(t,U3,col="green", type="s")
lines(pnorm(t)~t,col="blue",lwd=2)
