R/update_Z_bin_fc.R

update_Z_bin_fc <- function(Y, X, beta, sigma.squared, a, b, sigma.ab) {
  # In binary (probit) case, the full conditional of z is a truncated normal
  n <- dim(Y)[1]
  Z <- matrix(rep(NA,n*n), ncol=n)
  Zmean <- c(amen::Xbeta(X, beta) + (a %*% t(rep(1, n))) + (rep(1, n) %*% t(b)))
  highbound <- replace(x=rep(0, n^2), (c(Y) == 1), Inf)
  lowbound <- replace(rep(0, n^2), (c(Y) == 0), -Inf)
  Zcol <- truncnorm::rtruncnorm(n=n^2, a=lowbound, b=highbound, mean=Zmean, sd=sqrt(sigma.squared))
  Z <- matrix(Zcol, ncol=n)
  diag(Z) <- NA
  return(Z)
}
ianmtaylor1/amen2 documentation built on June 1, 2019, 4:55 a.m.