Description Usage Arguments Value Examples
MCMC method for continuous random vector with uniform distribution as proposal distribution using an independence sampler algorithm.
1 | mtrp_unif(f, n, init, a, b, 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, b |
The left and right support boundary vector. 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 | # the Exp(1) distribution right-truncated at 1-------------------------------
# i.e., with support [0,1]
# pdf f(x) = exp(1 - x) / (e - 1)
f <- function(x) ifelse(x >= 0 && x <=1, exp(-x), 0)
# generating random variates using function `mtrp_unif`
x.exp2 <- mtrp_unif(f, 10000, 1, a = 0, b = 1, burn = 0)
# exploring the results
summary(x.exp2)
plot(x.exp2, "c")
hist(x.exp2$chain, freq = FALSE, main = "Histogram of Samples", xlab = "X")
curve(exp(1 - x) / (exp(1) - 1), from = 0, to = 1, col = "red", add = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.