tabl.new | R Documentation |
UNU.RAN random variate generator for continuous distributions with given probability density function (PDF). It is based on the TABLe based rejection method (‘TABL’).
[Universal] – Rejection Method.
tabl.new(pdf, lb, ub, mode, islog=FALSE, ...) tabld.new(distr)
pdf |
probability density function. (R function) |
lb |
lower bound of domain;
use |
ub |
upper bound of domain;
use |
mode |
location of the mode. (numeric) |
islog |
whether |
... |
(optional) arguments for |
distr |
distribution object. (S4 object of class |
This function creates an unuran
object based on ‘TABL’
(TABLe based rejection). It can be used to draw samples of a
continuous random variate with given probability density function
using ur
.
The density pdf
must be positive but need not be normalized
(i.e., it can be any multiple of a density function).
The given pdf
must be unimodal.
Alternatively, one can use function tabld.new
where the object
distr
of class "unuran.cont"
must contain all required
information about the distribution.
The setup time of this method depends on the given PDF, whereas its marginal generation times are almost independent of the target distribution.
An object of class "unuran"
.
Josef Leydold and Wolfgang H\"ormann unuran@statmath.wu.ac.at.
W. H\"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg. See Section 5.1 (“Ahrens Method”).
ur
,
tdr.new
,
unuran.cont
,
unuran.new
,
unuran
.
## Create a sample of size 100 for a Gaussian distribution pdf <- function (x) { exp(-0.5*x^2) } gen <- tabl.new(pdf=pdf, lb=-Inf, ub=Inf, mode=0) x <- ur(gen,100) ## Create a sample of size 100 for a ## Gaussian distribution (use logPDF) logpdf <- function (x) { -0.5*x^2 } gen <- tabl.new(pdf=logpdf, islog=TRUE, lb=-Inf, ub=Inf, mode=0) x <- ur(gen,100) ## Draw sample from Gaussian distribution with mean 1 and ## standard deviation 2. Use 'dnorm'. gen <- tabl.new(pdf=dnorm, lb=-Inf, ub=Inf, mode=1, mean=1, sd=2) x <- ur(gen,100) ## Draw a sample from a truncated Gaussian distribution ## on domain [5,Inf) logpdf <- function (x) { -0.5*x^2 } gen <- tabl.new(pdf=logpdf, lb=5, ub=Inf, mode=5, islog=TRUE) x <- ur(gen,100) ## Alternative approach distr <- udnorm() gen <- tabld.new(distr) x <- ur(gen,100)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.