Sample a multinomial regression rate

sample_multinom_reg(
  p,
  z,
  k,
  mean,
  precision,
  method = c("slice", "normal", "uniform", "quadratic taylor", "mv ind quadratic taylor",
    "mv truncated exponential"),
  ref = c("first", "last"),
  ...,
  diag = all(precision[upper.tri(precision)] == 0),
  zmax = NULL,
  width = 1,
  nexpand = 10,
  ncontract = 100,
  acceptance = c("MH", "LL only", "regardless")
)

Arguments

p

the previous iteration of the logit-probability, as an array of dimension r x i x j, where r is the number of realizations, i is the number of (correlated) betas (that is, the dimension of precision), and j is the number of classes to split between. It is expected that p[, , ref] == 0. This can also be "flattened" to a matrix of dimension r x (i x j).

z

a matrix (or array) of zeros and ones. The zeros determine so-called "structural zeros": outcomes which are not possible. If two-dimensional, it is assumed not to change over the first dimension (r) of p. This is of dimension i x j or r x i x j.

k

the realized value from the binomial distribution; the same size as p.

mean

the prior mean for p. Must be either a scalar or an array of size r x i x (j-1) (when p is 3-D) or a "flattened" matrix of the same size.

precision

an array of dimension i x i x (j-1) or a "flattened" matrix of the same size. The j-dimension is assumed to be independent.

method

The method to use to propose new values.

  • "normal" proposes normal deviates from the current value.

  • "uniform" proposes uniform deviates.

  • "gamma" (only for Poisson) does moment-matching on the mean and variance to propose a conjugate gamma proposal.

  • "mv gamma" (only for Poisson) does the same, but ignores off-diagonal elements of the precision matrix in the proposal (for speed's sake; this may result in low acceptance rates when elements are highly correlated).

  • "mv beta" (only for binomial, and still somewhat experimental) does moment matching on a mean and variance approximated by the log-normal distribution (instead of logit-normal, for which there is no closed form) to propose a conjugate beta proposal; here again we ignore off-diagonal elements of the precision matrix for the proposal.

  • "quadratic taylor" proposes using a second-order Taylor approximation of the log-density at the current value, which amounts to a normal proposal with mean (usually) not equal to the current value.

  • "mv quadratic taylor" does the same, but uses a multivariate normal approximation.

  • "mv ind quadratic taylor" proposes using a similar Taylor approximation, but approximates the log-density around the mean, instead of the current value. Furthermore, like "mv beta" and "mv gamma", it ignores off-diagonal elements of the precision matrix for the proposal, which again might yield low acceptance rates when elements are highly correlated; in particular, it is not recommended for sample_multinom_reg, whose data are a priori correlated (unless you increase the variance a lot, in which case it works okay). Both of these simplifications yield a significant speed boost.

  • "mv truncated exponential" proposes using a first-order Taylor approximation of the log-density at the current value, which amounts to a truncated exponential proposal.

Note that "mv gamma", "mv beta" and "mv [ind ]quadratic taylor" accept or reject an entire row at a time.

ref

One of "first" or "last" or a numeric value, denoting which "column" (the third dimension) of p is the reference. If "first", then mean and precision map to the second through j-th elements of p. If "last", then mean and precision map to the first through (j-1)-th elements of p. If 2, then mean and precision map to the first and third through j-th elements of p. Etc.

...

Other arguments (not used)

diag

Logical, denoting whether the precision matrix is diagonal, for a small speed boost.

zmax

For advanced use: a matrix, usually computed from the last two dimensions of z.

width

For "normal" proposals, the standard deviation(s) of proposals. For "uniform" proposals, the half-width of the uniform proposal interval. For "slice", the width of each expansion (to the right and left each). For "gamma", "beta", and "mv ind quadratic taylor" a scaling factor to increase the variance of the proposal (it's squared, so that width is on the sd scale).

nexpand

The maximum number of expansions (to the right and left each)

ncontract

The maximum number of contractions. If this is exceeded, the original value is returned

acceptance

What should be the criteria for acceptance? "MH" indicates the usual Metropolis-Hastings update. "LL only" ignores the proposal densities but considers the log-likelihoods. "regardless" accepts no matter what. This is useful for testing, or for when the method is a gamma, beta, or quadratic approximation, which can be hard to accept if the initial starting point is low-density.

Details

The internals are defined in C++.

In the case that n is zero or z is zero, slice sampling is ignored in favor of a (possibly multivarite) normal draw.