Description Usage Arguments Value Examples
MCMC method for continuous random vector with exponential distribution as proposal distribution using an independence sampler algorithm.
1 | mtrp_exp(f, n, init, a = 0, rate = 1, burn = 1000)
|
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. |
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.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.