Learn R Programming

RVCompare (version 0.1.8)

sampleFromDensity: 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)

Value

Returns an array of samples.

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.

Examples

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

Run the code above in your browser using DataLab