## 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)
Run the code above in your browser using DataLab