Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rtruncated

Simulates from a truncated probability distribution


Description

Simulates a sample from a truncated distribution where the functions for the cdf and inverse cdf are available.

Usage

rtruncated(n,lo,hi,pf,qf,...)

Arguments

n

size of simulated sample

lo

low truncation point

hi

high truncation point

pf

function containing cdf of untruncated distribution

qf

function containing inverse cdf of untruncated distribution

...

parameters used in the functions pf and qf

Value

vector of simulated draws from distribution

Author(s)

Jim Albert

Examples

# want a sample of 10 from normal(2, 1) distribution truncated below by 3
n=10
lo=3
hi=Inf
rtruncated(n,lo,hi,pnorm,qnorm,mean=2,sd=1)
# want a sample of 20 from beta(2, 5) distribution truncated to (.3, .8)
n=20
lo=0.3
hi=0.8
rtruncated(n,lo,hi,pbeta,qbeta,2,5)

LearnBayes

Functions for Learning Bayesian Inference

v2.15.1
GPL (>= 2)
Authors
Jim Albert
Initial release
2018-03-18

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.