mtrp_exp: Metropolis-Hastings Algorithm Using Exponential Distribution

Description Usage Arguments Value Examples

View source: R/mtrp_exp.R

Description

MCMC method for continuous random vector with exponential distribution as proposal distribution using an independence sampler algorithm.

Usage

1
mtrp_exp(f, n, init, a = 0, rate = 1, burn = 1000)

Arguments

f

Density function from which one wants to sample.

n

The numbers of samples one wants to obtain.

init

The initial value vector, which indicates the dimensions.

a

The left support boundary vector. if a numeric number is provided, it will be broadcast to a vector with the same length as init.

rate

A vector with rate[i] being the rate of proposal for updating 'i'th variable. if a numeric number is provided, it will be broadcast to a vector with the same length as init.

burn

Times of iterations one wants to omit before recording.

Value

A "mcmcn" object 'list("chain" = chain, "reject" = k/iters, "acpt" = acpt)' with chain storing samples by row, reject being the rejection rate, acpt being whether to be accepted each iter.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# the Exp(1) Distribution Left-Truncated at 1--------------------------------
(i.e., with support [1,+Infinity))

# pdf f(x) = exp(1 - x)
f <- function(x) ifelse(x >= 1, exp(-x), 0)

# generating random variates using function `mtrp_exp`
x.exp1 <- mtrp_exp(f, 10000, 1, a = 1, burn = 0)

# exploring the results
summary(x.exp1)
plot(x.exp1, "c")
hist(x.exp1$chain, freq = FALSE, breaks = 50,
     main = "Histogram of Samples",
     xlab = "X", xlim = c(0,4), ylim = c(0,  exp(1)))
curve(exp(1 - x), col = "red", add = TRUE)

hjy78/mcmcn documentation built on Jan. 1, 2020, 1:03 p.m.