rARS: Adaptive Rejection Sampling Algorithm rARS generates a...

Description Usage Arguments Author(s) Examples

Description

Adaptive Rejection Sampling Algorithm rARS generates a sequence of random variables using ARS algorithm.

Usage

1
rARS(n, formula, min = -Inf, max = Inf, sp)

Arguments

n

Desired sample size

formula

Kernal density of target log target density

min, max

Domain including positive and negative infinity

sp

Supporting set.

Author(s)

Zhangdong<dzhang0716@126.com>

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
###Running the following codes my take you a few minutes!

#Standard normal distribution
x<-rARS(500,"exp(-x^2/2)",-Inf,Inf,c(-2,2))

#Truncated normal distribution
rARS(500,"exp(-x^2/2)",-2.1,2.1,c(-2,2))

#Normal distribution with mean=2 and sd=2
rARS(500,"exp(-(x-2)^2/(2*4))",-Inf,Inf,c(-3,3))

#Exponential distribution with rate=3
rARS(500,"exp(-3*x)",0,Inf,c(2,3,100))

#Beta distribution
rARS(500,"x^2*(1-x)^3",0,1,c(0.4,0.6))

#Gamma distribution
rARS(500,"x^(5-1)*exp(-2*x)",0,Inf,c(1,10))

#Student distribution
rARS(500,"(1+x^2/10)^(-(10+1)/2)",-Inf,Inf,c(-10,2))

#F distribution
rARS(500,"x^(10/2-1)/(1+10/5*x)^(15/2)",0,Inf,c(3,10))

#Cauchy distribution
rARS(500,"1/(1+(x-1)^2)",-Inf,Inf,c(-2,2,10))

#Rayleigh distribution with lambda=1
rARS(500,"2*x*exp(-x^2)",0,Inf,c(0.01,10))

teacher7738/AdapSamp documentation built on May 4, 2019, 4:22 p.m.