Learn R Programming

amen (version 1.0)

rrho_mh_rep: Metropolis update for dyadic correlation with independent replicate data

Description

Metropolis update for dyadic correlation with independent replicate data.

Usage

rrho_mh_rep(E.T, rho, s2 = 1)

Arguments

E.T
Array of square residual relational matrix series. The third dimension of the array is for different replicates. Each slice of the array according to the third dimension is a square residual relational matrix.
rho
current value of rho
s2
current value of s2

Value

  • a new value of rho

Examples

Run this code
## 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