## The function is currently defined as
function(E.T,rho,s2=1)
{
N<-dim(E.T)[3]
EM<-NULL
for (t in 1:N){
E<-E.T[,,t]
EM<-rbind(EM,cbind(E[upper.tri(E)],t(E)[upper.tri(E)] )/sqrt(s2))
}
emcp<-sum(EM[,1]*EM[,2])
emss<-sum(EM^2)
m<- nrow(EM)
sr<- 2*(1-cor(EM)[1,2]^2)/sqrt(m)
rho1<-rho+sr*qnorm( runif(1,pnorm( (-1-rho)/sr),pnorm( (1-rho)/sr)))
lhr<-(-.5*(m*log(1-rho1^2)+(emss-2*rho1*emcp)/(1-rho1^2)))-
(-.5*(m*log(1-rho^2 )+(emss-2*rho*emcp )/(1-rho^2 ))) +
( (-.5*log(1-rho1^2)) - (-.5*log(1-rho^2)) )
if(log(runif(1))<lhr) { rho<-rho1 }
rho
}
Run the code above in your browser using DataLab