library(bootstrap)
set.seed(10102)

law.mat<-as.matrix(law)
cor(law.mat)[1,2]

n<-nrow(law.mat)

index<-c(1:15)
B<-2000
r.boot<-rep(0,B)
for(b in 1:B){

	ind.boot<-sample(index,size=n,rep=T)
	law.boot<-law.mat[ind.boot,]
	r.boot[b]<-cor(law.boot)[1,2]

}
sd(r.boot)


hist(r.boot,br=seq(0,1,by=0.05),main="Histogram of resampled r",xlab="x",col="black",border="white")
abline(v=cor(law.mat)[1,2],col="red",lwd=2)
abline(v=mean(r.boot),col="red",lwd=2,lty=2)

Z<-sqrt(n-3)*0.5*(log(1+r.boot)-log(1-r.boot))
mv<-mean(Z)
var(Z)




hist(Z,br=seq(0,12.5,by=0.5),ylim=range(0,500),main="Histogram of resampled r",xlab="x",col="black",border="white")
xv<-seq(0,12.5,by=0.05)
yv<-dnorm(xv,mv,1)*B*0.5
lines(xv,yv,col="red",lwd=2)
