Learn R Programming

amen (version 1.0)

raSab_frn_fc: Simulate a and Sab from full conditional distributions under frn likelihood

Description

Simulate a and Sab from full conditional distributions under frn likelihood

Usage

raSab_frn_fc(Z, Y, YL, a, b, Sab, odmax, odobs, SS =
round(sqrt(nrow(Z))))

Arguments

Z
a square matrix, the current value of Z
Y
square matrix of ranked nomination data
YL
list of ranked individuals, from least to most preferred in each row
a
current value of row effects
b
current value of column effects
Sab
current value of Cov(a,b)
odmax
a scalar or vector giving the maximum number of nominations for each individual
odobs
observed outdegree
SS
number of iterations

Value

  • Znew value of Z
  • Sabnew value of Sab
  • anew value of a

Examples

Run this code
## The function is currently defined as
raSab_frn_fc<-
function (Z, Y, YL, a, b, Sab,  odmax, odobs, SS = round(sqrt(nrow(Z))))
{
    E <- Z - a %*% t(rep(1, nrow(Z)))
    lba <- -E[cbind(1:nrow(Z), YL[, 1])]
    lba[is.na(lba)] <- -Inf
    uba <- -apply(E - (Y != 0) * (Inf^(Y != 0)), 1, max, na.rm = TRUE)
    uba[odobs == odmax] <- Inf
    for (ss in 1:SS) {
        ea <- b * Sab[1, 2]/Sab[2, 2]
        sa <- sqrt(Sab[1, 1] - Sab[1, 2]^2/Sab[2, 2])
        a <- ea + sa * qnorm(runif(nrow(Z), pnorm((lba - ea)/sa),
            pnorm((uba - ea)/sa)))
        Sab <- solve(rwish(solve(diag(2) + crossprod(cbind(a,
            b))), 3 + nrow(Z)))
    }
    list(Z = E + a %*% t(rep(1, nrow(Z))), a = a, Sab = Sab)
}

Run the code above in your browser using DataLab