This function creates LaTeX or HTML regression tables for MCMC Output using the texreg function from the texreg R package.

mcmcReg(mod, pars = NULL, pointest = "mean", ci = 0.95,
  hpdi = FALSE, coefnames = NULL, gof = numeric(0),
  gofnames = character(0), format = "latex", file, regex = FALSE,
  ...)

Arguments

mod

Bayesian model object generated by R2jags, rjags, R2WinBUGS, R2OpenBUGS, MCMCpack, rstan, rstanarm, and brms, or a list of model objects of the same class.

pars

a scalar or vector of the parameters you wish to include in the table. By default, mcmcReg includes all parameters saved in a model object. If a model has lots of samples and lots of saved parameters, not explicitly specifying a limited number of parameters to include via pars may take a long time. pars can either be a vector with the specific parameters to be included in the table e.g. pars = c("beta[1]", "beta[2]", "beta[3]"), or they can be partial names that will be matched using regular expressions e.g. pars = "beta" if regex = TRUE. Both of these will include beta[1], beta[2], and beta[3] in the table. When combining models with different parameters in one table, this argument also accepts a list the length of the number of models.

pointest

a character indicating whether to use the mean or median for point estimates in the table.

ci

a scalar indicating the confidence level of the uncertainty intervals.

hpdi

a logical indicating whether to use highest posterior density intervals or equal tailed credible intervals to capture uncertainty.

coefnames

an optional vector or list of vectors containing parameter names for each model. If there are multiple models, the list must have the same number of elements as there are models, and the vector of names in each list element must match the number of parameters. If not supplied, the function will use the parameter names in the model object(s). Note that this replaces the standard custom.coef.names argument in texreg because there is no extract method for MCMC model objects, and many MCMC model objects do not have unique parameter names.

gof

a named list of goodness of fit statistics, or a list of such lists.

gofnames

an optional vector or list of vectors containing goodness of fit statistic names for each model. Like coefnames in this function (which replaces the custom.coef.names argument in texreg), gofnames replaces the standard custom.gof.names argument in texreg. If there are multiple models, the list must have the same number of elements as there are models, and the vector of names in each list element must match the number of goodness of fit statistics.

format

a character indicating latex or html output.

file

optional file name to write table to file instead of printing to console.

regex

use regular expression matching with pars?

...

optional arguments to texreg.

Value

A formatted regression table in LaTeX or HTML format.

Details

This function creates LaTeX or HTML regression tables for MCMC Output using the texreg function from the texreg R package

If using custom.coef.map with more than one model, you should rename the parameters in the model objects to ensure that different parameters with the same subscript are not conflated by texreg e.g. beta[1] could represent age in one model and income in another, and texreg would combine the two if you do not rename beta[1] to more informative names in the model objects.

If mod is a brmsfit object or list of brmsfit objects, note that the default brms names for coefficients are b_Intercept and b, so both of these should be included in par if you wish to include the intercept in the table.

Examples

.old_wd <- setwd(tempdir()) # \donttest{ ## simulating data set.seed(123456) b0 <- 0.2 # true value for the intercept b1 <- 0.5 # true value for first beta b2 <- 0.7 # true value for second beta n <- 500 # sample size X1 <- runif(n, -1, 1) X2 <- runif(n, -1, 1) Z <- b0 + b1 * X1 + b2 * X2 pr <- 1 / (1 + exp(-Z)) # inv logit function Y <- rbinom(n, 1, pr) data <- data.frame(cbind(X1, X2, Y)) ## formatting the data for jags datjags <- as.list(data) datjags$N <- length(datjags$Y) ## creating jags model model <- function() { for(i in 1:N){ Y[i] ~ dbern(p[i]) ## Bernoulli distribution of y_i logit(p[i]) <- mu[i] ## Logit link function mu[i] <- b[1] + b[2] * X1[i] + b[3] * X2[i] } for(j in 1:3){ b[j] ~ dnorm(0, 0.001) ## Use a coefficient vector for simplicity } } params <- c("b") inits1 <- list("b" = rep(0, 3)) inits2 <- list("b" = rep(0, 3)) inits <- list(inits1, inits2) ## fitting the model with R2jags set.seed(123) fit <- R2jags::jags(data = datjags, inits = inits, parameters.to.save = params, n.chains = 2, n.iter = 2000, n.burnin = 1000, model.file = model)
#> Compiling model graph #> Resolving undeclared variables #> Allocating nodes #> Graph information: #> Observed stochastic nodes: 500 #> Unobserved stochastic nodes: 3 #> Total graph size: 3506 #> #> Initializing model #>
## generating regression table with all parameters mcmcReg(fit)
#> #> \begin{table} #> \begin{center} #> \begin{tabular}{l c} #> \hline #> & Model 1 \\ #> \hline #> b[1] & $0.11$ \\ #> & $ [ -0.07; 0.29]$ \\ #> b[2] & $0.52^{*}$ \\ #> & $ [ 0.20; 0.84]$ \\ #> b[3] & $0.63^{*}$ \\ #> & $ [ 0.33; 0.95]$ \\ #> deviance & $670.28^{*}$ \\ #> & $ [667.49; 676.68]$ \\ #> \hline #> \multicolumn{2}{l}{\scriptsize{$^*$ 0 outside 95\% credible interval.}} #> \end{tabular} #> \caption{Statistical models} #> \label{table:coefficients} #> \end{center} #> \end{table}
## generating regression table with only betas and custom coefficent names mcmcReg(fit, pars = c('b'), coefnames = c('Variable 1', 'Variable 2', 'Variable 3'))
#> Error in x[, y]: subscript out of bounds
## generating regression tables with all betas and custom names mcmcReg(fit, coefnames = c('Variable 1', 'Variable 2', 'Variable 3', 'deviance'))
#> #> \begin{table} #> \begin{center} #> \begin{tabular}{l c} #> \hline #> & Model 1 \\ #> \hline #> Variable 1 & $0.11$ \\ #> & $ [ -0.07; 0.29]$ \\ #> Variable 2 & $0.52^{*}$ \\ #> & $ [ 0.20; 0.84]$ \\ #> Variable 3 & $0.63^{*}$ \\ #> & $ [ 0.33; 0.95]$ \\ #> deviance & $670.28^{*}$ \\ #> & $ [667.49; 676.68]$ \\ #> \hline #> \multicolumn{2}{l}{\scriptsize{$^*$ 0 outside 95\% credible interval.}} #> \end{tabular} #> \caption{Statistical models} #> \label{table:coefficients} #> \end{center} #> \end{table}
# } setwd(.old_wd)