sampleFromDensity: Get sample given the density function

View source: R/RVCompare.R

sampleFromDensityR Documentation

Get sample given the density function

Description

Returns an array with samples given the probability density function.

Usage

sampleFromDensity(density, nSamples, xlims, nIntervals = 1e+05)

Arguments

density

the probability density function.

nSamples

the number of samples to generate.

xlims

the domain of definition of the random variable.

nIntervals

(optional, default = 1e4) the number of intervals from which to draw samples. A higher value implies more accuracy but also more computation time.

Value

Returns an array of samples.

Examples

normDens <- normalDensity(0,1)
samples <- sampleFromDensity(normDens, 1e4, c(-4,4))
hist(samples,  breaks=20)

EtorArza/RVCompare documentation built on Jan. 11, 2025, 12:05 a.m.