Description Usage Arguments Value Elements in mh list Examples
View source: R/mcmc_functions.R
This is the basic computing function for MH and should not be called directly except by experienced users.
| 1 2 3 4 5 6 7 8 9 10 11 | 
| 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  | 
| ... | Additional parameters for  | 
List for mh
mh listNNumber 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
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # Logistic regression example
X <- cbind(1, seq(-100, 100, by=0.25))
betavals <- c(-0.9, 0.2)
lodds <- X %*% betavals
prob1 <- as.numeric(1 / (1 + exp(-lodds)))
set.seed(9874)
y <- sapply(prob1, function(xx) {
  sample(c(0, 1), 1, prob=c(1-xx, xx))
})
f1 <- mh.fit(N = 2000,
         theta.init = rep(0, 2),
         nu = c(0.03, 0.001),
         qPROP = qprop,
         qFUN = qfun,
         logPOSTERIOR = logistic_posterior,
         varnames = paste0("beta", 0:1),
         y=y, X=X)
f1$accept / f1$N
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.