twoDsample: Two variable Rejection Sampling

Description Usage Arguments Details Value Examples

Description

This function "twoDsample(f, N, lbx, ubx, lby, uby)" implements two variabel rejection sampling for rvs with bounded support and which have bounded pdf.

Usage

1
twoDsample(f, N, lbx = -5000, ubx = 5000, lby = -5000, uby = 5000)

Arguments

f

the pdf that we are sampling from

N

the nimber of attempted samples.

lbx

lower bound of x support of f

ubx

upper bound of x support of f

lby

lower bound of y support of f

uby

upper bound of y support of f

Details

Additionaly, the function 'twoDsampleplot()' shows the plot of simulation joint density function.

Value

A vector containing samples from pdf ggplot of simulation joint density function

Examples

1
2
3
4
5
6
f <- function(x){
x1 = x[1]
x2 = x[2]
ifelse(0<x1 & x1<1 & 0<x2 & x2<1 & 0<x1+x2 & x1+x2<1, 24*x1*x2, 0)}
a <- twoDsample(f , N=1000, lbx = 0, ubx = 1, lby = 0, uby = 1)
ggplot(a, aes(x, y)) +  geom_density_2d()

sissidong/4800-project documentation built on May 12, 2019, 8:45 a.m.