Description Usage Arguments Value Elements for hmclearn objects Available logPOSTERIOR functions Author(s) Examples
View source: R/mcmc_functions.R
This function runs the MH algorithm on a generic model provided
the logPOSTERIOR
function.
All parameters specified within the list param
are passed to these the posterior function.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
N |
Number of MCMC samples |
theta.init |
Vector of initial values for the parameters |
qPROP |
Function to generate proposal |
qFUN |
Probability for proposal function. First argument is where to evaluate, and second argument is the conditional parameter |
logPOSTERIOR |
Function to calculate and return the log posterior given a vector of values of |
nu |
Single value or vector parameter passed to |
varnames |
Optional vector of theta parameter names |
param |
List of additional parameters for |
chains |
Number of MCMC chains to run |
parallel |
Logical to set whether multiple MCMC chains should be run in parallel |
... |
Additional parameters for |
Object of class hmclearn
hmclearn
objectsN
Number of MCMC samples
theta
Nested list of length N
of the sampled values of theta
for each chain
thetaCombined
List of dataframes containing sampled values, one for each chain
r
NULL for Metropolis-Hastings
theta.all
Nested list of all parameter values of theta
sampled prior to accept/reject step for each
r.all
NULL for Metropolis-Hastings
accept
Number of accepted proposals. The ratio accept
/ N
is the acceptance rate
accept_v
Vector of length N
indicating which samples were accepted
M
NULL for Metropolis-Hastings
algorithm
MH
for Metropolis-Hastings
varnames
Optional vector of parameter names
chains
Number of MCMC chains
logPOSTERIOR
functionslinear_posterior
Linear regression: log posterior
logistic_posterior
Logistic regression: log posterior
poisson_posterior
Poisson (count) regression: log posterior
lmm_posterior
Linear mixed effects model: log posterior
glmm_bin_posterior
Logistic mixed effects model: log posterior
glmm_poisson_posterior
Poisson mixed effects model: log posterior
Samuel Thomas samthoma@iu.edu, Wanzhu Tu wtu@iu.edu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # Linear regression example
set.seed(521)
X <- cbind(1, matrix(rnorm(300), ncol=3))
betavals <- c(0.5, -1, 2, -3)
y <- X%*%betavals + rnorm(100, sd=.2)
f1_mh <- mh(N = 3e3,
theta.init = c(rep(0, 4), 1),
nu <- c(rep(0.001, 4), 0.1),
qPROP = qprop,
qFUN = qfun,
logPOSTERIOR = linear_posterior,
varnames = c(paste0("beta", 0:3), "log_sigma_sq"),
param=list(y=y, X=X), parallel=FALSE, chains=1)
summary(f1_mh, burnin=1000)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.