Description Usage Arguments Value Examples
r2d2marg
adopts the Gibbs sampling algorithm, aiming to obtain a
sequence of posterior samples, which are approximately from the Marginal
R2-D2 prior.
1 |
x |
An n-by-p input matrix, each row of which is an observation vector. |
y |
An n-by-one vector, representing the response variable. |
hyper |
The values of the hyperparameters in the prior, i.e., the values
of
|
mcmc.n |
Number of MCMC samples, by default, 10000. |
eps |
Tolerance of convergence, by default, 1e-7. |
thin |
Thinning parameter of the chain. The default is 1, representing no thinning. |
print |
Boolean variable determining whether to print the progress of the MCMC iterations, i.e., which iteration the function is currently on. The default is TRUE. |
A list containing the following components:
beta: Matrix (mcmc.n * p) of posterior samples for beta.
sigma2: Vector (mcmc.n) of posterior samples for sigma^2.
psi: Matrix (mcmc.n * p) of posterior samples for psi.
w: Vector (mcmc.n) of posterior samples for the total prior probability w.
xi: Vector (mcmc.n) of posterior samples for xi.
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 | rho <- 0.5
# Number of predictors
p <- 25
# Number of observations
n <- 60
# Construct beta
n_nonzero <- 5
beta <- rep(0, p)
set.seed(1)
beta[11:(10 + n_nonzero)] <- stats::rt(n_nonzero, df = 3) * sqrt(0.5/(3 * n_nonzero/2))
# Construct x
sigma <- 1
times <- 1:p
H <- abs(outer(times, times, "-"))
V <- sigma * rho^H
x <- mvtnorm::rmvnorm(n, rep(0, p), V)
x <- scale(x, center = TRUE, scale = FALSE)
# Construct y
y <- x %*% beta + stats::rnorm(n)
# Gibbs sampling
mcmc.n <- 10000
fit.new <- r2d2marg(x = x, y = y, mcmc.n = mcmc.n, print = FALSE)
# Discard the early samples
burnIn <- 5000
beta.new <- fit.new$beta[burnIn:10000, ]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.