Learn R Programming

amen (version 1.0)

rrho_mh: Metropolis update for dyadic correlation

Description

Metropolis update for dyadic correlation

Usage

rrho_mh(E, rho, s2 = 1)

Arguments

E
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, rho, s2 = 1)
{
    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 <- (-0.5 * (m * log(1 - rho1^2) + (emss - 2 * rho1 *
        emcp)/(1 - rho1^2))) - (-0.5 * (m * log(1 - rho^2) +
        (emss - 2 * rho * emcp)/(1 - rho^2))) + ((-0.5 * log(1 -
        rho1^2)) - (-0.5 * log(1 - rho^2)))
    if (log(runif(1)) < lhr) {
        rho <- rho1
    }
    rho
  }

Run the code above in your browser using DataLab