random_trim | R Documentation |
Generate random numbers from a trimmed distribution.
random_trim(d, n, trim = c(-Inf, Inf), doTrunc = FALSE)
d |
distributions3 object |
n |
Integer, number of samples to draw |
trim |
Numeric vector of size 2, trimming bounds. |
doTrunc |
Logical, do truncation? default FALSE, i.e. rectification is used. |
a numeric vector containing the generated values
# Define Normal distribution
norm <- Normal(mu=0.75,sigma=0.5)
# Generate values from basic / rectified / truncated Gaussian distributions
n=1000
y0=random_trim(norm,n)
yr=random_trim(norm,n,trim=c(0,1))
yt=random_trim(norm,n,trim=c(0,1),doTrunc=TRUE)
# plot results
par(mfrow=c(2,3))
lim=c(-0.75,2.25)
plot(y0,ylim=lim);plot(yr,col='red',ylim=lim);plot(yt,col='blue',ylim=lim)
hist(y0,xlim=lim);hist(yr,col='red',xlim=lim);hist(yt,col='blue',xlim=lim)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.