LHSpmf: Sample from probability mass function

Description Usage Arguments Value Examples

View source: R/RcppExports.R

Description

Sample from a probability mass function (PMF) via Latin hypercube sampling.

Usage

1
LHSpmf(pmf, sampleSize, seed)

Arguments

pmf

A 2-column data frame as a PMF. The 1st column is sorted and contains value points. The 2nd column contains probabilities. Probabilities should sum up to 1.

sampleSize

Sample size.

seed

An integer vector of size 1 or 4. Both seed a pcg64 RNG while the latter gives the complete state of the RNG.

Value

Random samples from pmf as a numeric vector of size sampleSize.

Examples

1
2
3
4
5
6
# Make a random PMF.
val = seq(0, 15, len = 100)
pmf = data.frame(val = val, P = dgamma(val, shape = 2, scale = 2))
pmf$P = pmf$P / sum(pmf$P)
pmfSample = SimJoint::LHSpmf(pmf, 1000, 123)
hist(pmfSample, breaks = 200)

SimJoint documentation built on Dec. 11, 2021, 9:29 a.m.

Related to LHSpmf in SimJoint...