twoDsample: Double Variable Rejection Sampling

Description Usage Arguments Details Value Examples

View source: R/twoDSample.R

Description

This function implements two variables rejection sampling for rvs with bounded support and which have a bounded pdf.

Usage

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

Arguments

f

the pdf that we are sampling from

N

the number of attempted samples

lbx

the lower bound of support x of f

ubx

the upper bound of support x of f

lby

the lower bound of support y of f

uby

the upper bound of support y of f

Details

Here are more details about the algorithm that we are using

Value

A vector containing samples from pdf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
jointPFF <- function(x){
x1 = x[1]
x2 = x[2]
ifelse(0<x1 & x1<1 & 0<x2 & x2<1 , 24*x1*x2, 0)}
w = twoDsample(f = jointPFF, N=10000,0,1,0,1)
ggplot(w, aes(x, y)) +  geom_density_2d()

f <- function(x){
x1 = x[1]
x2 = x[2]
ifelse(x2>0, 1/pi/(1+x1^2) * 0.05*exp(-0.05*x2), 0)}
w=twoDsample(f = f, N=10000)
ggplot(a, aes(x, y)) +  geom_density_2d()

zwang8889/project4800 documentation built on May 29, 2019, 12:20 p.m.