rpmf: rpmf

Description Usage Arguments Author(s) See Also Examples

Description

Draw random samples from a probability mass function using the inverse transform sampling.

Usage

1
rpmf(n, pmf, support, ...)

Arguments

n

An integer >= 1.

pmf

A probability mass function which takes elements of an ambient space of pmf's support (i.e. an input that makes pmf return a probability) in its first argument. This pmf has a finite support, and must be able to take an array of elements and return an array of probabilities. Each output of this pmf must fall in [0, 1], and every conceivable output, including 0, must sum up to 1, i.e. if an object that is not an element of support is given, pmf must return 0.

support

A vector which consists of the elements of the support of pmf, i.e. sum(pmf(support, ...)) == 1 && !(0 %in% pmf(support, ...))

...

An additional argument of pmf

Author(s)

Junkyu Park

See Also

csum_N, dpmf, Evaluating a hard-to-evaluate pmf using pgf and DFT

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Example 1: dfruit in dpmf example
# Generate 12 random samples from dfruit
rpmf(12, dfruit, c('apple', 'orange', 'neither'))
# Example 2: dX in csum_N example
# Generate 20 samples of X_i ~ dX
rpmf(20, dX, 0:5)
# Example 3: S = sum of iid X_i's, i = 1, ..., N,
# where N ~ Pois(3) and N independent of all X_i ~ dX (in Example 2)
# Generate 12 samples of S
result_X <- csum_N(dX, support = 0:5, lambda = 3)
M <- length(result_X)
rpmf(12, dpmf, 0:(M - 1), result_X)

joon3216/funpark documentation built on June 18, 2019, 7:32 a.m.