psamplr: Single and Two Variable Probability Function

Description Usage Arguments Details Value Examples

View source: R/psamplr.R

Description

This function implements one and two variable rejection sampling to find probabilities.

Usage

1
psamplr(f, q, g = NULL)

Arguments

f

The pdf you wish to use to find the probability of. For 2D probability density functions, the argument must be a vector of the two parameters of the pdf.

q

The value you want the samples to be less than. For 2D, the value you want your function g to be less than.

g

The function of random variables x and y for 2D that you wish to find the probability associated with.

Details

This function is in an implimentation of a distribution function for single and two variable pdfs using the samplr rejection sampler.

For one dimensional variables, this function uses samplr to find P(X < q).

For two dimensional random variables, this function uses samplr to find P(g(X,Y) < q), where X and Y are found using samplr(f, 10000, twod = TRUE).

Value

A number between 0 and 1 associated with the distribution function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
One dimensional

f <- function(x) {
  ifelse(0 < x & x < 1, 2*x, 0)
}
psamplr(f,.5)

f <- function(x) {
  ifelse(0 < x & x < 2, 1/2*x, 0)
}
psamplr(f,1)

f <- function(x) {
  ifelse(0 < x & x < 6.2832, 1/2/pi*(sin(x) + 1), 0)
}
psamplr(f,pi)

Two dimensional

f <- function(z) {
  x <- z[1]
  y <- z[2]
  ifelse(0 <= x & x <= 1 & 0 <= y & y <= 1, x + y, 0)
}
g <- function(z) {
  x <- z[1]
  y <- z[2]
  2*x + y
}
psamplr(f,1,f)
psamplr(f,2,g)

bubj/samplr documentation built on May 28, 2019, 7:14 p.m.