update_s: Update class weight vector

View source: R/RcppExports.R

update_sR Documentation

Update class weight vector

Description

This function updates the class weight vector by drawing from its posterior distribution.

Usage

update_s(delta, m)

Arguments

delta

A numeric for the concentration parameter vector rep(delta,C) of the Dirichlet prior for s. Per default, delta = 1. In case of Dirichlet process-based updates of the latent classes, delta = 0.1 per default.

m

The vector of current class frequencies.

Details

Let m=(m_1,…,m_C) be the frequencies of C classes. Given the class weight (probability) vector s=(s_1,…,s_C), the distribution of m is multinomial and its likelihood is

L(m\mid s) \propto ∏_{i=1}^C s_i^{m_i}.

The conjugate prior p(s) for s is a Dirichlet distribution, which has a density function proportional to

∏_{i=1}^C s_i^{δ_i-1},

where δ = (δ_1,…,δ_C) is the concentration parameter vector. Note that in RprobitB, δ_1=…=δ_C. This restriction is necessary because the class number C can change. The posterior distribution of s is proportional to

p(s) L(m\mid s) \propto ∏_{i=1}^C s_i^{δ_i + m_i - 1},

which in turn is proportional to a Dirichlet distribution with parameters δ+m.

Value

A vector, a draw from the Dirichlet posterior distribution for s.

Examples

### number of classes
C <- 4
### current class sizes
m <- sample.int(C)
### concentration parameter for Dirichlet prior (single-valued)
delta <- 1
### updated class weight vector
update_s(delta = 1, m = m)

RprobitB documentation built on Nov. 10, 2022, 5:12 p.m.