d2_sampler_special: Sample from a 2D Distribution Given FX(x) and F(y|X = x)

Description Usage Arguments Value Author(s) Examples

Description

Sample from a 2D Distribution Given FX(x) and F(y|X = x) This function samples from a 2D distribution given the marginal pdf of X and the conditional pdf of Y given X = x. Its output is in the form of a data frame where the elements are x and y samples from the specified 2D distribution.

This function uses the rejection_sampling function. Depending upon the sample size and complexity of the distribution, this function may run more than 1 minute.

Usage

1
d2_sampler_special(n = 1, fx, fyx)

Arguments

n

is the number of samples to generate.

fx

is the marginal pdf of X.

fyx

is the conditional pdf of Y given X = x (it is in the form function(y,x) expression).

Value

my_samples is a data frame of x and y samples from the desired 2D distribution.

Author(s)

Peter Reiker

Examples

1
2
3
d2_sampler_special(2*10^3, function(x) {exp(-x^2/2)/sqrt(2*pi)}, function(y,x){exp(-y^2/2)/sqrt(2*pi)})
d2_sampler_special(2*10^3, function(x) {ifelse(x > 0, exp(-x), 0)}, function(y,x){ifelse(0 < y & y < x, 1/x, 0)})
d2_sampler_special(2*10^3, function(x) {ifelse(0.01 < x & x < 1.01, 1, 0)}, function(y,x){ifelse(0 < y, x*exp(-y*x), 0)})

reikerp/contdistpeter documentation built on May 26, 2019, 2:32 p.m.