DAbayesSuite: Parallel inference in Bayesian hierarchical model for...

Description Usage Arguments Value Author(s) Examples

View source: R/DAbayesSuite.R

Description

This function wraps all the necessary functions in DAbayes package to run the MCMC Suite. By default, this will execute the adaptive MCM algorithm in single core (sequentially), and it can be executed in parallel by changing the number of cores to the number of cores available.

Usage

1
2
3
DAbayesSuite(ensemble, model_runs, control_runs, r_max = NULL,
  theta_intVal = NULL, prior = NULL, AD_proposal = NULL, niter = 20000,
  start_adapting = 50, numCore = 1)

Arguments

ensemble

an n by N matrix of ensembles of measured variable, say temperature increase

model_runs

a list of elements, each of which is model-output of the measured variable (temperature increase) under a specific forcing scenario

control_runs

an n by L0 matrix, where n is the number of grid cells, and L0 is the number of control runs

r_max

an integer representing the maximum number of empirical orthogonal functions

theta_intVal

a list of 3 elements containing initial values for parameters in the MCMC algorithm

prior

a list of 6 elements in prior distributions for corresponding parameters

AD_proposal

a list of 6 elements containing quantities to adjust mean and covariance in the proposal distribution

niter

an integer containing the total number of MCMC interations

start_adapting

an integer specifiying when to adapt proposal in the MCMC algorithm

numCore

an integer specifying how many cores are used in parallel computing

Value

a list of r elements, where r is the number of EOFs specified, and each element is again a list of 6 elements containing posterior quantities of parameters, log-likelihood, chisq statistics, and prior:

beta: a matrix holds the posterior samples for the parameter beta with each row corresponding to each beta

logsigma: a vector holds the posterior samples for the parameter log of sigma

lambda: a vector holds the posterior samples for the parameter lambda

loglik: a vector holds the log-likelihood evaluated with updated parameters

chisq: a vector holds chisquare statistics for residual consistency test

prior: a vector holds the prior density evaluated with updated parameters

Author(s)

Pulong Ma <mpulong@gmail.com>

Examples

 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
28
## Not run:  
## Run Gibbs sampling with Metropolis-Hastings algorithm in the 
# Bayesian statistical model
data(ensemble_temperature)
data(GCM_runs)
data(GCM_control_run)

Res <- DAbayesSuite(ensemble=ensemble_temperature, model_runs=GCM_runs, 
control_runs=GCM_control_run, r_max=2, theta_intVal=NULL, prior=NULL,
AD_proposal=NULL, niter=20000, start_adapting=100, numCore=1)

## diagnostic plots for posterior samples, and more sophisticated
# diagnostic plots can be obtained with coda package
# take the first element in Res for example
# plot only first 2 beta's
plot(Res[[1]]$beta[1, ], xlab="Iteration", ylab="beta_1",  type="l")
plot(Res[[1]]$beta[2, ], xlab="Iteration", ylab="beta_2", type="l")
plot(Res[[1]]$logsigma, xlab="Iteration", ylab="logsigma", type="l")
# plot only first 3 lambda's
plot(Res[[1]]$lambda[1, ], xlab="Iteration", ylab="lambda1", type="l")
plot(Res[[1]]$lambda[2, ], xlab="Iteration", ylab="lambda2", type="l")
plot(Res[[1]]$lambda[3, ], xlab="Iteration", ylab="lambda3", type="l")

## save plots 
burnin <- 5000
plotMCMC(Res, N, n, dir=getwd(), burnin)

## End(Not run)

mapn/DAbayes documentation built on May 21, 2019, 11:26 a.m.