Learn R Programming

BayesLogit (version 0.6.1)

draw.indicators: Draw Indicators

Description

Draw indicator variables from a normal mixture.

Usage

draw.indicators(res, nmix)
draw.indicators.C(res, nmix)
draw.indicators.R(res, nmix)

Arguments

res

A one-dimensional array of residuals.

nmix

A list representing the mixture of normals with components m, v, p, representing the arrays of means, variances, weights of the normal mixture.

Value

Returns a one-dimensional array of mixture component identifiers.

Details

Suppose \(e_i \sim N(m_{\gamma_i}, v_{\gamma_i})\). Then, given \(e_i\), draw \(\gamma_i\) from \(P(\gamma_i = j | e_i)\) for each \(i\).

See Also

compute.mixture

Examples

Run this code
# NOT RUN {
## Approximate - log[Ga] using mixture of normals.
sp = 9
nm = compute.mixture(sp, "log.gamma")
nc = length(nm$m)

r  = sample.int(nc, 10, replace=TRUE, prob=nm$p)
e  = rnorm(10, nm$m[r], sqrt(nm$v[r]))

r.post = draw.indicators(e, nm)

## Approximate type III logistic using mixture of normals.
sp = 9
nm = compute.mixture(sp, "logistic.iii")
nc = length(nm$m)

r  = sample.int(nc, 10, replace=TRUE, prob=nm$p)
e  = rnorm(10, nm$m[r], sqrt(nm$v[r]))

r.post = draw.indicators(e, nm)

# }

Run the code above in your browser using DataLab