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 objectsNNumber of MCMC samples
thetaNested list of length N of the sampled values of theta for each chain
thetaCombinedList of dataframes containing sampled values, one for each chain
rNULL for Metropolis-Hastings
theta.allNested list of all parameter values of theta sampled prior to accept/reject step for each
r.allNULL for Metropolis-Hastings
acceptNumber of accepted proposals. The ratio accept / N is the acceptance rate
accept_vVector of length N indicating which samples were accepted
MNULL for Metropolis-Hastings
algorithmMH for Metropolis-Hastings
varnamesOptional vector of parameter names
chainsNumber of MCMC chains
logPOSTERIOR functionslinear_posteriorLinear regression: log posterior
logistic_posteriorLogistic regression: log posterior
poisson_posteriorPoisson (count) regression: log posterior
lmm_posteriorLinear mixed effects model: log posterior
glmm_bin_posteriorLogistic mixed effects model: log posterior
glmm_poisson_posteriorPoisson 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.