| spavs | R Documentation |
spavs is the main function of the package. It runs a Markov chain or multiple chains corresponding either to different temperatures when parallel tempering is used or to different initializations when tempering is not used. At each iteration, a move is proposed that is chosen with equal probability among those allowed. A move can be a merge or a split move of one of two kinds (type 1 and of type 2). The details of the algorithm are described in the paper by S. Monni and M. G. Tadesse (2009). As far as possible, the input statistical parameters of the spavs function follow the notation in that paper.
This function does not return any R objects. Instead the MCMC output (i.e., the sampled configurations) and other information are written into output files as detailed below.
If needed for analysis, the sampled configurations can then be loaded in R from these output files as lists, employing the
function conf.file.to.list. Estimates of posterior probabilities can be computed with the function pairwise.probs.
spavs(
Y,
X,
h0,
h,
nu,
sigma0.square,
rho,
alpha0 = NULL,
beta0 = NULL,
p.split = 1/2,
tempering = FALSE,
inv.temp = 1,
tchains = 1,
tswaps = 0,
mws = 30000,
parallel.params = list(cores = 1, preschedule = TRUE, affinity.list = NULL),
init.conf = c("random", "predetermined", "data"),
init.conf.params,
thin = 200,
outputfile = "output",
print.monitoring = FALSE
)
Y |
the matrix of outcomes: an n*q matrix, with q the number of reponses and n the number of samples (the transpose of the matrix Y in the paper). |
X |
the matrix of predictors: an n*p matrix, with p the number of predictors (the transpose of the matrix X in the paper). |
h0, h |
hyperparameters that control the variance of the normal priors of the regression coefficients.
|
sigma0.square, nu |
the shape and scale hyperparameters for the inverse-Gamma prior of the component residuals variances sigma_k^2. The prior mode is nu/(sigma0.square+1). |
rho |
a real number 0< rho < 1. It controls the prior probability: P(C)=rho^{m*n}, for an (m, n) configuration C. |
alpha0 |
a length-q numeric vector. If NULL (default) the entries are set to 0. It is the mean of the normal prior of the intercepts of the mean function of (Y_1, …, Y_q). |
beta0 |
a length-p numeric vector. If NULL (default) the entries are set to 0. It is the mean of the normal prior of the vector of the regression coefficients for predictors (X_1, …, X_p). |
p.split |
controls the number of common predictors in the components resulting from a split move of type 2.
P(k)=p.split/(1+\floor(m/2)), for k=0,1, …, \floor(m/2) P(k)=(1-p.split)/(m-\floor(m/2)), for k=\floor(m/2), …, m, and, when m=0, k=0 with probability 1. |
tempering |
TRUE/FALSE specifies whether or not tempering is to be employed. |
inv.temp |
a numeric vector of either length 1 or length equal to |
tchains |
an integer greater than 0 indicating the number of chains.
If |
tswaps |
total number of temperature swaps (moves that exchange configurations at different temperatures),
when |
mws |
number of moves in each chain within attempts at temperature-transfers.
If tempering is not implemented, one can either set tswaps=0, so that |
parallel.params |
a list with three entries, |
init.conf |
one of the strings: "random", predetermined", "data".
If |
init.conf.params |
If |
thin |
an integer indicating the thinning used for the sampler
(namely, the configuration of the chain at T=1 are output every |
outputfile |
a string, the prefix to the names of the 3 files where the sampled configurations are written. |
print.monitoring |
TRUE/FALSE. If TRUE, print on screen the acceptance rates after each temperature swap. |
none. The routine writes the samples and other information in files and does not save R objects.
Use conf.file.to.list to load the saved configurations into R in the form of lists.
There are three types of output files, all with the same prefix specified in the option outputfile. They are:
-"outputfile_tk_conf.txt" will contain the sampled configurations
of the k-th chain. If 'tempering=TRUE', only one file for T=1 is
printed.
Each configuration is in one line.
Components are separated by a semicolon. A comma separates
the indices of the regressors and responses of a component.
E.g., the line: 5 , 3 ; 5 7 , 2 ; , 1 ; represents:
C1= X_5, Y_3; C2=X_5, X_7, Y_2; C3=Y_1.
-"outputfile_logpost_size.txt", a two-column file
with each row having logpost and size of the sampled configuration
saved in the corresponding row of the "outputfile_t_k_conf.txt" file.
-"outputfile_ar.txt" tabulates the acceptance rates for the moves in
all chains and, with tempering, for the swaps between thermal chains.
Each row has the number of attempted and accepted moves of a specific
type, for all different chains in order of increasing temperature
(the first column being thus the T_1=1 chain).
The last row gives proposed and accepted numbers of swaps between
contiguous tempering chains, in order of increasing temperature:
the first two columns refer to the swap between the T_1=1 and T_2
chains, the second two to the swap between the T_2 and T_3 chains...
S. Monni, M. G. Tadesse, A Stochastic Partitioning Method to Associate High-dimensional Responses and Covariates, Bayesian Analysis (2009) 4, pp. 413-436. https://doi.org/10.1214/09-BA416
# four chains at temperatures 1, 0.9, 0.85, 0.81, # with a parallelization using 4 cores spavs(Y=Y, X=X, h0=2, h=2, nu=1, sigma0.square=3, rho=0.3, tchains=4, tempering=TRUE, inv.temp=c(1,0.9, 0.85, 0.81), init.conf="random", init.conf.params=c(3,3,1,4), parallel.params=list(cores=4)) # four chains at the same temperature T=1 (no tempering) # with a parallelization using 4 cores. # this is equivalent to 4 different runs spavs(Y=Y, X=X, h0=2, h=2, nu=1, sigma0.square=3, rho=0.3, tchains=4, tempering=FALSE, init.conf="random", init.conf.params=c(3,3,1,4), parallel.params=list(cores=4)) # one chain spavs(Y=Y, X=X, h0=2.2, h=2, nu=2, sigma0.square=1.3, rho=0.01, p.split=0.8, tempering=FALSE, tchain=1, init.conf="data", outputfile="run1")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.