R/sample_e.R

Defines functions sample_e

sample_e <-
function(e, trunc, iR) {
  e2 <- e
  n <- dim(e)[1]
  nsp <- dim(iR)[1]
  coy2 <- 1 / iR[col(iR) == row(iR)]
  A <- iR
  A[col(A) == row(A)] <- 0
  for (i in 1:nsp) {
    mn <- -coy2[i] * (e2 %*% A[i, ])
    std <- sqrt(coy2[i])
    n <- length(mn)
    e2[, i] <- rtnorm(n, mn, rep(std, n), trunc[, i, 1], trunc[, i, 2])
  }
  e2
}

Try the BayesComm package in your browser

Any scripts or data that you put into this service are public.

BayesComm documentation built on May 2, 2019, 1:43 p.m.