Description Usage Arguments Details Value Note Author(s) References See Also Examples
These functions implement a Bayesian analysis of complete contingency tables. This is accomplished using an MCMC algorithm where the null moves are performed using a Metropolis-Hastings algorithm and the between models moves are performed using a reversible jump algorithm.
bcct
should be used initially, and bcctu
should be used to do additional
MCMC iterations, if required.
bcctsubset
and bcctsubsetu
operate on a subset of models.
1 2 3 4 5 6 7 8 9 10 11 | bcct(formula, data, n.sample, prior = "SBH", start.formula = NULL,
start.beta = NULL, start.sig = NULL, save = 0, name = NULL, null.move.prob=0.5,
a = 0.001, b = 0.001, progress = FALSE)
bcctu(object, n.sample, save = NULL, name = NULL, progress = FALSE)
bcctsubset(subsetformula, data, n.sample, prior = "SBH", start.formula = NULL,
start.beta = NULL, start.sig = NULL, save = 0, name = NULL, null.move.prob=0.5,
a = 0.001, b = 0.001, progress = FALSE)
bcctsubsetu(object, n.sample, save = NULL, name = NULL, progress = FALSE)
|
formula |
An object of class |
subsetformula |
A list with elements of class |
object |
An object of class |
data |
An object of class |
n.sample |
A numeric scalar giving the number of (additional, in the case of |
prior |
An optional argument giving the prior to be used in the analysis. It can be one of
|
start.formula |
An optional argument giving an object of class |
start.beta |
An optional argument giving the starting values of the log-linear parameters for the MCMC algorithm.
It should be a vector of the same length as the number of log-linear parameters in the starting model
implied by the argument |
start.sig |
An optional argument giving the starting value of sigma^2 (under the Sabanes-Bove & Held prior) for the
MCMC algorithm when the argument of prior is |
save |
An optional argument for saving the MCMC output mid-algorithm. For For |
name |
An optional argument giving a prefix to the file name of the external files saved if the argument |
null.move.prob |
An optional scalar argument giving the probability of performing a null move in the reversible jump algorithm, i.e. proposing a move to the current model. The default value is 0.5. |
a |
The shape hyperparameter of the Sabanes-Bove & Held prior, see Overstall & King (2014). The default value
is 0.001. A value of |
b |
The scale hyperparameter of the Sabanes-Bove & Held prior, see Overstall & King (2014). The default value
is 0.001. A value of |
progress |
Logical argument. If |
For identifiability, the parameters are constrained. The conting-package
uses sum-to-zero constraints.
See Overstall & King (2014), and the references therein, for more details.
The Metropolis-Hastings algorithm employed is the iterated weighted least squares method for generalised linear models (GLMs) proposed by Gamerman (1997). The reversible jump algorithm employed is that orthogonal projections method for GLMs proposed by Forster et al (2012). For details on these methods applied to log-linear models see Overstall & King (2014), and the references therein.
For details on the unit information and Sabanes-Bove & Held priors for generalised linear models see Ntzoufras et al (2003) and Sabanes-Bove & Held (2011), respectively. See Overstall & King (2014), and the references therein, for their application to log-linear models and contingency tables.
The functions will return an object of class "bcct"
which is a list with the following components:
BETA |
An |
MODEL |
A vector of length |
SIG |
A vector of length |
rj_acc |
A binary vector of the same length as the number of reversible jump moves attempted. A 0 indicates that the proposal was rejected, and a 1 that the proposal was accepted. |
mh_acc |
A binary vector of the same length as the number of Metropolis-Hastings moves attempted. A 0 indicates that the proposal was rejected, and a 1 that the proposal was accepted. |
priornum |
A numeric scalar indicating which prior was used: 1 = |
maximal.mod |
An object of class |
IP |
A p by p matrix giving the inverse of the prior scale matrix for the maximal model. |
eta.hat |
A vector of length n (number of cells) giving the posterior mode of the linear predictor under the maximal model. |
save |
The argument |
name |
The argument |
null.move.prob |
The argument |
time |
The total computer time (in seconds) used for the MCMC computations. |
a |
The argument |
b |
The argument |
subset.index |
Model indicators (in hexidecimal format) of the subset of models. |
These functions are wrappers for bcct.fit
.
In Version 1.0 of conting-package
, note that the default value for prior
was "UIP"
. From
Version 1.1 onwards, the default value is "SBH"
.
Antony M. Overstall A.M.Overstall@soton.ac.uk.
Sabanes-Bove, D. & Held, L. (2011) Hyper-g priors for generalized linear models. Bayesian Analysis, 6 (3), 387–410.
Forster, J.J., Gill, R.C. & Overstall, A.M. (2012) Reversible jump methods for generalised linear models and generalised linear mixed models. Statistics and Computing, 22 (1), 107–120.
Gamerman, D. (1997) Sampling from the posterior distribution in generalised linear mixed models. Statistics and Computing, 7 (1), 57–68.
Gelman, A. (2006) Prior distributions for variance parameters in hierarchical models(Comment on Article by Browne and Draper). Bayesian Analysis, 1 (3), 515–534.
Nztoufras, I., Dellaportas, P. & Forster, J.J. (2003) Bayesian variable and link determination for generalised linear models. Journal of Statistical Planning and Inference, 111 (1), 165–180.
Overstall, A.M. & King, R. (2014) conting: An R package for Bayesian analysis of complete and incomplete contingency tables. Journal of Statistical Software, 58 (7), 1–27. http://www.jstatsoft.org/v58/i07/
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | set.seed(1)
## Set seed for reproducibility.
data(AOH)
## Load the AOH data
test1<-bcct(formula=y~(alc+hyp+obe)^3,data=AOH,n.sample=50,prior="UIP")
## Let the maximal model be the saturated model. Starting from the
## posterior mode of the maximal model do 50 iterations under the unit
## information prior.
test1<-bcctu(object=test1,n.sample=50)
## Do another 50 iterations
test1
## Printing out a bcct object produces this simple summary
#Number of cells in table = 24
#
#Maximal model =
#y ~ (alc + hyp + obe)^3
#
#Number of log-linear parameters in maximal model = 24
#
#Number of MCMC iterations = 100
#
#Computer time for MCMC = 00:00:01
#
#Prior distribution for log-linear parameters = UIP
summary(test1)
## Printing out a summary produces a bit more:
#Posterior summary statistics of log-linear parameters:
# post_prob post_mean post_var lower_lim upper_lim
#(Intercept) 1 2.877924 0.002574 2.78778 2.97185
#alc1 1 -0.060274 0.008845 -0.27772 0.06655
#alc2 1 -0.049450 0.006940 -0.20157 0.11786
#alc3 1 0.073111 0.005673 -0.05929 0.20185
#hyp1 1 -0.544988 0.003485 -0.65004 -0.42620
#obe1 1 -0.054672 0.007812 -0.19623 0.12031
#obe2 1 0.007809 0.004127 -0.11024 0.11783
#NB: lower_lim and upper_lim refer to the lower and upper values of the
#95 % highest posterior density intervals, respectively
#
#Posterior model probabilities:
# prob model_formula
#1 0.45 ~alc + hyp + obe
#2 0.30 ~alc + hyp + obe + hyp:obe
#3 0.11 ~alc + hyp + obe + alc:hyp + hyp:obe
#4 0.06 ~alc + hyp + obe + alc:hyp + alc:obe + hyp:obe
#5 0.05 ~alc + hyp + obe + alc:hyp
#
#Total number of models visited = 7
#
#Under the X2 statistic
#
#Summary statistics for T_pred
# Min. 1st Qu. Median Mean 3rd Qu. Max.
# 11.79 20.16 23.98 24.70 28.77 52.40
#
#Summary statistics for T_obs
# Min. 1st Qu. Median Mean 3rd Qu. Max.
# 8.18 24.22 31.51 30.12 35.63 42.49
#
#Bayesian p-value = 0.28
## For more examples see Overstall & King (2014).
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.