sample_logp: Sample with unequal and unnormalized log-probabilities

Description Usage Arguments Value Examples

View source: R/sample_logp.R

Description

Samples with replacement from given log-probability vector

Usage

1
sample_logp(x, size, lp_vec)

Arguments

x

a vector of possible outcomes

size

number of samples to take, where sampling is with replacement

lp_vec

a numeric vector that contains the log-probabilities with which to sample. These probabilities might or not be normalized to sum to one.

Value

a sample of size size from x

Examples

1
2
3
4
5
6
7
K = 4

# unnormalized probability vector (on log-scale)
lq_vec = log(runif(K))

# sample first K letters according to lqvec
x = sample_logp(letters[1:K], 1000, lq_vec)

baruuum/btoolbox documentation built on Aug. 17, 2020, 1:29 a.m.