powered by
Returns an array with samples given the probability density function.
sampleFromDensity(density, nSamples, xlims, nIntervals = 1e+05)
Returns an array of samples.
the probability density function.
the number of samples to generate.
the domain of definition of the random variable.
(optional, default = 1e4) the number of intervals from which to draw samples. A higher value implies more accuracy but also more computation time.
normDens <- normalDensity(0,1) samples <- sampleFromDensity(normDens, 1e4, c(-4,4)) hist(samples, breaks=20)
Run the code above in your browser using DataLab