MCMCpack/0000755000176200001440000000000013621173116011631 5ustar liggesusersMCMCpack/NAMESPACE0000644000176200001440000000426313621162722013056 0ustar liggesusers# Generated by roxygen2: do not edit by hand S3method(plot,qrssvs) S3method(print,BayesFactor) S3method(print,qrssvs) S3method(print,summary.qrssvs) S3method(summary,BayesFactor) S3method(summary,qrssvs) export(BayesFactor) export(HDPHMMnegbin) export(HDPHMMpoisson) export(HDPHSMMnegbin) export(HMMpanelFE) export(HMMpanelRE) export(MCMCSVDreg) export(MCMCbinaryChange) export(MCMCdynamicEI) export(MCMCdynamicIRT1d) export(MCMCfactanal) export(MCMChierEI) export(MCMChlogit) export(MCMChpoisson) export(MCMChregress) export(MCMCirt1d) export(MCMCirtHier1d) export(MCMCirtKd) export(MCMCirtKdRob) export(MCMClogit) export(MCMCmetrop1R) export(MCMCmixfactanal) export(MCMCmnl) export(MCMCnegbin) export(MCMCnegbinChange) export(MCMCoprobit) export(MCMCoprobitChange) export(MCMCordfactanal) export(MCMCpoisson) export(MCMCpoissonChange) export(MCMCprobit) export(MCMCprobitChange) export(MCMCquantreg) export(MCMCregress) export(MCMCregressChange) export(MCMCresidualBreakAnalysis) export(MCMCtobit) export(MCbinomialbeta) export(MCmultinomdirichlet) export(MCnormalnormal) export(MCpoissongamma) export(PostProbMod) export(SSVSquantreg) export(choicevar) export(ddirichlet) export(dinvgamma) export(diwish) export(dnoncenhypergeom) export(dtomogplot) export(dwish) export(is.BayesFactor) export(make.breaklist) export(mptable) export(plotChangepoint) export(plotHDPChangepoint) export(plotState) export(procrustes) export(rdirichlet) export(read.Scythe) export(rinvgamma) export(riwish) export(rnoncenhypergeom) export(rwish) export(testpanelGroupBreak) export(testpanelSubjectBreak) export(tomogplot) export(topmodels) export(vech) export(write.Scythe) export(xpnd) import(MASS) import(coda) import(grDevices) import(lattice) import(mcmc) import(methods) import(quantreg) import(stats) import(utils) importFrom(graphics,abline) importFrom(graphics,axTicks) importFrom(graphics,axis) importFrom(graphics,box) importFrom(graphics,layout) importFrom(graphics,lcm) importFrom(graphics,legend) importFrom(graphics,lines) importFrom(graphics,par) importFrom(graphics,plot) importFrom(graphics,plot.new) importFrom(graphics,plot.window) importFrom(graphics,points) importFrom(graphics,rect) useDynLib(MCMCpack, .registration=TRUE) MCMCpack/README0000644000176200001440000000317013564573453012530 0ustar liggesusers///////////////////// // MCMCpack README // ///////////////////// // Authors Andrew D. Martin Kevin M. Quinn Jong Hee Park // Compilation This package (along with Scythe) uses C++ and the Standard Template Library (STL). We suggest using of the GCC compiler 4.0 or greater. The current package has been tested using GCC 4.0 on Linux and MacOS X. Many thanks to Dan Pemstein for helping with all sorts of C++ issues, and to Kurt Hornik and Fritz Leisch for their help with debugging as well as their service to the R community. We are also very grateful to Brian Ripley who provided C++ patches to fix a number of clang and Solaris issues. // Acknowledgments We gratefully acknowledge support from: * National Science Foundation, Program in Methodology, Measurement, and Statistics, Grants SES-0350646 and SES-0350613 * Washington University, Department of Political Science, the Weidenbaum Center on the Economy, Government, and Public Policy (http://wc.wustl.edu), and the Center for Empirical Research in the Law (http://cerl.wustl.edu) * Harvard University, Department of Government and the Institute for Quantitative Social Sciences (http://iq.harvard.edu) Neither the National Science Foundation, Washington University, or Harvard University bear any responsibility for the content of this package. Please contact Jong Hee Park if you have any problems or questions. -- Jong Hee Park, Ph.D. Associate Professor in Dept. Political Science and International Relations Seoul National University Email: jongheepark@snu.ac.kr WWW: http://jhp.snu.ac.kr MCMCpack/data/0000755000176200001440000000000013564573453012560 5ustar liggesusersMCMCpack/data/Rehnquist.rda0000644000176200001440000000324013564573453015231 0ustar liggesusers\ϋ\E~&AYЃ""dApр<݁ ݣ'03gʪ~/;~|U]=3wx|iI3v7_&ˍ9y{x|5_ok]ÝծfGјh/חKQ}?JҼk6yz):}4Q;V=4nsv~*uMW?+άuWXxe:Ǯlh|qI/>hڏu_cׯ~>Qy o!v?GTOꍝ/G_[i8Q?V+C^<}{y W)Yu~; DIzO,\V} Uƶ8dՏ/mKk~QBY8q`_>f@} %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)kRĥKY&.eM\ʚ5q)kRĕ+YW&dM\ɚ5q%kJĕ+YW&dM\ɚ5q%kJĕ+YW&dM\ɚ5q%kJĕ+YW&dM\ɚ5q%kJĕ+YW&dM\ɚ5q%kJĕ+YW&dM\ɚ5q%kJĕ+YW&dM\ɚ5q%kJĕ+YW&dM\ɚ5q%kJĕ+YW&dM\ɚ5q%kJզ&~3!_7 %6On׷Ww/>}f/7gg'Wޗwo/nӓ//ή/S7 庝v[Exve4t}ŋu|vs<|usr~&99{]/Ov.ϮY߼{rGu:9x%:__y/nN^oN.g'GwNړ:e띣/No]\xUE+ӛ&7]\/۬%gnߥ>ys`<=9=Z_[뛛Tݎ}|zj}f.߾MNnn_g׻>>=;~S'ֻplXB=='o.ޞ*e˓6 iƗoon.ڭW'gɋ7뫋WoNZuoa} 67'ys._|so.v:~ u.m^T_{/믲'Bn?W;ܷw7oS6;߻>E˛۷K|-7G+Qcts`wǩ=owy˗";ק)m^v~q[KoNvN\^\"dS_]ׇA:)7{= 0 & z < 1] <- 1; y[z >= 1 & z < 1.5] <- 2; y[z >= 1.5] <- 3; out1 <- MCMCoprobit(y ~ x1 + x2, tune=0.3) out2 <- MCMCoprobit(y ~ x1 + x2, tune=0.3, tdf=3, verbose=1000, mcmc.method="AC") summary(out1) summary(out2) plot(out1) plot(out2) } } \references{ Albert, J. H. and S. Chib. 1993. ``Bayesian Analysis of Binary and Polychotomous Response Data.'' \emph{J. Amer. Statist. Assoc.} 88, 669-679 M. K. Cowles. 1996. ``Accelerating Monte Carlo Markov Chain Convergence for Cumulative-link Generalized Linear Models." \emph{Statistics and Computing.} 6: 101-110. Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Valen E. Johnson and James H. Albert. 1999. \emph{Ordinal Data Modeling}. Springer: New York. Albert, James and Siddhartha Chib. 2001. ``Sequential Ordinal Modeling with Applications to Survival Data." \emph{Biometrics.} 57: 829-836. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. } \seealso{ \code{\link[coda]{plot.mcmc}},\code{\link[coda]{summary.mcmc}} } \keyword{models} MCMCpack/man/read.Scythe.Rd0000644000176200001440000000153213564573453015063 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/scythe.R \name{read.Scythe} \alias{read.Scythe} \title{Read a Matrix from a File written by Scythe} \usage{ read.Scythe(infile = NA) } \arguments{ \item{infile}{The file to be read. This can include path information.} } \value{ A matrix containing the data stored in the read file. } \description{ This function reads a matrix from an ASCII file in the form produced by the Scythe Statistical Library. Scythe output files contain the number of rows and columns in the first row, followed by the data. } \examples{ \dontrun{ mymatrix <- read.Scythe("myfile.txt") } } \references{ Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. } \seealso{ \code{\link{write.Scythe}} } \keyword{file} MCMCpack/man/MCMCdynamicEI.Rd0000644000176200001440000001721513564573453015221 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCdynamicEI.R \name{MCMCdynamicEI} \alias{MCMCdynamicEI} \title{Markov Chain Monte Carlo for Quinn's Dynamic Ecological Inference Model} \usage{ MCMCdynamicEI(r0, r1, c0, c1, burnin = 5000, mcmc = 50000, thin = 1, verbose = 0, seed = NA, W = 0, a0 = 0.825, b0 = 0.0105, a1 = 0.825, b1 = 0.0105, ...) } \arguments{ \item{r0}{\eqn{(ntables \times 1)} vector of row sums from row 0.} \item{r1}{\eqn{(ntables \times 1)} vector of row sums from row 1.} \item{c0}{\eqn{(ntables \times 1)} vector of column sums from column 0.} \item{c1}{\eqn{(ntables \times 1)} vector of column sums from column 1.} \item{burnin}{The number of burn-in scans for the sampler.} \item{mcmc}{The number of mcmc scans to be saved.} \item{thin}{The thinning interval used in the simulation. The number of mcmc iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 then every \code{verbose}th iteration will be printed to the screen.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{W}{Weight (\emph{not precision}) matrix structuring the temporal dependence among elements of \eqn{\theta_{0}} and \eqn{\theta_{1}}. The default value of 0 will construct a weight matrix that corresponds to random walk priors for \eqn{\theta_{0}} and \eqn{\theta_{1}}. The default assumes that the tables are equally spaced throughout time and that the elements of \eqn{r0}, \eqn{r1}, \eqn{c0}, and \eqn{c1} are temporally ordered.} \item{a0}{\code{a0/2} is the shape parameter for the inverse-gamma prior on the \eqn{\sigma^2_0} parameter.} \item{b0}{\code{b0/2} is the scale parameter for the inverse-gamma prior on the \eqn{\sigma^2_0} parameter.} \item{a1}{\code{a1/2} is the shape parameter for the inverse-gamma prior on the \eqn{\sigma^2_1} parameter.} \item{b1}{\code{b1/2} is the scale parameter for the inverse-gamma prior on the \eqn{\sigma^2_1} parameter.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the sample from the posterior distribution. This object can be summarized by functions provided by the coda package. } \description{ MCMCdynamicEI is used to fit Quinn's dynamic ecological inference model for partially observed 2 x 2 contingency tables. } \details{ Consider the following partially observed 2 by 2 contingency table for unit \eqn{t} where \eqn{t=1,\ldots,ntables}: \tabular{llll}{ \tab | \eqn{Y=0} \tab | \eqn{Y=1} \tab | \cr --------- \tab ------------ \tab ------------ \tab ------------ \cr \eqn{X=0} \tab | \eqn{Y_{0t}} \tab | \tab | \eqn{r_{0t}} \cr --------- \tab ------------ \tab ------------ \tab ------------ \cr \eqn{X=1} \tab | \eqn{Y_{1t}} \tab | \tab | \eqn{r_{1t}} \cr --------- \tab ------------ \tab ------------ \tab ------------ \cr \tab | \eqn{c_{0t}} \tab | \eqn{c_{1t}} \tab | \eqn{N_t} } Where \eqn{r_{0t}}, \eqn{r_{1t}}, \eqn{c_{0t}}, \eqn{c_{1t}}, and \eqn{N_t} are non-negative integers that are observed. The interior cell entries are not observed. It is assumed that \eqn{Y_{0t}|r_{0t} \sim \mathcal{B}inomial(r_{0t}, p_{0t})} and \eqn{Y_{1t}|r_{1t} \sim \mathcal{B}inomial(r_{1t}, p_{1t})}. Let \eqn{\theta_{0t} = log(p_{0t}/(1-p_{0t}))}, and \eqn{\theta_{1t} = log(p_{1t}/(1-p_{1t}))}. The following prior distributions are assumed: \deqn{p(\theta_0|\sigma^2_0) \propto \sigma_0^{-ntables} \exp \left(-\frac{1}{2\sigma^2_0} \theta'_{0} P \theta_{0}\right)} and \deqn{p(\theta_1|\sigma^2_1) \propto \sigma_1^{-ntables} \exp \left(-\frac{1}{2\sigma^2_1} \theta'_{1} P \theta_{1}\right)} where \eqn{P_{ts}} = \eqn{-W_{ts}} for \eqn{t} not equal to \eqn{s} and \eqn{P_{tt}} = \eqn{\sum_{s \ne t}W_{ts}}. The \eqn{\theta_{0t}} is assumed to be a priori independent of \eqn{\theta_{1t}} for all t. In addition, the following hyperpriors are assumed: \eqn{\sigma^2_0 \sim \mathcal{IG}(a_0/2, b_0/2)}, and \eqn{\sigma^2_1 \sim \mathcal{IG}(a_1/2, b_1/2)}. Inference centers on \eqn{p_0}, \eqn{p_1}, \eqn{\sigma^2_0}, and \eqn{\sigma^2_1}. Univariate slice sampling (Neal, 2003) together with Gibbs sampling is used to sample from the posterior distribution. } \examples{ \dontrun{ ## simulated data example 1 set.seed(3920) n <- 100 r0 <- rpois(n, 2000) r1 <- round(runif(n, 100, 4000)) p0.true <- pnorm(-1.5 + 1:n/(n/2)) p1.true <- pnorm(1.0 - 1:n/(n/4)) y0 <- rbinom(n, r0, p0.true) y1 <- rbinom(n, r1, p1.true) c0 <- y0 + y1 c1 <- (r0+r1) - c0 ## plot data dtomogplot(r0, r1, c0, c1, delay=0.1) ## fit dynamic model post1 <- MCMCdynamicEI(r0,r1,c0,c1, mcmc=40000, thin=5, verbose=100, seed=list(NA, 1)) ## fit exchangeable hierarchical model post2 <- MCMChierEI(r0,r1,c0,c1, mcmc=40000, thin=5, verbose=100, seed=list(NA, 2)) p0meanDyn <- colMeans(post1)[1:n] p1meanDyn <- colMeans(post1)[(n+1):(2*n)] p0meanHier <- colMeans(post2)[1:n] p1meanHier <- colMeans(post2)[(n+1):(2*n)] ## plot truth and posterior means pairs(cbind(p0.true, p0meanDyn, p0meanHier, p1.true, p1meanDyn, p1meanHier)) ## simulated data example 2 set.seed(8722) n <- 100 r0 <- rpois(n, 2000) r1 <- round(runif(n, 100, 4000)) p0.true <- pnorm(-1.0 + sin(1:n/(n/4))) p1.true <- pnorm(0.0 - 2*cos(1:n/(n/9))) y0 <- rbinom(n, r0, p0.true) y1 <- rbinom(n, r1, p1.true) c0 <- y0 + y1 c1 <- (r0+r1) - c0 ## plot data dtomogplot(r0, r1, c0, c1, delay=0.1) ## fit dynamic model post1 <- MCMCdynamicEI(r0,r1,c0,c1, mcmc=40000, thin=5, verbose=100, seed=list(NA, 1)) ## fit exchangeable hierarchical model post2 <- MCMChierEI(r0,r1,c0,c1, mcmc=40000, thin=5, verbose=100, seed=list(NA, 2)) p0meanDyn <- colMeans(post1)[1:n] p1meanDyn <- colMeans(post1)[(n+1):(2*n)] p0meanHier <- colMeans(post2)[1:n] p1meanHier <- colMeans(post2)[(n+1):(2*n)] ## plot truth and posterior means pairs(cbind(p0.true, p0meanDyn, p0meanHier, p1.true, p1meanDyn, p1meanHier)) } } \references{ Kevin Quinn. 2004. ``Ecological Inference in the Presence of Temporal Dependence." In \emph{Ecological Inference: New Methodological Strategies}. Gary King, Ori Rosen, and Martin A. Tanner (eds.). New York: Cambridge University Press. Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Radford Neal. 2003. ``Slice Sampling" (with discussion). \emph{Annals of Statistics}, 31: 705-767. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. Jonathan C. Wakefield. 2004. ``Ecological Inference for 2 x 2 Tables.'' \emph{Journal of the Royal Statistical Society, Series A}. 167(3): 385445. } \seealso{ \code{\link{MCMChierEI}}, \code{\link[coda]{plot.mcmc}},\code{\link[coda]{summary.mcmc}} } \keyword{models} MCMCpack/man/choicevar.Rd0000644000176200001440000000130513564573453014653 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCmnl.R \name{choicevar} \alias{choicevar} \title{Handle Choice-Specific Covariates in Multinomial Choice Models} \usage{ choicevar(var, varname, choicelevel) } \arguments{ \item{var}{The is the name of the variable in the dataframe.} \item{varname}{The name of the new variable to be created.} \item{choicelevel}{The level of \code{y} that the variable corresponds to.} } \value{ The new variable used by the \code{MCMCmnl()} function. } \description{ This function handles choice-specific covariates in multinomial choice models. See the example for an example of useage. } \seealso{ \code{\link{MCMCmnl}} } \keyword{manip} MCMCpack/man/MCMCquantreg.Rd0000644000176200001440000001421713564573453015204 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCquantreg.R \name{MCMCquantreg} \alias{MCMCquantreg} \title{Bayesian quantile regression using Gibbs sampling} \usage{ MCMCquantreg(formula, data = NULL, tau = 0.5, burnin = 1000, mcmc = 10000, thin = 1, verbose = 0, seed = sample(1:1e+06, 1), beta.start = NA, b0 = 0, B0 = 0, ...) } \arguments{ \item{formula}{Model formula.} \item{data}{Data frame.} \item{tau}{The quantile of interest. Must be between 0 and 1. The default value of 0.5 corresponds to median regression.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of MCMC iterations after burnin.} \item{thin}{The thinning interval used in the simulation. The number of MCMC iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number and the most recently sampled values of \eqn{\beta} and \eqn{\sigma} are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The default value for this argument is a random integer between 1 and 1,000,000. This default value ensures that if the function is used again with a different value of \eqn{\tau}, it is extremely unlikely that the seed will be identical. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{beta.start}{The starting values for \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the dimension of \eqn{\beta}. The default value of NA will use the OLS estimate \eqn{\hat{\beta}} with \eqn{\hat{\sigma}\Phi^{-1}(\tau)} added on to the first element of \eqn{\hat{\beta}} as the starting value. (\eqn{\hat{\sigma}^2} denotes the usual unbiased estimator of \eqn{\sigma^2} under ordinary mean regression and \eqn{\Phi^{-1}(\tau)} denotes the inverse of the cumulative density function of the standard normal distribution.) Note that the default value assume that an intercept is included in the model. If a scalar is given, that value will serve as the starting value for all \eqn{\beta}.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the dimension of \eqn{\beta}. If this takes a scalar value, then that value will serve as the prior mean for all \eqn{\beta}.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of \eqn{\beta}. Default value of 0 is equivalent to an improper uniform prior for \eqn{\beta}.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarised by functions provided by the coda package. } \description{ This function fits quantile regression models under Bayesian inference. The function samples from the posterior distribution using Gibbs sampling with data augmentation. A multivariate normal prior is assumed for \eqn{\beta}. The user supplies the prior parameters. A sample of the posterior distribution is returned as an mcmc object, which can then be analysed by functions in the coda package. } \details{ \code{MCMCquantreg} simulates from the posterior distribution using Gibbs sampling with data augmentation (see \url{http://people.brunel.ac.uk/~mastkky/}). \eqn{\beta} are drawn from a multivariate normal distribution. The augmented data are drawn conditionally from the inverse Gaussian distribution. The simulation is carried out in compiled C++ code to maximise efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyse the posterior sample. We assume the model \deqn{Q_{\tau}(y_i|x_i) = x_i'\beta} where \eqn{Q_{\tau}(y_i|x_i)} denotes the conditional \eqn{\tau}th quantile of \eqn{y_i} given \eqn{x_i}, and \eqn{\beta=\beta(\tau)} are the regression parameters possibly dependent on \eqn{\tau}. The likelihood is formed based on assuming independent Asymmetric Laplace distributions on the \eqn{y_i} with skewness parameter \eqn{\tau} and location parameters \eqn{x_i'\beta}. This assumption ensures that the likelihood function is maximised by the \eqn{\tau}th conditional quantile of the response variable. We assume standard, semi-conjugate priors on \eqn{\beta}: \deqn{\beta \sim \mathcal{N}(b_0,B_0^{-1})} Only starting values for \eqn{\beta} are allowed for this sampler. } \examples{ \dontrun{ x<-rep(1:10,5) y<-rnorm(50,mean=x) posterior_50 <- MCMCquantreg(y~x) posterior_95 <- MCMCquantreg(y~x, tau=0.95, verbose=10000, mcmc=50000, thin=10, seed=2) plot(posterior_50) plot(posterior_95) raftery.diag(posterior_50) autocorr.plot(posterior_95) summary(posterior_50) summary(posterior_95) } } \references{ Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.2.} \url{http://scythe.lsa.umich.edu}. Craig Reed and Keming Yu. 2009. ``An Efficient Gibbs Sampler for Bayesian Quantile Regression.'' Technical Report. Keming Yu and Jin Zhang. 2005. ``A Three Parameter Asymmetric Laplace Distribution and it's extensions.'' \emph{Communications in Statistics - Theory and Methods}, 34, 1867-1879. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. } \seealso{ \code{\link[MCMCpack]{MCMCregress}}, \code{\link[coda]{plot.mcmc}}, \code{\link[coda]{summary.mcmc}}, \code{\link[stats]{lm}}, \code{\link[quantreg]{rq}} } \author{ Craig Reed } \keyword{models} MCMCpack/man/MCMCregressChange.Rd0000644000176200001440000002162013564573453016132 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCregressChange.R \name{MCMCregressChange} \alias{MCMCregressChange} \title{Markov Chain Monte Carlo for a linear Gaussian Multiple Changepoint Model} \usage{ MCMCregressChange(formula, data = parent.frame(), m = 1, b0 = 0, B0 = 0, c0 = 0.001, d0 = 0.001, sigma.mu = NA, sigma.var = NA, a = NULL, b = NULL, mcmc = 1000, burnin = 1000, thin = 1, verbose = 0, seed = NA, beta.start = NA, P.start = NA, random.perturb = FALSE, WAIC = FALSE, marginal.likelihood = c("none", "Chib95"), ...) } \arguments{ \item{formula}{Model formula.} \item{data}{Data frame.} \item{m}{The number of changepoints.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of beta. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{c0}{\eqn{c_0/2} is the shape parameter for the inverse Gamma prior on \eqn{\sigma^2} (the variance of the disturbances). The amount of information in the inverse Gamma prior is something like that from \eqn{c_0} pseudo-observations.} \item{d0}{\eqn{d_0/2} is the scale parameter for the inverse Gamma prior on \eqn{\sigma^2} (the variance of the disturbances). In constructing the inverse Gamma prior, \eqn{d_0} acts like the sum of squared errors from the \eqn{c_0} pseudo-observations.} \item{sigma.mu}{The mean of the inverse Gamma prior on \eqn{\sigma^2}. \eqn{sigma.mu} and \eqn{sigma.var} allow users to choose the inverse Gamma prior by choosing its mean and variance.} \item{sigma.var}{The variacne of the inverse Gamma prior on \eqn{\sigma^2}. \eqn{sigma.mu} and \eqn{sigma.var} allow users to choose the inverse Gamma prior by choosing its mean and variance.} \item{a}{\eqn{a} is the shape1 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{b}{\eqn{b} is the shape2 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{mcmc}{The number of MCMC iterations after burnin.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of MCMC iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the \eqn{\beta} vector, and the error variance are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{beta.start}{The starting values for the \eqn{\beta} vector. This can either be a scalar or a column vector with dimension equal to the number of betas. The default value of of NA will use the MLE estimate of \eqn{\beta} as the starting value. If this is a scalar, that value will serve as the starting value mean for all of the betas.} \item{P.start}{The starting values for the transition matrix. A user should provide a square matrix with dimension equal to the number of states. By default, draws from the \code{Beta(0.9, 0.1)} are used to construct a proper transition matrix for each raw except the last raw.} \item{random.perturb}{If TRUE, randomly sample hidden states whenever regularly sampled hidden states have at least one single observation state (SOS). SOS is a sign of overfitting in non-ergodic hidden Markov models.} \item{WAIC}{Compute the Widely Applicable Information Criterion (Watanabe 2010).} \item{marginal.likelihood}{How should the marginal likelihood be calculated? Options are: \code{none} in which case the marginal likelihood will not be calculated, and \code{Chib95} in which case the method of Chib (1995) is used.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. The object contains an attribute \code{prob.state} storage matrix that contains the probability of \eqn{state_i} for each period, the log-likelihood of the model (\code{loglike}), and the log-marginal likelihood of the model (\code{logmarglike}). } \description{ This function generates a sample from the posterior distribution of a linear Gaussian model with multiple changepoints. The function uses the Markov chain Monte Carlo method of Chib (1998). The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMCregressChange} simulates from the posterior distribution of the linear regression model with multiple changepoints. The model takes the following form: \deqn{y_t=x_t ' \beta_i + I(s_t=i)\varepsilon_{t},\;\; i=1, \ldots, k} Where \eqn{k} is the number of states and \eqn{I(s_t=i)} is an indicator function that becomes 1 when a state at \eqn{t} is \eqn{i} and otherwise 0. The errors are assumed to be Gaussian in each regime: \deqn{I(s_t=i)\varepsilon_{t} \sim \mathcal{N}(0, \sigma^2_i)} We assume standard, semi-conjugate priors: \deqn{\beta_i \sim \mathcal{N}(b_0,B_0^{-1}),\;\; i=1, \ldots, k} And: \deqn{\sigma^{-2}_i \sim \mathcal{G}amma(c_0/2, d_0/2),\;\; i=1, \ldots, k} Where \eqn{\beta_i} and \eqn{\sigma^{-2}_i} are assumed \emph{a priori} independent. The simulation proper is done in compiled C++ code to maximize efficiency. } \examples{ \dontrun{ set.seed(1119) n <- 100 x1 <- runif(n) true.beta1 <- c(2, -2) true.beta2 <- c(0, 2) true.Sigma <- c(1, 2) true.s <- rep(1:2, each=n/2) mu1 <- cbind(1, x1[true.s==1])\%*\%true.beta1 mu2 <- cbind(1, x1[true.s==2])\%*\%true.beta2 y <- as.ts(c(rnorm(n/2, mu1, sd=sqrt(true.Sigma[1])), rnorm(n/2, mu2, sd=sqrt(true.Sigma[2])))) formula=y ~ x1 ols1 <- lm(y[true.s==1] ~x1[true.s==1]) ols2 <- lm(y[true.s==2] ~x1[true.s==2]) ## prior b0 <- 0 B0 <- 1 sigma.mu=sd(y) sigma.var=var(y) ## models model0 <- MCMCregressChange(formula, m=0, b0=b0, B0=B0, mcmc=100, burnin=100, sigma.mu=sigma.mu, sigma.var=sigma.var, marginal.likelihood="Chib95") model1 <- MCMCregressChange(formula, m=1, b0=b0, B0=B0, mcmc=100, burnin=100, sigma.mu=sigma.mu, sigma.var=sigma.var, marginal.likelihood="Chib95") model2 <- MCMCregressChange(formula, m=2, b0=b0, B0=B0, mcmc=100, burnin=100, sigma.mu=sigma.mu, sigma.var=sigma.var, marginal.likelihood="Chib95") model3 <- MCMCregressChange(formula, m=3, b0=b0, B0=B0, mcmc=100, burnin=100, sigma.mu=sigma.mu, sigma.var=sigma.var, marginal.likelihood="Chib95") model4 <- MCMCregressChange(formula, m=4, b0=b0, B0=B0, mcmc=100, burnin=100, sigma.mu=sigma.mu, sigma.var=sigma.var, marginal.likelihood="Chib95") model5 <- MCMCregressChange(formula, m=5, b0=b0, B0=B0, mcmc=100, burnin=100, sigma.mu=sigma.mu, sigma.var=sigma.var, marginal.likelihood="Chib95") print(BayesFactor(model0, model1, model2, model3, model4, model5)) plotState(model1) plotChangepoint(model1) } } \references{ Jong Hee Park and Yunkyu Sohn. 2017. "Detecting Structural Changes in Network Data: An Application to Changes in Military Alliance Networks, 1816-2012". Working Paper. Jong Hee Park, 2012. ``Unified Method for Dynamic and Cross-Sectional Heterogeneity: Introducing Hidden Markov Panel Models.'' \emph{American Journal of Political Science}.56: 1040-1054. Sumio Watanabe. 2010. "Asymptotic equivalence of Bayes cross validation and widely applicable information criterion in singular learning theory" \emph{Journal of Machine Learning Research}. 11: 3571-3594. Siddhartha Chib. 1995. "Marginal Likelihood from the Gibbs Output." \emph{Journal of the American Statistical Association}. 90: 1313-1321. Siddhartha Chib. 1998. "Estimation and comparison of multiple change-point models." \emph{Journal of Econometrics}. 86: 221-241. } \seealso{ \code{\link{plotState}}, \code{\link{plotChangepoint}} } \keyword{models} MCMCpack/man/SupremeCourt.Rd0000644000176200001440000000175513564573453015356 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/data.R \docType{data} \name{SupremeCourt} \alias{SupremeCourt} \title{U.S. Supreme Court Vote Matrix} \format{The dataframe has contains data for justices Rehnquist, Stevens, O'Connor, Scalia, Kennedy, Souter, Thomas, Ginsburg, and Breyer for the 2000 term of the U.S. Supreme Court. It contains data from 43 non-unanimous cases. The votes are coded liberal (1) and conservative (0) using the protocol of Spaeth (2003). The unit of analysis is the case citation (ANALU=0). We are concerned with formally decided cases issued with written opinions, after full oral argument and cases decided by an equally divided vote (DECTYPE=1,5,6,7).} \source{ Harold J. Spaeth. 2005. \emph{Original United States Supreme Court Database: 1953-2004 Terms.} \url{http://supremecourtdatabase.org}. } \description{ This dataframe contains a matrix votes cast by U.S. Supreme Court justices in all cases in the 2000 term. } \keyword{datasets} MCMCpack/man/write.Scythe.Rd0000644000176200001440000000215213564573453015301 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/scythe.R \name{write.Scythe} \alias{write.Scythe} \title{Write a Matrix to a File to be Read by Scythe} \usage{ write.Scythe(outmatrix, outfile = NA, overwrite = FALSE) } \arguments{ \item{outmatrix}{The matrix to be written to a file.} \item{outfile}{The file to be written. This can include path information.} \item{overwrite}{A logical that determines whether an existing file should be over-written. By default, it protects the user from over-writing existing files.} } \value{ A zero if the file is properly written. } \description{ This function writes a matrix to an ASCII file that can be read by the Sycthe Statistical Library. Scythe requires that input files contain the number of rows and columns in the first row, followed by the data. } \examples{ \dontrun{ write.Scythe(mymatrix, file.path(tempdir(), "myfile.txt")) } } \references{ Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. } \seealso{ \code{\link{write.Scythe}} } \keyword{file} MCMCpack/man/MCpoissongamma.Rd0000644000176200001440000000310513564573453015625 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCmodels.R \name{MCpoissongamma} \alias{MCpoissongamma} \title{Monte Carlo Simulation from a Poisson Likelihood with a Gamma Prior} \usage{ MCpoissongamma(y, alpha, beta, mc = 1000, ...) } \arguments{ \item{y}{A vector of counts (must be non-negative).} \item{alpha}{Gamma prior distribution shape parameter.} \item{beta}{Gamma prior distribution scale parameter.} \item{mc}{The number of Monte Carlo draws to make.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a Poisson likelihood with a Gamma prior. } \details{ \code{MCpoissongamma} directly simulates from the posterior distribution. This model is designed primarily for instructional use. \eqn{\lambda} is the parameter of interest of the Poisson distribution. We assume a conjugate Gamma prior: \deqn{\lambda \sim \mathcal{G}amma(\alpha, \beta)} \eqn{y} is a vector of counts. } \examples{ \dontrun{ data(quine) posterior <- MCpoissongamma(quine$Days, 15, 1, 5000) summary(posterior) plot(posterior) grid <- seq(14,18,0.01) plot(grid, dgamma(grid, 15, 1), type="l", col="red", lwd=3, ylim=c(0,1.3), xlab="lambda", ylab="density") lines(density(posterior), col="blue", lwd=3) legend(17, 1.3, c("prior", "posterior"), lwd=3, col=c("red", "blue")) } } \seealso{ \code{\link[coda]{plot.mcmc}}, \code{\link[coda]{summary.mcmc}} } \keyword{models} MCMCpack/man/dtomogplot.Rd0000644000176200001440000000703013564573453015101 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/tomog.R \name{dtomogplot} \alias{dtomogplot} \title{Dynamic Tomography Plot} \usage{ dtomogplot(r0, r1, c0, c1, time.vec = NA, delay = 0, xlab = "fraction of r0 in c0 (p0)", ylab = "fraction of r1 in c0 (p1)", color.palette = heat.colors, bgcol = "black", ...) } \arguments{ \item{r0}{An \eqn{(ntables \times 1)} vector of row sums from row 0.} \item{r1}{An \eqn{(ntables \times 1)} vector of row sums from row 1.} \item{c0}{An \eqn{(ntables \times 1)} vector of column sums from column 0.} \item{c1}{An \eqn{(ntables \times 1)} vector of column sums from column 1.} \item{time.vec}{Vector of time periods that correspond to the elements of \eqn{r_0}, \eqn{r_1}, \eqn{c_0}, and \eqn{c_1}.} \item{delay}{Time delay in seconds between the plotting of the tomography lines. Setting a positive delay is useful for visualizing temporal dependence.} \item{xlab}{The x axis label for the plot.} \item{ylab}{The y axis label for the plot.} \item{color.palette}{Color palette to be used to encode temporal patterns.} \item{bgcol}{The background color for the plot.} \item{...}{further arguments to be passed} } \description{ dtomogplot is used to produce a tomography plot (see King, 1997) for a series of temporally ordered, partially observed 2 x 2 contingency tables. } \details{ Consider the following partially observed 2 by 2 contingency table: \tabular{llll}{ \tab | \eqn{Y=0} \tab | \eqn{Y=1} \tab | \cr --------- \tab --------- \tab --------- \tab --------- \cr \eqn{X=0} \tab | \eqn{Y_0} \tab | \tab | \eqn{r_0} \cr --------- \tab --------- \tab --------- \tab --------- \cr \eqn{X=1} \tab | \eqn{Y_1} \tab | \tab | \eqn{r_1} \cr --------- \tab --------- \tab --------- \tab --------- \cr \tab | \eqn{c_0} \tab | \eqn{c_1} \tab | \eqn{N} } where \eqn{r_0}, \eqn{r_1}, \eqn{c_0}, \eqn{c_1}, and \eqn{N} are non-negative integers that are observed. The interior cell entries are not observed. It is assumed that \eqn{Y_0|r_0 \sim \mathcal{B}inomial(r_0, p_0)} and \eqn{Y_1|r_1 \sim \mathcal{B}inomial(r_1, p_1)}. This function plots the bounds on the maximum likelihood estimates for (p0, p1) and color codes them by the elements of time.vec. } \examples{ \dontrun{ ## simulated data example 1 set.seed(3920) n <- 100 r0 <- rpois(n, 2000) r1 <- round(runif(n, 100, 4000)) p0.true <- pnorm(-1.5 + 1:n/(n/2)) p1.true <- pnorm(1.0 - 1:n/(n/4)) y0 <- rbinom(n, r0, p0.true) y1 <- rbinom(n, r1, p1.true) c0 <- y0 + y1 c1 <- (r0+r1) - c0 ## plot data dtomogplot(r0, r1, c0, c1, delay=0.1) ## simulated data example 2 set.seed(8722) n <- 100 r0 <- rpois(n, 2000) r1 <- round(runif(n, 100, 4000)) p0.true <- pnorm(-1.0 + sin(1:n/(n/4))) p1.true <- pnorm(0.0 - 2*cos(1:n/(n/9))) y0 <- rbinom(n, r0, p0.true) y1 <- rbinom(n, r1, p1.true) c0 <- y0 + y1 c1 <- (r0+r1) - c0 ## plot data dtomogplot(r0, r1, c0, c1, delay=0.1) } } \references{ Gary King, 1997. \emph{A Solution to the Ecological Inference Problem}. Princeton: Princeton University Press. Jonathan C. Wakefield. 2004. ``Ecological Inference for 2 x 2 Tables.'' \emph{Journal of the Royal Statistical Society, Series A}. 167(3): 385445. Kevin Quinn. 2004. ``Ecological Inference in the Presence of Temporal Dependence." In \emph{Ecological Inference: New Methodological Strategies}. Gary King, Ori Rosen, and Martin A. Tanner (eds.). New York: Cambridge University Press. } \seealso{ \code{\link{MCMChierEI}}, \code{\link{MCMCdynamicEI}},\code{\link{tomogplot}} } \keyword{hplot} MCMCpack/man/MCMClogit.Rd0000644000176200001440000001721613564573453014476 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMClogit.R \name{MCMClogit} \alias{MCMClogit} \title{Markov Chain Monte Carlo for Logistic Regression} \usage{ MCMClogit(formula, data = NULL, burnin = 1000, mcmc = 10000, thin = 1, tune = 1.1, verbose = 0, seed = NA, beta.start = NA, b0 = 0, B0 = 0, user.prior.density = NULL, logfun = TRUE, marginal.likelihood = c("none", "Laplace"), ...) } \arguments{ \item{formula}{Model formula.} \item{data}{Data frame.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of Metropolis iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of mcmc iterations must be divisible by this value.} \item{tune}{Metropolis tuning parameter. Can be either a positive scalar or a \eqn{k}-vector, where \eqn{k} is the length of \eqn{\beta}.Make sure that the acceptance rate is satisfactory (typically between 0.20 and 0.5) before using the posterior sample for inference.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the current beta vector, and the Metropolis acceptance rate are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{beta.start}{The starting value for the \eqn{\beta} vector. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the starting value for all of the betas. The default value of NA will use the maximum likelihood estimate of \eqn{\beta} as the starting value.} \item{b0}{If \code{user.prior.density==NULL} \code{b0} is the prior mean of \eqn{\beta} under a multivariate normal prior. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{If \code{user.prior.density==NULL} \code{B0} is the prior precision of \eqn{\beta} under a multivariate normal prior. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of \eqn{\beta}. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{user.prior.density}{If non-NULL, the prior (log)density up to a constant of proportionality. This must be a function defined in R whose first argument is a continuous (possibly vector) variable. This first argument is the point in the state space at which the prior (log)density is to be evaluated. Additional arguments can be passed to \code{user.prior.density()} by inserting them in the call to \code{MCMClogit()}. See the Details section and the examples below for more information.} \item{logfun}{Logical indicating whether \code{use.prior.density()} returns the natural log of a density function (TRUE) or a density (FALSE).} \item{marginal.likelihood}{How should the marginal likelihood be calculated? Options are: \code{none} in which case the marginal likelihood will not be calculated or \code{Laplace} in which case the Laplace approximation (see Kass and Raftery, 1995) is used.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a logistic regression model using a random walk Metropolis algorithm. The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMClogit} simulates from the posterior distribution of a logistic regression model using a random walk Metropolis algorithm. The simulation proper is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. The model takes the following form: \deqn{y_i \sim \mathcal{B}ernoulli(\pi_i)} Where the inverse link function: \deqn{\pi_i = \frac{\exp(x_i'\beta)}{1 + \exp(x_i'\beta)}} By default, we assume a multivariate Normal prior on \eqn{\beta}: \deqn{\beta \sim \mathcal{N}(b_0,B_0^{-1})} Additionally, arbitrary user-defined priors can be specified with the \code{user.prior.density} argument. If the default multivariate normal prior is used, the Metropolis proposal distribution is centered at the current value of \eqn{\beta} and has variance-covariance \eqn{V = T (B_0 + C^{-1})^{-1} T }, where \eqn{T} is a the diagonal positive definite matrix formed from the \code{tune}, \eqn{B_0} is the prior precision, and \eqn{C} is the large sample variance-covariance matrix of the MLEs. This last calculation is done via an initial call to \code{glm}. If a user-defined prior is used, the Metropolis proposal distribution is centered at the current value of \eqn{\beta} and has variance-covariance \eqn{V = T C T}, where \eqn{T} is a the diagonal positive definite matrix formed from the \code{tune} and \eqn{C} is the large sample variance-covariance matrix of the MLEs. This last calculation is done via an initial call to \code{glm}. } \examples{ \dontrun{ ## default improper uniform prior data(birthwt) posterior <- MCMClogit(low~age+as.factor(race)+smoke, data=birthwt) plot(posterior) summary(posterior) ## multivariate normal prior data(birthwt) posterior <- MCMClogit(low~age+as.factor(race)+smoke, b0=0, B0=.001, data=birthwt) plot(posterior) summary(posterior) ## user-defined independent Cauchy prior logpriorfun <- function(beta){ sum(dcauchy(beta, log=TRUE)) } posterior <- MCMClogit(low~age+as.factor(race)+smoke, data=birthwt, user.prior.density=logpriorfun, logfun=TRUE) plot(posterior) summary(posterior) ## user-defined independent Cauchy prior with additional args logpriorfun <- function(beta, location, scale){ sum(dcauchy(beta, location, scale, log=TRUE)) } posterior <- MCMClogit(low~age+as.factor(race)+smoke, data=birthwt, user.prior.density=logpriorfun, logfun=TRUE, location=0, scale=10) plot(posterior) summary(posterior) } } \references{ Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. } \seealso{ \code{\link[coda]{plot.mcmc}},\code{\link[coda]{summary.mcmc}}, \code{\link[stats]{glm}} } \keyword{models} MCMCpack/man/MCMCpoisson.Rd0000644000176200001440000001254713564573453015054 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCpoisson.R \name{MCMCpoisson} \alias{MCMCpoisson} \title{Markov Chain Monte Carlo for Poisson Regression} \usage{ MCMCpoisson(formula, data = NULL, burnin = 1000, mcmc = 10000, thin = 1, tune = 1.1, verbose = 0, seed = NA, beta.start = NA, b0 = 0, B0 = 0, marginal.likelihood = c("none", "Laplace"), ...) } \arguments{ \item{formula}{Model formula.} \item{data}{Data frame.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of Metropolis iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of mcmc iterations must be divisible by this value.} \item{tune}{Metropolis tuning parameter. Can be either a positive scalar or a \eqn{k}-vector, where \eqn{k} is the length of \eqn{\beta}.Make sure that the acceptance rate is satisfactory (typically between 0.20 and 0.5) before using the posterior sample for inference.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the current beta vector, and the Metropolis acceptance rate are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{beta.start}{The starting value for the \eqn{\beta} vector. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the starting value for all of the betas. The default value of NA will use the maximum likelihood estimate of \eqn{\beta} as the starting value.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of \eqn{\beta}. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{marginal.likelihood}{How should the marginal likelihood be calculated? Options are: \code{none} in which case the marginal likelihood will not be calculated or \code{Laplace} in which case the Laplace approximation (see Kass and Raftery, 1995) is used.} \item{...}{further arguments to be passed.} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a Poisson regression model using a random walk Metropolis algorithm. The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMCpoisson} simulates from the posterior distribution of a Poisson regression model using a random walk Metropolis algorithm. The simulation proper is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. The model takes the following form: \deqn{y_i \sim \mathcal{P}oisson(\mu_i)} Where the inverse link function: \deqn{\mu_i = \exp(x_i'\beta)} We assume a multivariate Normal prior on \eqn{\beta}: \deqn{\beta \sim \mathcal{N}(b_0,B_0^{-1})} The Metropois proposal distribution is centered at the current value of \eqn{\theta} and has variance-covariance \eqn{V = T (B_0 + C^{-1})^{-1} T } where \eqn{T} is a the diagonal positive definite matrix formed from the \code{tune}, \eqn{B_0} is the prior precision, and \eqn{C} is the large sample variance-covariance matrix of the MLEs. This last calculation is done via an initial call to \code{glm}. } \examples{ \dontrun{ counts <- c(18,17,15,20,10,20,25,13,12) outcome <- gl(3,1,9) treatment <- gl(3,3) posterior <- MCMCpoisson(counts ~ outcome + treatment) plot(posterior) summary(posterior) } } \references{ Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. } \seealso{ \code{\link[coda]{plot.mcmc}},\code{\link[coda]{summary.mcmc}}, \code{\link[stats]{glm}} } \keyword{models} MCMCpack/man/MCMCresidualBreakAnalysis.Rd0000644000176200001440000001547213564573453017643 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCresidualBreakAnalysis.R \name{MCMCresidualBreakAnalysis} \alias{MCMCresidualBreakAnalysis} \title{Break Analysis of Univariate Time Series using Markov Chain Monte Carlo} \usage{ MCMCresidualBreakAnalysis(resid, m = 1, b0 = 0, B0 = 0.001, c0 = 0.1, d0 = 0.1, a = NULL, b = NULL, mcmc = 1000, burnin = 1000, thin = 1, verbose = 0, seed = NA, beta.start = NA, P.start = NA, random.perturb = FALSE, WAIC = FALSE, marginal.likelihood = c("none", "Chib95"), ...) } \arguments{ \item{resid}{Univariate time series} \item{m}{The number of breaks.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of beta. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{c0}{\eqn{c_0/2} is the shape parameter for the inverse Gamma prior on \eqn{\sigma^2} (the variance of the disturbances). The amount of information in the inverse Gamma prior is something like that from \eqn{c_0} pseudo-observations.} \item{d0}{\eqn{d_0/2} is the scale parameter for the inverse Gamma prior on \eqn{\sigma^2} (the variance of the disturbances). In constructing the inverse Gamma prior, \eqn{d_0} acts like the sum of squared errors from the \eqn{c_0} pseudo-observations.} \item{a}{\eqn{a} is the shape1 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{b}{\eqn{b} is the shape2 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{mcmc}{The number of MCMC iterations after burnin.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of MCMC iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the \eqn{\beta} vector, and the error variance are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{beta.start}{The starting values for the \eqn{\beta} vector. This can either be a scalar or a column vector with dimension equal to the number of betas. The default value of of NA will use the OLS estimate of \eqn{\beta} as the starting value. If this is a scalar, that value will serve as the starting value mean for all of the betas.} \item{P.start}{The starting values for the transition matrix. A user should provide a square matrix with dimension equal to the number of states. By default, draws from the \code{Beta(0.9, 0.1)} are used to construct a proper transition matrix for each raw except the last raw.} \item{random.perturb}{If TRUE, randomly sample hidden states whenever regularly sampled hidden states have at least one single observation state. It's one method to avoid overfitting in a non-ergodic hidden Markov models. See Park and Sohn (2017).} \item{WAIC}{Compute the Widely Applicable Information Criterion (Watanabe 2010).} \item{marginal.likelihood}{How should the marginal likelihood be calculated? Options are: \code{none} in which case the marginal likelihood will not be calculated, and \code{Chib95} in which case the method of Chib (1995) is used.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function performs a break analysis for univariate time series data using a linear Gaussian changepoint model. The code is written mainly for an internal use in \code{testpanelSubjectBreak}. } \details{ \code{MCMCresidualBreakAnalysis} simulates from the posterior distribution using standard Gibbs sampling (a multivariate Normal draw for the betas, and an inverse Gamma draw for the conditional error variance). The simulation proper is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. The model takes the following form: \deqn{y_{i} \sim \mathcal{N}(\beta_{m}, \sigma^2_{m}) \;\; m = 1, \ldots, M} We assume standard, semi-conjugate priors: \deqn{\beta \sim \mathcal{N}(b_0,B_0^{-1})} And: \deqn{\sigma^{-2} \sim \mathcal{G}amma(c_0/2, d_0/2)} Where \eqn{\beta} and \eqn{\sigma^{-2}} are assumed \emph{a priori} independent. And: \deqn{p_{mm} \sim \mathcal{B}eta(a, b),\;\; m = 1, \ldots, M} Where \eqn{M} is the number of states. } \examples{ \dontrun{ line <- list(X = c(-2,-1,0,1,2), Y = c(1,3,3,3,5)) ols <- lm(Y~X) residual <- rstandard(ols) posterior <- MCMCresidualBreakAnalysis(residual, m = 1, data=line, mcmc=1000, verbose=200) plotState(posterior) summary(posterior) } } \references{ Jong Hee Park and Yunkyu Sohn. 2017. "Detecting Structural Changes in Network Data: An Application to Changes in Military Alliance Networks, 1816-2012". Working Paper. Jong Hee Park, 2012. ``Unified Method for Dynamic and Cross-Sectional Heterogeneity: Introducing Hidden Markov Panel Models.'' \emph{American Journal of Political Science}.56: 1040-1054. Sumio Watanabe. 2010. "Asymptotic equivalence of Bayes cross validation and widely applicable information criterion in singular learning theory" \emph{Journal of Machine Learning Research}. 11: 3571-3594. Siddhartha Chib. 1995. "Marginal Likelihood from the Gibbs Output." \emph{Journal of the American Statistical Association}. 90: 1313-1321. Siddhartha Chib. 1998. "Estimation and comparison of multiple change-point models." \emph{Journal of Econometrics}. 86: 221-241. } \seealso{ \code{\link[coda]{plot.mcmc}}, \code{\link[coda]{summary.mcmc}}, \code{\link[stats]{lm}} } \keyword{models} MCMCpack/man/Nethvote.Rd0000644000176200001440000000511213564573453014504 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/data.R \docType{data} \name{Nethvote} \alias{Nethvote} \title{Dutch Voting Behavior in 1989} \format{A data frame with 1754 observations and 11 variables from the 1989 Dutch Parliamentary Election Study (Anker and Oppenhuis, 1993). Each observation is a survey respondent. These data are a subset of one of five multiply imputed datasets used in Quinn and Martin (2002). For more information see Quinn and Martin (2002). \describe{ \item{vote}{A factor giving the self-reported vote choice of each respondent. The levels are CDA (Christen Democratisch Appel), D66 (Democraten 66), Pvda (Partij van de Arbeid), and VVD (Volkspartij voor Vrijheid en Democratie).} \item{distD66}{A numeric variable giving the squared ideological distance between the respondent and the D66. Larger values indicate ideological dissimilarity between the respondent and the party.} \item{distPvdA}{A numeric variable giving the squared ideological distance between the respondent and the PvdA. Larger values indicate ideological dissimilarity between the respondent and the party.} \item{distVVD}{A numeric variable giving the squared ideological distance between the respondent and the VVD. Larger values indicate ideological dissimilarity between the respondent and the party.} \item{distCDA}{A numeric variable giving the squared ideological distance between the respondent and the CDA. Larger values indicate ideological dissimilarity between the respondent and the party.} \item{relig}{An indicator variable equal to 0 if the respondent is not religious and 1 if the respondent is religious.} \item{class}{Social class of respondent. 0 is the lowest social class, 4 is the highest social class.} \item{income}{Income of respondent. 0 is lowest and 6 is highest.} \item{educ}{Education of respondent. 0 is lowest and 4 is highest.} \item{age}{Age category of respondent. 0 is lowest and 12 is highest.} \item{urban}{Indicator variable equal to 0 if the respondent is not a resident of an urban area and 1 if the respondent is a resident of an urban area.} }} \source{ H. Anker and E.V. Oppenhuis. 1993. ``Dutch Parliamentary Election Study.'' (computer file). Dutch Electoral Research Foundation and Netherlands Central Bureau of Statistics, Amsterdam. } \description{ Dutch Voting Behavior in 1989. } \references{ Kevin M. Quinn and Andrew D. Martin. 2002. ``An Integrated Computational Model of Multiparty Electoral Competition.'' \emph{Statistical Science}. 17: 405-419. } \keyword{datasets} MCMCpack/man/MCMCmixfactanal.Rd0000644000176200001440000002772413564573453015654 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCmixfactanal.R \name{MCMCmixfactanal} \alias{MCMCmixfactanal} \title{Markov Chain Monte Carlo for Mixed Data Factor Analysis Model} \usage{ MCMCmixfactanal(x, factors, lambda.constraints = list(), data = parent.frame(), burnin = 1000, mcmc = 20000, thin = 1, tune = NA, verbose = 0, seed = NA, lambda.start = NA, psi.start = NA, l0 = 0, L0 = 0, a0 = 0.001, b0 = 0.001, store.lambda = TRUE, store.scores = FALSE, std.mean = TRUE, std.var = TRUE, ...) } \arguments{ \item{x}{A one-sided formula containing the manifest variables. Ordinal (including dichotomous) variables must be coded as ordered factors. Each level of these ordered factors must be present in the data passed to the function. NOTE: data input is different in \code{MCMCmixfactanal} than in either \code{MCMCfactanal} or \code{MCMCordfactanal}.} \item{factors}{The number of factors to be fitted.} \item{lambda.constraints}{List of lists specifying possible equality or simple inequality constraints on the factor loadings. A typical entry in the list has one of three forms: \code{varname=list(d,c)} which will constrain the dth loading for the variable named varname to be equal to c, \code{varname=list(d,"+")} which will constrain the dth loading for the variable named varname to be positive, and \code{varname=list(d, "-")} which will constrain the dth loading for the variable named varname to be negative. If x is a matrix without column names defaults names of ``V1", ``V2", ... , etc will be used. Note that, unlike \code{MCMCfactanal}, the \eqn{\Lambda} matrix used here has \code{factors}+1 columns. The first column of \eqn{\Lambda} corresponds to negative item difficulty parameters for ordinal manifest variables and mean parameters for continuous manifest variables and should generally not be constrained directly by the user.} \item{data}{A data frame.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of iterations must be divisible by this value.} \item{tune}{The tuning parameter for the Metropolis-Hastings sampling. Can be either a scalar or a \eqn{k}-vector (where \eqn{k} is the number of manifest variables). \code{tune} must be strictly positive.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is great than 0 the iteration number and the Metropolis-Hastings acceptance rate are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{lambda.start}{Starting values for the factor loading matrix Lambda. If \code{lambda.start} is set to a scalar the starting value for all unconstrained loadings will be set to that scalar. If \code{lambda.start} is a matrix of the same dimensions as Lambda then the \code{lambda.start} matrix is used as the starting values (except for equality-constrained elements). If \code{lambda.start} is set to \code{NA} (the default) then starting values for unconstrained elements in the first column of Lambda are based on the observed response pattern, the remaining unconstrained elements of Lambda are set to 0, and starting values for inequality constrained elements are set to either 1.0 or -1.0 depending on the nature of the constraints.} \item{psi.start}{Starting values for the error variance (uniqueness) matrix. If \code{psi.start} is set to a scalar then the starting value for all diagonal elements of \code{Psi} that represent error variances for continuous variables are set to this value. If \code{psi.start} is a \eqn{k}-vector (where \eqn{k} is the number of manifest variables) then the staring value of \code{Psi} has \code{psi.start} on the main diagonal with the exception that entries corresponding to error variances for ordinal variables are set to 1.. If \code{psi.start} is set to \code{NA} (the default) the starting values of all the continuous variable uniquenesses are set to 0.5. Error variances for ordinal response variables are always constrained (regardless of the value of \code{psi.start} to have an error variance of 1 in order to achieve identification.} \item{l0}{The means of the independent Normal prior on the factor loadings. Can be either a scalar or a matrix with the same dimensions as \code{Lambda}.} \item{L0}{The precisions (inverse variances) of the independent Normal prior on the factor loadings. Can be either a scalar or a matrix with the same dimensions as \code{Lambda}.} \item{a0}{Controls the shape of the inverse Gamma prior on the uniqueness. The actual shape parameter is set to \code{a0/2}. Can be either a scalar or a \eqn{k}-vector.} \item{b0}{Controls the scale of the inverse Gamma prior on the uniquenesses. The actual scale parameter is set to \code{b0/2}. Can be either a scalar or a \eqn{k}-vector.} \item{store.lambda}{A switch that determines whether or not to store the factor loadings for posterior analysis. By default, the factor loadings are all stored.} \item{store.scores}{A switch that determines whether or not to store the factor scores for posterior analysis. \emph{NOTE: This takes an enormous amount of memory, so should only be used if the chain is thinned heavily, or for applications with a small number of observations}. By default, the factor scores are not stored.} \item{std.mean}{If \code{TRUE} (the default) the continuous manifest variables are rescaled to have zero mean.} \item{std.var}{If \code{TRUE} (the default) the continuous manifest variables are rescaled to have unit variance.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a mixed data (both continuous and ordinal) factor analysis model. Normal priors are assumed on the factor loadings and factor scores, improper uniform priors are assumed on the cutpoints, and inverse gamma priors are assumed for the error variances (uniquenesses). The user supplies data and parameters for the prior distributions, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ The model takes the following form: Let \eqn{i=1,\ldots,N} index observations and \eqn{j=1,\ldots,K} index response variables within an observation. An observed variable \eqn{x_{ij}} can be either ordinal with a total of \eqn{C_j} categories or continuous. The distribution of \eqn{X} is governed by a \eqn{N \times K} matrix of latent variables \eqn{X^*} and a series of cutpoints \eqn{\gamma}. \eqn{X^*} is assumed to be generated according to: \deqn{x^*_i = \Lambda \phi_i + \epsilon_i} \deqn{\epsilon_i \sim \mathcal{N}(0,\Psi)} where \eqn{x^*_i} is the \eqn{k}-vector of latent variables specific to observation \eqn{i}, \eqn{\Lambda} is the \eqn{k \times d} matrix of factor loadings, and \eqn{\phi_i} is the \eqn{d}-vector of latent factor scores. It is assumed that the first element of \eqn{\phi_i} is equal to 1 for all \eqn{i}. If the \eqn{j}th variable is ordinal, the probability that it takes the value \eqn{c} in observation \eqn{i} is: \deqn{\pi_{ijc} = \Phi(\gamma_{jc} - \Lambda'_j\phi_i) - \Phi(\gamma_{j(c-1)} - \Lambda'_j\phi_i)} If the \eqn{j}th variable is continuous, it is assumed that \eqn{x^*_{ij} = x_{ij}} for all \eqn{i}. The implementation used here assumes independent conjugate priors for each element of \eqn{\Lambda} and each \eqn{\phi_i}. More specifically we assume: \deqn{\Lambda_{ij} \sim \mathcal{N}(l_{0_{ij}}, L_{0_{ij}}^{-1}), i=1,\ldots,k, j=1,\ldots,d} \deqn{\phi_{i(2:d)} \sim \mathcal{N}(0, I), i=1,\dots,n} \code{MCMCmixfactanal} simulates from the posterior distribution using a Metropolis-Hastings within Gibbs sampling algorithm. The algorithm employed is based on work by Cowles (1996). Note that the first element of \eqn{\phi_i} is a 1. As a result, the first column of \eqn{\Lambda} can be interpretated as negative item difficulty parameters. Further, the first element \eqn{\gamma_1} is normalized to zero, and thus not returned in the mcmc object. The simulation proper is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. As is the case with all measurement models, make sure that you have plenty of free memory, especially when storing the scores. } \examples{ \dontrun{ data(PErisk) post <- MCMCmixfactanal(~courts+barb2+prsexp2+prscorr2+gdpw2, factors=1, data=PErisk, lambda.constraints = list(courts=list(2,"-")), burnin=5000, mcmc=1000000, thin=50, verbose=500, L0=.25, store.lambda=TRUE, store.scores=TRUE, tune=1.2) plot(post) summary(post) library(MASS) data(Cars93) attach(Cars93) new.cars <- data.frame(Price, MPG.city, MPG.highway, Cylinders, EngineSize, Horsepower, RPM, Length, Wheelbase, Width, Weight, Origin) rownames(new.cars) <- paste(Manufacturer, Model) detach(Cars93) # drop obs 57 (Mazda RX 7) b/c it has a rotary engine new.cars <- new.cars[-57,] # drop 3 cylinder cars new.cars <- new.cars[new.cars$Cylinders!=3,] # drop 5 cylinder cars new.cars <- new.cars[new.cars$Cylinders!=5,] new.cars$log.Price <- log(new.cars$Price) new.cars$log.MPG.city <- log(new.cars$MPG.city) new.cars$log.MPG.highway <- log(new.cars$MPG.highway) new.cars$log.EngineSize <- log(new.cars$EngineSize) new.cars$log.Horsepower <- log(new.cars$Horsepower) new.cars$Cylinders <- ordered(new.cars$Cylinders) new.cars$Origin <- ordered(new.cars$Origin) post <- MCMCmixfactanal(~log.Price+log.MPG.city+ log.MPG.highway+Cylinders+log.EngineSize+ log.Horsepower+RPM+Length+ Wheelbase+Width+Weight+Origin, data=new.cars, lambda.constraints=list(log.Horsepower=list(2,"+"), log.Horsepower=c(3,0), weight=list(3,"+")), factors=2, burnin=5000, mcmc=500000, thin=100, verbose=500, L0=.25, tune=3.0) plot(post) summary(post) } } \references{ Kevin M. Quinn. 2004. ``Bayesian Factor Analysis for Mixed Ordinal and Continuous Responses.'' \emph{Political Analysis}. 12: 338-353. Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. M. K. Cowles. 1996. ``Accelerating Monte Carlo Markov Chain Convergence for Cumulative-link Generalized Linear Models." \emph{Statistics and Computing.} 6: 101-110. Valen E. Johnson and James H. Albert. 1999. ``Ordinal Data Modeling." Springer: New York. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. } \seealso{ \code{\link[coda]{plot.mcmc}}, \code{\link[coda]{summary.mcmc}}, \code{\link[stats]{factanal}}, \code{\link[MCMCpack]{MCMCfactanal}}, \code{\link[MCMCpack]{MCMCordfactanal}}, \code{\link[MCMCpack]{MCMCirt1d}}, \code{\link[MCMCpack]{MCMCirtKd}} } \keyword{models} MCMCpack/man/tomogplot.Rd0000644000176200001440000000443413564573453014742 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/tomog.R \name{tomogplot} \alias{tomogplot} \title{Tomography Plot} \usage{ tomogplot(r0, r1, c0, c1, xlab = "fraction of r0 in c0 (p0)", ylab = "fraction of r1 in c0 (p1)", bgcol = "white", ...) } \arguments{ \item{r0}{An \eqn{(ntables \times 1)} vector of row sums from row 0.} \item{r1}{An \eqn{(ntables \times 1)} vector of row sums from row 1.} \item{c0}{An \eqn{(ntables \times 1)} vector of column sums from column 0.} \item{c1}{An \eqn{(ntables \times 1)} vector of column sums from column 1.} \item{xlab}{The x axis label for the plot.} \item{ylab}{The y axis label for the plot.} \item{bgcol}{The background color for the plot.} \item{...}{further arguments to be passed} } \description{ tomogplot is used to produce a tomography plot (see King, 1997) for a series of partially observed 2 x 2 contingency tables. } \details{ Consider the following partially observed 2 by 2 contingency table: \tabular{llll}{ \tab | \eqn{Y=0} \tab | \eqn{Y=1} \tab | \cr --------- \tab --------- \tab --------- \tab --------- \cr \eqn{X=0} \tab | \eqn{Y_0} \tab | \tab | \eqn{r_0} \cr --------- \tab --------- \tab --------- \tab --------- \cr \eqn{X=1} \tab | \eqn{Y_1} \tab | \tab | \eqn{r_1} \cr --------- \tab --------- \tab --------- \tab --------- \cr \tab | \eqn{c_0} \tab | \eqn{c_1} \tab | \eqn{N} } where \eqn{r_0}, \eqn{r_1}, \eqn{c_0}, \eqn{c_1}, and \eqn{N} are non-negative integers that are observed. The interior cell entries are not observed. It is assumed that \eqn{Y_0|r_0 \sim \mathcal{B}inomial(r_0, p_0)} and \eqn{Y_1|r_1 \sim \mathcal{B}inomial(r_1, p_1)}. This function plots the bounds on the maximum likelihood estimatess for (p0, p1). } \examples{ r0 <- rpois(100, 500) r1 <- rpois(100, 200) c0 <- rpois(100, 100) c1 <- (r0 + r1) - c0 tomogplot(r0, r1, c0, c1) } \references{ Gary King, 1997. \emph{A Solution to the Ecological Inference Problem}. Princeton: Princeton University Press. Jonathan C. Wakefield. 2004. ``Ecological Inference for 2 x 2 Tables.'' \emph{Journal of the Royal Statistical Society, Series A}. 167(3): 385445. } \seealso{ \code{\link{MCMChierEI}}, \code{\link{MCMCdynamicEI}}, \code{\link{dtomogplot}} } \keyword{hplot} MCMCpack/man/HMMpanelRE.Rd0000644000176200001440000002245013564573453014604 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/HMMpanelRE.R \name{HMMpanelRE} \alias{HMMpanelRE} \title{Markov Chain Monte Carlo for the Hidden Markov Random-effects Model} \usage{ HMMpanelRE(subject.id, time.id, y, X, W, m = 1, mcmc = 1000, burnin = 1000, thin = 1, verbose = 0, b0 = 0, B0 = 0.001, c0 = 0.001, d0 = 0.001, r0, R0, a = NULL, b = NULL, seed = NA, beta.start = NA, sigma2.start = NA, D.start = NA, P.start = NA, marginal.likelihood = c("none", "Chib95"), ...) } \arguments{ \item{subject.id}{A numeric vector indicating the group number. It should start from 1.} \item{time.id}{A numeric vector indicating the time unit. It should start from 1.} \item{y}{The dependent variable} \item{X}{The model matrix of the fixed-effects} \item{W}{The model matrix of the random-effects. W should be a subset of X.} \item{m}{The number of changepoints.} \item{mcmc}{The number of MCMC iterations after burn-in.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of MCMC iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0, the iteration number and the posterior density samples are printed to the screen every \code{verbose}th iteration.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of beta. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{c0}{\eqn{c_0/2} is the shape parameter for the inverse Gamma prior on \eqn{\sigma^2} (the variance of the disturbances). The amount of information in the inverse Gamma prior is something like that from \eqn{c_0} pseudo-observations.} \item{d0}{\eqn{d_0/2} is the scale parameter for the inverse Gamma prior on \eqn{\sigma^2} (the variance of the disturbances). In constructing the inverse Gamma prior, \eqn{d_0} acts like the sum of squared errors from the \eqn{c_0} pseudo-observations.} \item{r0}{The shape parameter for the Inverse-Wishart prior on variance matrix for the random effects. Set r=q for an uninformative prior where q is the number of random effects} \item{R0}{The scale matrix for the Inverse-Wishart prior on variance matrix for the random effects. This must be a square q-dimension matrix. Use plausible variance regarding random effects for the diagonal of R.} \item{a}{\eqn{a} is the shape1 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{b}{\eqn{b} is the shape2 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{seed}{The seed for the random number generator. If NA, current R system seed is used.} \item{beta.start}{The starting values for the beta vector. This can either be a scalar or a column vector with dimension equal to the number of betas. The default value of NA will use draws from the Uniform distribution with the same boundary with the data as the starting value. If this is a scalar, that value will serve as the starting value mean for all of the betas. When there is no covariate, the log value of means should be used.} \item{sigma2.start}{The starting values for \eqn{\sigma^2}. This can either be a scalar or a column vector with dimension equal to the number of states.} \item{D.start}{The starting values for the beta vector. This can either be a scalar or a column vector with dimension equal to the number of betas. The default value of NA will use draws from the Uniform distribution with the same boundary with the data as the starting value. If this is a scalar, that value will serve as the starting value mean for all of the betas. When there is no covariate, the log value of means should be used.} \item{P.start}{The starting values for the transition matrix. A user should provide a square matrix with dimension equal to the number of states. By default, draws from the \code{Beta(0.9, 0.1)} are used to construct a proper transition matrix for each raw except the last raw.} \item{marginal.likelihood}{How should the marginal likelihood be calculated? Options are: \code{none} in which case the marginal likelihood will not be calculated and \code{Chib95} in which case the method of Chib (1995) is used.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. The object contains an attribute \code{prob.state} storage matrix that contains the probability of \eqn{state_i} for each period, and the log-marginal likelihood of the model (\code{logmarglike}). } \description{ HMMpanelRE generates a sample from the posterior distribution of the hidden Markov random-effects model discussed in Park (2011). The code works for panel data with the same starting point. The sampling of panel parameters is based on Algorithm 2 of Chib and Carlin (1999). This model uses a multivariate Normal prior for the fixed effects parameters and varying individual effects, an Inverse-Wishart prior on the random-effects parameters, an Inverse-Gamma prior on the residual error variance, and Beta prior for transition probabilities. The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{HMMpanelRE} simulates from the random-effect hidden Markov panel model introduced by Park (2011). The model takes the following form: \deqn{y_i = X_i \beta_m + W_i b_i + \varepsilon_i\;\; m = 1, \ldots, M}{y_i = X_i * beta_m + W_i * b_i + epsilon_i, m = 1,..., M.} Where each group \eqn{i} have \eqn{k_i} observations. Random-effects parameters are assumed to be time-varying at the system level: \deqn{b_i \sim \mathcal{N}_q(0, D_m)} \deqn{\varepsilon_i \sim \mathcal{N}(0, \sigma^2_m I_{k_i})} And the errors: We assume standard, conjugate priors: \deqn{\beta \sim \mathcal{N}_p(b0, B0)} And: \deqn{\sigma^{2} \sim \mathcal{IG}amma(c0/2, d0/2)} And: \deqn{D \sim \mathcal{IW}ishart(r0, R0)} See Chib and Carlin (1999) for more details. And: \deqn{p_{mm} \sim \mathcal{B}eta(a, b),\;\; m = 1, \ldots, M} Where \eqn{M} is the number of states. \emph{NOTE:} We do not provide default parameters for the priors on the precision matrix for the random effects. When fitting one of these models, it is of utmost importance to choose a prior that reflects your prior beliefs about the random effects. Using the \code{dwish} and \code{rwish} functions might be useful in choosing these values. } \examples{ \dontrun{ ## data generating set.seed(1977) Q <- 3 true.beta1 <- c(1, 1, 1) ; true.beta2 <- c(-1, -1, -1) true.sigma2 <- c(2, 5); true.D1 <- diag(.5, Q); true.D2 <- diag(2.5, Q) N=30; T=100; NT <- N*T x1 <- runif(NT, 1, 2) x2 <- runif(NT, 1, 2) X <- cbind(1, x1, x2); W <- X; y <- rep(NA, NT) ## true break numbers are one and at the center break.point = rep(T/2, N); break.sigma=c(rep(1, N)); break.list <- rep(1, N) id <- rep(1:N, each=NT/N) K <- ncol(X); ruler <- c(1:T) ## compute the weight for the break W.mat <- matrix(NA, T, N) for (i in 1:N){ W.mat[, i] <- pnorm((ruler-break.point[i])/break.sigma[i]) } Weight <- as.vector(W.mat) ## data generating by weighting two means and variances j = 1 for (i in 1:N){ Xi <- X[j:(j+T-1), ] Wi <- W[j:(j+T-1), ] true.V1 <- true.sigma2[1]*diag(T) + Wi\%*\%true.D1\%*\%t(Wi) true.V2 <- true.sigma2[2]*diag(T) + Wi\%*\%true.D2\%*\%t(Wi) true.mean1 <- Xi\%*\%true.beta1 true.mean2 <- Xi\%*\%true.beta2 weight <- Weight[j:(j+T-1)] y[j:(j+T-1)] <- (1-weight)*true.mean1 + (1-weight)*chol(true.V1)\%*\%rnorm(T) + weight*true.mean2 + weight*chol(true.V2)\%*\%rnorm(T) j <- j + T } ## model fitting subject.id <- c(rep(1:N, each=T)) time.id <- c(rep(1:T, N)) ## model fitting G <- 100 b0 <- rep(0, K) ; B0 <- solve(diag(100, K)) c0 <- 2; d0 <- 2 r0 <- 5; R0 <- diag(c(1, 0.1, 0.1)) subject.id <- c(rep(1:N, each=T)) time.id <- c(rep(1:T, N)) out1 <- HMMpanelRE(subject.id, time.id, y, X, W, m=1, mcmc=G, burnin=G, thin=1, verbose=G, b0=b0, B0=B0, c0=c0, d0=d0, r0=r0, R0=R0) ## latent state changes plotState(out1) ## print mcmc output summary(out1) } } \references{ Jong Hee Park, 2012. ``Unified Method for Dynamic and Cross-Sectional Heterogeneity: Introducing Hidden Markov Panel Models.'' \emph{American Journal of Political Science}.56: 1040-1054. Siddhartha Chib. 1998. ``Estimation and comparison of multiple change-point models.'' \emph{Journal of Econometrics}. 86: 221-241. } \keyword{models} MCMCpack/man/MCMCoprobitChange.Rd0000644000176200001440000001671613564573453016150 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCoprobitChange.R \name{MCMCoprobitChange} \alias{MCMCoprobitChange} \title{Markov Chain Monte Carlo for Ordered Probit Changepoint Regression Model} \usage{ MCMCoprobitChange(formula, data = parent.frame(), m = 1, burnin = 1000, mcmc = 1000, thin = 1, tune = NA, verbose = 0, seed = NA, beta.start = NA, gamma.start = NA, P.start = NA, b0 = NULL, B0 = NULL, a = NULL, b = NULL, marginal.likelihood = c("none", "Chib95"), gamma.fixed = 0, ...) } \arguments{ \item{formula}{Model formula.} \item{data}{Data frame.} \item{m}{The number of changepoints.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of MCMC iterations after burnin.} \item{thin}{The thinning interval used in the simulation. The number of MCMC iterations must be divisible by this value.} \item{tune}{The tuning parameter for the Metropolis-Hastings step. Default of NA corresponds to a choice of 0.05 divided by the number of categories in the response variable.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the \eqn{\beta} vector, and the error variance are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{beta.start}{The starting values for the \eqn{\beta} vector. This can either be a scalar or a column vector with dimension equal to the number of betas. The default value of of NA will use the MLE estimate of \eqn{\beta} as the starting value. If this is a scalar, that value will serve as the starting value mean for all of the betas.} \item{gamma.start}{The starting values for the \eqn{\gamma} vector. This can either be a scalar or a column vector with dimension equal to the number of gammas. The default value of of NA will use the MLE estimate of \eqn{\gamma} as the starting value. If this is a scalar, that value will serve as the starting value mean for all of the gammas.} \item{P.start}{The starting values for the transition matrix. A user should provide a square matrix with dimension equal to the number of states. By default, draws from the \code{Beta(0.9, 0.1)} are used to construct a proper transition matrix for each raw except the last raw.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of beta. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{a}{\eqn{a} is the shape1 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{b}{\eqn{b} is the shape2 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{marginal.likelihood}{How should the marginal likelihood be calculated? Options are: \code{none} in which case the marginal likelihood will not be calculated, and \code{Chib95} in which case the method of Chib (1995) is used.} \item{gamma.fixed}{1 if users want to constrain \eqn{\gamma} values to be constant. By default, \eqn{\gamma} values are allowed to vary across regimes.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. The object contains an attribute \code{prob.state} storage matrix that contains the probability of \eqn{state_i} for each period, the log-likelihood of the model (\code{loglike}), and the log-marginal likelihood of the model (\code{logmarglike}). } \description{ This function generates a sample from the posterior distribution of an ordered probit regression model with multiple parameter breaks. The function uses the Markov chain Monte Carlo method of Chib (1998). The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMCoprobitChange} simulates from the posterior distribution of an ordinal probit regression model with multiple parameter breaks. The simulation of latent states is based on the linear approximation method discussed in Park (2011). The model takes the following form: \deqn{\Pr(y_t = 1) = \Phi(\gamma_{c, m} - x_i'\beta_m) - \Phi(\gamma_{c-1, m} - x_i'\beta_m)\;\; m = 1, \ldots, M} Where \eqn{M} is the number of states, and \eqn{\gamma_{c, m}} and \eqn{\beta_m} are paramters when a state is \eqn{m} at \eqn{t}. We assume Gaussian distribution for prior of \eqn{\beta}: \deqn{\beta_m \sim \mathcal{N}(b_0,B_0^{-1}),\;\; m = 1, \ldots, M} And: \deqn{p_{mm} \sim \mathcal{B}eta(a, b),\;\; m = 1, \ldots, M} Where \eqn{M} is the number of states. Note that when the fitted changepoint model has very few observations in any of states, the marginal likelihood outcome can be ``nan," which indicates that too many breaks are assumed given the model and data. } \examples{ set.seed(1909) N <- 200 x1 <- rnorm(N, 1, .5); ## set a true break at 100 z1 <- 1 + x1[1:100] + rnorm(100); z2 <- 1 -0.2*x1[101:200] + rnorm(100); z <- c(z1, z2); y <- z ## generate y y[z < 1] <- 1; y[z >= 1 & z < 2] <- 2; y[z >= 2] <- 3; ## inputs formula <- y ~ x1 ## fit multiple models with a varying number of breaks out1 <- MCMCoprobitChange(formula, m=1, mcmc=100, burnin=100, thin=1, tune=c(.5, .5), verbose=100, b0=0, B0=10, marginal.likelihood = "Chib95") out2 <- MCMCoprobitChange(formula, m=2, mcmc=100, burnin=100, thin=1, tune=c(.5, .5, .5), verbose=100, b0=0, B0=10, marginal.likelihood = "Chib95") ## Do model comparison ## NOTE: the chain should be run longer than this example! BayesFactor(out1, out2) ## draw plots using the "right" model plotState(out1) plotChangepoint(out1) } \references{ Jong Hee Park. 2011. ``Changepoint Analysis of Binary and Ordinal Probit Models: An Application to Bank Rate Policy Under the Interwar Gold Standard." \emph{Political Analysis}. 19: 188-204. Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Siddhartha Chib. 1998. ``Estimation and comparison of multiple change-point models.'' \emph{Journal of Econometrics}. 86: 221-241. } \seealso{ \code{\link{plotState}}, \code{\link{plotChangepoint}} } \keyword{models} MCMCpack/man/MCMCirt1d.Rd0000644000176200001440000002320613564573453014377 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCirt1d.R \name{MCMCirt1d} \alias{MCMCirt1d} \title{Markov Chain Monte Carlo for One Dimensional Item Response Theory Model} \usage{ MCMCirt1d(datamatrix, theta.constraints = list(), burnin = 1000, mcmc = 20000, thin = 1, verbose = 0, seed = NA, theta.start = NA, alpha.start = NA, beta.start = NA, t0 = 0, T0 = 1, ab0 = 0, AB0 = 0.25, store.item = FALSE, store.ability = TRUE, drop.constant.items = TRUE, ...) } \arguments{ \item{datamatrix}{The matrix of data. Must be 0, 1, or missing values. The rows of \code{datamatrix} correspond to subjects and the columns correspond to items.} \item{theta.constraints}{A list specifying possible simple equality or inequality constraints on the ability parameters. A typical entry in the list has one of three forms: \code{varname=c} which will constrain the ability parameter for the subject named \code{varname} to be equal to c, \code{varname="+"} which will constrain the ability parameter for the subject named \code{varname} to be positive, and \code{varname="-"} which will constrain the ability parameter for the subject named \code{varname} to be negative. If x is a matrix without row names defaults names of ``V1",``V2", ... , etc will be used. See Rivers (2003) for a thorough discussion of identification of IRT models.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of Gibbs iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of Gibbs iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 then every \code{verbose}th iteration will be printed to the screen.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{theta.start}{The starting values for the subject abilities (ideal points). This can either be a scalar or a column vector with dimension equal to the number of voters. If this takes a scalar value, then that value will serve as the starting value for all of the thetas. The default value of NA will choose the starting values based on an eigenvalue-eigenvector decomposition of the aggreement score matrix formed from the \code{datamatrix}.} \item{alpha.start}{The starting values for the \eqn{\alpha} difficulty parameters. This can either be a scalar or a column vector with dimension equal to the number of items. If this takes a scalar value, then that value will serve as the starting value for all of the alphas. The default value of NA will set the starting values based on a series of probit regressions that condition on the starting values of theta.} \item{beta.start}{The starting values for the \eqn{\beta} discrimination parameters. This can either be a scalar or a column vector with dimension equal to the number of items. If this takes a scalar value, then that value will serve as the starting value for all of the betas. The default value of NA will set the starting values based on a series of probit regressions that condition on the starting values of theta.} \item{t0}{A scalar parameter giving the prior mean of the subject abilities (ideal points).} \item{T0}{A scalar parameter giving the prior precision (inverse variance) of the subject abilities (ideal points).} \item{ab0}{The prior mean of \code{(alpha, beta)}. Can be either a scalar or a 2-vector. If a scalar both means will be set to the passed value. The prior mean is assumed to be the same across all items.} \item{AB0}{The prior precision of \code{(alpha, beta)}.This can either be ascalar or a 2 by 2 matrix. If this takes a scalar value, then that value times an identity matrix serves as the prior precision. The prior precision is assumed to be the same across all items.} \item{store.item}{A switch that determines whether or not to store the item parameters for posterior analysis. \emph{NOTE: In situations with many items storing the item parameters takes an enormous amount of memory, so \code{store.item} should only be \code{FALSE} if the chain is thinned heavily, or for applications with a small number of items}. By default, the item parameters are not stored.} \item{store.ability}{A switch that determines whether or not to store the ability parameters for posterior analysis. \emph{NOTE: In situations with many individuals storing the ability parameters takes an enormous amount of memory, so \code{store.ability} should only be \code{TRUE} if the chain is thinned heavily, or for applications with a small number of individuals}. By default, the item parameters are stored.} \item{drop.constant.items}{A switch that determines whether or not items that have no variation should be deleted before fitting the model. Default = TRUE.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the sample from the posterior distribution. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a one dimensional item response theory (IRT) model, with Normal priors on the subject abilities (ideal points), and multivariate Normal priors on the item parameters. The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ If you are interested in fitting K-dimensional item response theory models, or would rather identify the model by placing constraints on the item parameters, please see \code{\link[MCMCpack]{MCMCirtKd}}. \code{MCMCirt1d} simulates from the posterior distribution using standard Gibbs sampling using data augmentation (a Normal draw for the subject abilities, a multivariate Normal draw for the item parameters, and a truncated Normal draw for the latent utilities). The simulation proper is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. The model takes the following form. We assume that each subject has an subject ability (ideal point) denoted \eqn{\theta_j} and that each item has a difficulty parameter \eqn{\alpha_i} and discrimination parameter \eqn{\beta_i}. The observed choice by subject \eqn{j} on item \eqn{i} is the observed data matrix which is \eqn{(I \times J)}. We assume that the choice is dictated by an unobserved utility: \deqn{z_{i,j} = -\alpha_i + \beta_i \theta_j + \varepsilon_{i,j}} Where the errors are assumed to be distributed standard Normal. The parameters of interest are the subject abilities (ideal points) and the item parameters. We assume the following priors. For the subject abilities (ideal points): \deqn{\theta_j \sim \mathcal{N}(t_{0},T_{0}^{-1})} For the item parameters, the prior is: \deqn{\left[\alpha_i, \beta_i \right]' \sim \mathcal{N}_2 (ab_{0},AB_{0}^{-1})} The model is identified by the proper priors on the item parameters and constraints placed on the ability parameters. As is the case with all measurement models, make sure that you have plenty of free memory, especially when storing the item parameters. } \examples{ \dontrun{ ## US Supreme Court Example with inequality constraints data(SupremeCourt) posterior1 <- MCMCirt1d(t(SupremeCourt), theta.constraints=list(Scalia="+", Ginsburg="-"), B0.alpha=.2, B0.beta=.2, burnin=500, mcmc=100000, thin=20, verbose=500, store.item=TRUE) geweke.diag(posterior1) plot(posterior1) summary(posterior1) ## US Senate Example with equality constraints data(Senate) Sen.rollcalls <- Senate[,6:677] posterior2 <- MCMCirt1d(Sen.rollcalls, theta.constraints=list(KENNEDY=-2, HELMS=2), burnin=2000, mcmc=100000, thin=20, verbose=500) geweke.diag(posterior2) plot(posterior2) summary(posterior2) } } \references{ James H. Albert. 1992. ``Bayesian Estimation of Normal Ogive Item Response Curves Using Gibbs Sampling." \emph{Journal of Educational Statistics}. 17: 251-269. Joshua Clinton, Simon Jackman, and Douglas Rivers. 2004. ``The Statistical Analysis of Roll Call Data." \emph{American Political Science Review}. 98: 355-370. Valen E. Johnson and James H. Albert. 1999. ``Ordinal Data Modeling." Springer: New York. Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. Douglas Rivers. 2004. ``Identification of Multidimensional Item-Response Models." Stanford University, typescript. } \seealso{ \code{\link[coda]{plot.mcmc}},\code{\link[coda]{summary.mcmc}}, \code{\link[MCMCpack]{MCMCirtKd}} } \keyword{models} MCMCpack/man/MCMCmnl.Rd0000644000176200001440000002402213564573453014137 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCmnl.R \name{MCMCmnl} \alias{MCMCmnl} \title{Markov Chain Monte Carlo for Multinomial Logistic Regression} \usage{ MCMCmnl(formula, baseline = NULL, data = NULL, burnin = 1000, mcmc = 10000, thin = 1, mcmc.method = c("IndMH", "RWM", "slice"), tune = 1, tdf = 6, verbose = 0, seed = NA, beta.start = NA, b0 = 0, B0 = 0, ...) } \arguments{ \item{formula}{Model formula. If the choicesets do not vary across individuals, the \code{y} variable should be a factor or numeric variable that gives the observed choice of each individual. If the choicesets do vary across individuals, \code{y} should be a \eqn{n \times p} matrix where \eqn{n} is the number of individuals and \eqn{p} is the maximum number of choices in any choiceset. Here each column of \code{y} corresponds to a particular observed choice and the elements of \code{y} should be either \code{0} (not chosen but available), \code{1} (chosen), or \code{-999} (not available). Choice-specific covariates have to be entered using the syntax: \code{choicevar(cvar, "var", "choice")} where \code{cvar} is the name of a variable in \code{data}, \code{"var"} is the name of the new variable to be created, and \code{"choice"} is the level of \code{y} that \code{cvar} corresponds to. Specifying each choice-specific covariate will typically require \eqn{p} calls to the \code{choicevar} function in the formula. Individual specific covariates can be entered into the formula normally. See the examples section below to see the syntax used to fit various models.} \item{baseline}{The baseline category of the response variable. \code{baseline} should be set equal to one of the observed levels of the response variable. If left equal to \code{NULL} then the baseline level is set to the alpha-numerically first element of the response variable. If the choicesets vary across individuals, the baseline choice must be in the choiceset of each individual.} \item{data}{The data frame used for the analysis. Each row of the dataframe should correspond to an individual who is making a choice.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of iterations to run the sampler past burn-in.} \item{thin}{The thinning interval used in the simulation. The number of mcmc iterations must be divisible by this value.} \item{mcmc.method}{Can be set to either "IndMH" (default), "RWM", or "slice" to perform independent Metropolis-Hastings sampling, random walk Metropolis sampling or slice sampling respectively.} \item{tune}{Metropolis tuning parameter. Can be either a positive scalar or a \eqn{k}-vector, where \eqn{k} is the length of \eqn{\beta}. Make sure that the acceptance rate is satisfactory (typically between 0.20 and 0.5) before using the posterior sample for inference.} \item{tdf}{Degrees of freedom for the multivariate-t proposal distribution when \code{mcmc.method} is set to "IndMH". Must be positive.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the current beta vector, and the Metropolis acceptance rate are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{beta.start}{The starting value for the \eqn{\beta} vector. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the starting value for all of the betas. The default value of NA will use the maximum likelihood estimate of \eqn{\beta} as the starting value.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of \eqn{\beta}. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{...}{Further arguments to be passed.} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a multinomial logistic regression model using either a random walk Metropolis algorithm or a slice sampler. The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMCmnl} simulates from the posterior distribution of a multinomial logistic regression model using either a random walk Metropolis algorithm or a univariate slice sampler. The simulation proper is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. The model takes the following form: \deqn{y_i \sim \mathcal{M}ultinomial(\pi_i)} where: \deqn{\pi_{ij} = \frac{\exp(x_{ij}'\beta)}{\sum_{k=1}^p\exp(x_{ik}'\beta)}} We assume a multivariate Normal prior on \eqn{\beta}: \deqn{\beta \sim \mathcal{N}(b_0,B_0^{-1})} The Metropolis proposal distribution is centered at the current value of \eqn{\beta} and has variance-covariance \eqn{V = T(B_0 + C^{-1})^{-1} T}, where \eqn{T} is a the diagonal positive definite matrix formed from the \code{tune}, \eqn{B_0} is the prior precision, and \eqn{C} is the large sample variance-covariance matrix of the MLEs. This last calculation is done via an initial call to \code{optim}. } \examples{ \dontrun{ data(Nethvote) ## just a choice-specific X var post1 <- MCMCmnl(vote ~ choicevar(distD66, "sqdist", "D66") + choicevar(distPvdA, "sqdist", "PvdA") + choicevar(distVVD, "sqdist", "VVD") + choicevar(distCDA, "sqdist", "CDA"), baseline="D66", mcmc.method="IndMH", B0=0, verbose=500, mcmc=100000, thin=10, tune=1.0, data=Nethvote) plot(post1) summary(post1) ## just individual-specific X vars post2<- MCMCmnl(vote ~ relig + class + income + educ + age + urban, baseline="D66", mcmc.method="IndMH", B0=0, verbose=500, mcmc=100000, thin=10, tune=0.5, data=Nethvote) plot(post2) summary(post2) ## both choice-specific and individual-specific X vars post3 <- MCMCmnl(vote ~ choicevar(distD66, "sqdist", "D66") + choicevar(distPvdA, "sqdist", "PvdA") + choicevar(distVVD, "sqdist", "VVD") + choicevar(distCDA, "sqdist", "CDA") + relig + class + income + educ + age + urban, baseline="D66", mcmc.method="IndMH", B0=0, verbose=500, mcmc=100000, thin=10, tune=0.5, data=Nethvote) plot(post3) summary(post3) ## numeric y variable nethvote$vote <- as.numeric(nethvote$vote) post4 <- MCMCmnl(vote ~ choicevar(distD66, "sqdist", "2") + choicevar(distPvdA, "sqdist", "3") + choicevar(distVVD, "sqdist", "4") + choicevar(distCDA, "sqdist", "1") + relig + class + income + educ + age + urban, baseline="2", mcmc.method="IndMH", B0=0, verbose=500, mcmc=100000, thin=10, tune=0.5, data=Nethvote) plot(post4) summary(post4) ## Simulated data example with nonconstant choiceset n <- 1000 y <- matrix(0, n, 4) colnames(y) <- c("a", "b", "c", "d") xa <- rnorm(n) xb <- rnorm(n) xc <- rnorm(n) xd <- rnorm(n) xchoice <- cbind(xa, xb, xc, xd) z <- rnorm(n) for (i in 1:n){ ## randomly determine choiceset (c is always in choiceset) choiceset <- c(3, sample(c(1,2,4), 2, replace=FALSE)) numer <- matrix(0, 4, 1) for (j in choiceset){ if (j == 3){ numer[j] <- exp(xchoice[i, j] ) } else { numer[j] <- exp(xchoice[i, j] - z[i] ) } } p <- numer / sum(numer) y[i,] <- rmultinom(1, 1, p) y[i,-choiceset] <- -999 } post5 <- MCMCmnl(y~choicevar(xa, "x", "a") + choicevar(xb, "x", "b") + choicevar(xc, "x", "c") + choicevar(xd, "x", "d") + z, baseline="c", verbose=500, mcmc=100000, thin=10, tune=.85) plot(post5) summary(post5) } } \references{ Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Radford Neal. 2003. ``Slice Sampling'' (with discussion). \emph{Annals of Statistics}, 31: 705-767. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. Siddhartha Chib, Edward Greenberg, and Yuxin Chen. 1998. ``MCMC Methods for Fitting and Comparing Multinomial Response Models." } \seealso{ \code{\link[coda]{plot.mcmc}},\code{\link[coda]{summary.mcmc}}, \code{\link[nnet]{multinom}} } \keyword{models} MCMCpack/man/HDPHSMMnegbin.Rd0000644000176200001440000002314213564573453015176 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/HDPHSMMnegbin.R \name{HDPHSMMnegbin} \alias{HDPHSMMnegbin} \title{Markov Chain Monte Carlo for HDP-HSMM with a Negative Binomial outcome distribution} \usage{ HDPHSMMnegbin(formula, data = parent.frame(), K = 10, b0 = 0, B0 = 1, a.alpha = 1, b.alpha = 0.1, a.gamma = 1, b.gamma = 0.1, a.omega, b.omega, e = 2, f = 2, g = 10, r = 1, burnin = 1000, mcmc = 1000, thin = 1, verbose = 0, seed = NA, beta.start = NA, P.start = NA, rho.start = NA, rho.step, nu.start = NA, omega.start = NA, gamma.start = 0.5, alpha.start = 100, ...) } \arguments{ \item{formula}{Model formula.} \item{data}{Data frame.} \item{K}{The number of regimes under consideration. This should be larger than the hypothesized number of regimes in the data. Note that the sampler will likely visit fewer than \code{K} regimes.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of beta. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{a.alpha, b.alpha}{Shape and scale parameters for the Gamma distribution on \eqn{\alpha}.} \item{a.gamma, b.gamma}{Shape and scale parameters for the Gamma distribution on \eqn{\gamma}.} \item{a.omega, b.omega}{Paramaters for the Beta prior on \eqn{\omega}, which determines the regime length distribution, which is Negative Binomial, with parameters \code{r} and \code{omega}.} \item{e}{The hyperprior for the distribution \eqn{\rho} See details.} \item{f}{The hyperprior for the distribution \eqn{\rho}. See details.} \item{g}{The hyperprior for the distribution \eqn{\rho}. See details.} \item{r}{Parameter of the Negative Binomial prior for regime durations. It is the target number of successful trials. Must be strictly positive. Higher values increase the variance of the duration distributions.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of Metropolis iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of mcmc iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the current beta vector, and the Metropolis acceptance rate are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{beta.start}{The starting value for the \eqn{\beta} vector. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the starting value for all of the betas. The default value of NA will use the maximum likelihood estimate of \eqn{\beta} as the starting value for all regimes.} \item{P.start}{Initial transition matrix between regimes. Should be a \code{K} by \code{K} matrix. If not provided, the default value will be uniform transition distributions.} \item{rho.start}{The starting value for the \eqn{\rho} variable. This can either be a scalar or a column vector with dimension equal to the number of regimes. If the value is scalar, it will be used for all regimes. The default value is a vector of ones.} \item{rho.step}{Tuning parameter for the slice sampling approach to sampling \eqn{rho}. Determines the size of the step-out used to find the correct slice to draw from. Lower values are more accurate, but will take longer (up to a fixed searching limit). Default is 0.1.} \item{nu.start}{The starting values for the random effect, \eqn{\nu}. The default value is a vector of ones.} \item{omega.start}{A vector of starting values for the probability of success parameter in the Negative Binomial distribution that governs the duration distributions.} \item{alpha.start, gamma.start}{Scalar starting values for the \eqn{\alpha}, and \eqn{\gamma} parameters.} \item{...}{further arguments to be passed.} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a Hidden Semi-Markov Model with a Heirarchical Dirichlet Process and a Negative Binomial outcome distribution (Johnson and Willsky, 2013). The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{HDPHSMMnegbin} simulates from the posterior distribution of a HDP-HSMM with a Negative Binomial outcome distribution, allowing for multiple, arbitrary changepoints in the model. The details of the model are discussed in Johnson & Willsky (2013). The implementation here is based on a weak-limit approximation, where there is a large, though finite number of regimes that can be switched between. Unlike other changepoint models in \code{MCMCpack}, the HDP-HSMM approach allows for the state sequence to return to previous visited states. The model takes the following form, where we show the fixed-limit version: \deqn{y_t \sim \mathcal{P}oisson(\nu_t\mu_t)} \deqn{\mu_t = x_t ' \beta_k,\;\; k = 1, \ldots, K} \deqn{\nu_t \sim \mathcal{G}amma(\rho_k, \rho_k)} Where \eqn{K} is an upper bound on the number of states and \eqn{\beta_k} and \eqn{\rho_k} are parameters when a state is \eqn{k} at \eqn{t}. In the HDP-HSMM, there is a super-state sequence that, for a given observation, is drawn from the transition distribution and then a duration is drawn from a duration distribution to determin how long that state will stay active. After that duration, a new super-state is drawn from the transition distribution, where self-transitions are disallowed. The transition probabilities between states are assumed to follow a heirarchical Dirichlet process: \deqn{\pi_k \sim \mathcal{D}irichlet(\alpha\delta_1, \ldots , \alpha\delta_K)} \deqn{\delta \sim \mathcal{D}irichlet(\gamma/K, \ldots, \gamma/K)} In the algorithm itself, these \eqn{\pi} vectors are modified to remove self-transitions as discussed above. There is a unique duration distribution for each regime with the following parameters: \deqn{D_k \sim \mathcal{N}egBin(r, \omega_k)} \deqn{\omega_k \sim \mathcal{B}eta(a_{\omega,k}, b_{\omega, k})} We assume Gaussian distribution for prior of \eqn{\beta}: \deqn{\beta_k \sim \mathcal{N}(b_0,B_0^{-1}),\;\; m = 1, \ldots, K} The overdispersion parameters have a prior with the following form: \deqn{f(\rho_k|e,f,g) \propto \rho^{e-1}(\rho + g)^{-(e+f)}} The model is simulated via blocked Gibbs conditonal on the states. The \eqn{\beta} being simulated via the auxiliary mixture sampling method of Fuerhwirth-Schanetter et al. (2009). The \eqn{\rho} is updated via slice sampling. The \eqn{\nu_t} are updated their (conjugate) full conditional, which is also Gamma. The states and their durations are drawn as in Johnson & Willsky (2013). } \examples{ \dontrun{ n <- 150 reg <- 3 true.s <- gl(reg, n/reg, n) rho.true <- c(1.5, 0.5, 3) b1.true <- c(1, -2, 2) x1 <- runif(n, 0, 2) nu.true <- rgamma(n, rho.true[true.s], rho.true[true.s]) mu <- nu.true * exp(1 + x1 * b1.true[true.s]) y <- rpois(n, mu) posterior <- HDPHSMMnegbin(y ~ x1, K = 10, verbose = 1000, e = 2, f = 2, g = 10, b0 = 0, B0 = 1/9, a.omega = 1, b.omega = 100, r = 1, rho.step = rep(0.75, times = 10), seed = list(NA, 2), omega.start = 0.05, gamma.start = 10, alpha.start = 5) plotHDPChangepoint(posterior, ylab="Density", start=1) } } \references{ Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Sylvia Fruehwirth-Schnatter, Rudolf Fruehwirth, Leonhard Held, and Havard Rue. 2009. ``Improved auxiliary mixture sampling for hierarchical models of non-Gaussian data'', \emph{Statistics and Computing} 19(4): 479-492. \url{http://doi.org/10.1007/s11222-008-9109-4} Matthew Blackwell. 2017. ``Game Changers: Detecting Shifts in Overdispersed Count Data,'' \emph{Political Analysis} Forthcoming. \url{http://www.mattblackwell.org/files/papers/gamechangers-letter.pdf} Matthew J. Johnson and Alan S. Willsky. 2013. ``Bayesian Nonparametric Hidden Semi-Markov Models.'' \emph{Journal of Machine Learning Research}, 14(Feb), 673-701. } \seealso{ \code{\link{MCMCnegbinChange}}, \code{\link{HDPHMMnegbin}}, } \keyword{models} MCMCpack/man/MCmultinomdirichlet.Rd0000644000176200001440000000310413564573453016663 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCmodels.R \name{MCmultinomdirichlet} \alias{MCmultinomdirichlet} \title{Monte Carlo Simulation from a Multinomial Likelihood with a Dirichlet Prior} \usage{ MCmultinomdirichlet(y, alpha0, mc = 1000, ...) } \arguments{ \item{y}{A vector of data (number of successes for each category).} \item{alpha0}{The vector of parameters of the Dirichlet prior.} \item{mc}{The number of Monte Carlo draws to make.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a multinomial likelihood with a Dirichlet prior. } \details{ \code{MCmultinomdirichlet} directly simulates from the posterior distribution. This model is designed primarily for instructional use. \eqn{\pi} is the parameter of interest of the multinomial distribution. It is of dimension \eqn{(d \times 1)}. We assume a conjugate Dirichlet prior: \deqn{\pi \sim \mathcal{D}irichlet(\alpha_0)} \eqn{y} is a \eqn{(d \times 1)} vector of observed data. } \examples{ \dontrun{ ## Example from Gelman, et. al. (1995, p. 78) posterior <- MCmultinomdirichlet(c(727,583,137), c(1,1,1), mc=10000) bush.dukakis.diff <- posterior[,1] - posterior[,2] cat("Pr(Bush > Dukakis): ", sum(bush.dukakis.diff > 0) / length(bush.dukakis.diff), "\\n") hist(bush.dukakis.diff) } } \seealso{ \code{\link[coda]{plot.mcmc}}, \code{\link[coda]{summary.mcmc}} } \keyword{models} MCMCpack/man/MCMCregress.Rd0000644000176200001440000001470113564573453015026 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCregress.R \name{MCMCregress} \alias{MCMCregress} \title{Markov Chain Monte Carlo for Gaussian Linear Regression} \usage{ MCMCregress(formula, data = NULL, burnin = 1000, mcmc = 10000, thin = 1, verbose = 0, seed = NA, beta.start = NA, b0 = 0, B0 = 0, c0 = 0.001, d0 = 0.001, sigma.mu = NA, sigma.var = NA, marginal.likelihood = c("none", "Laplace", "Chib95"), ...) } \arguments{ \item{formula}{Model formula.} \item{data}{Data frame.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of MCMC iterations after burnin.} \item{thin}{The thinning interval used in the simulation. The number of MCMC iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the \eqn{\beta} vector, and the error variance are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{beta.start}{The starting values for the \eqn{\beta} vector. This can either be a scalar or a column vector with dimension equal to the number of betas. The default value of of NA will use the OLS estimate of \eqn{\beta} as the starting value. If this is a scalar, that value will serve as the starting value mean for all of the betas.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of beta. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{c0}{\eqn{c_0/2} is the shape parameter for the inverse Gamma prior on \eqn{\sigma^2} (the variance of the disturbances). The amount of information in the inverse Gamma prior is something like that from \eqn{c_0} pseudo-observations.} \item{d0}{\eqn{d_0/2} is the scale parameter for the inverse Gamma prior on \eqn{\sigma^2} (the variance of the disturbances). In constructing the inverse Gamma prior, \eqn{d_0} acts like the sum of squared errors from the \eqn{c_0} pseudo-observations.} \item{sigma.mu}{The mean of the inverse Gamma prior on \eqn{\sigma^2}. \eqn{sigma.mu} and \eqn{sigma.var} allow users to choose the inverse Gamma prior by choosing its mean and variance.} \item{sigma.var}{The variacne of the inverse Gamma prior on \eqn{\sigma^2}. \eqn{sigma.mu} and \eqn{sigma.var} allow users to choose the inverse Gamma prior by choosing its mean and variance.} \item{marginal.likelihood}{How should the marginal likelihood be calculated? Options are: \code{none} in which case the marginal likelihood will not be calculated, \code{Laplace} in which case the Laplace approximation (see Kass and Raftery, 1995) is used, and \code{Chib95} in which case the method of Chib (1995) is used.} \item{...}{further arguments to be passed.} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a linear regression model with Gaussian errors using Gibbs sampling (with a multivariate Gaussian prior on the beta vector, and an inverse Gamma prior on the conditional error variance). The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMCregress} simulates from the posterior distribution using standard Gibbs sampling (a multivariate Normal draw for the betas, and an inverse Gamma draw for the conditional error variance). The simulation proper is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. The model takes the following form: \deqn{y_i = x_i ' \beta + \varepsilon_{i}} Where the errors are assumed to be Gaussian: \deqn{\varepsilon_{i} \sim \mathcal{N}(0, \sigma^2)} We assume standard, semi-conjugate priors: \deqn{\beta \sim \mathcal{N}(b_0,B_0^{-1})} And: \deqn{\sigma^{-2} \sim \mathcal{G}amma(c_0/2, d_0/2)} Where \eqn{\beta} and \eqn{\sigma^{-2}} are assumed \emph{a priori} independent. Note that only starting values for \eqn{\beta} are allowed because simulation is done using Gibbs sampling with the conditional error variance as the first block in the sampler. } \examples{ \dontrun{ line <- list(X = c(-2,-1,0,1,2), Y = c(1,3,3,3,5)) posterior <- MCMCregress(Y~X, b0=0, B0 = 0.1, sigma.mu = 5, sigma.var = 25, data=line, verbose=1000) plot(posterior) raftery.diag(posterior) summary(posterior) } } \references{ Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Siddhartha Chib. 1995. ``Marginal Likelihood from the Gibbs Output.'' \emph{Journal of the American Statistical Association}. 90: 1313-1321. Robert E. Kass and Adrian E. Raftery. 1995. ``Bayes Factors.'' \emph{Journal of the American Statistical Association}. 90: 773-795. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. } \seealso{ \code{\link[coda]{plot.mcmc}}, \code{\link[coda]{summary.mcmc}}, \code{\link[stats]{lm}} } \keyword{models} MCMCpack/man/MCMChlogit.Rd0000644000176200001440000002361013564573453014641 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMChlogit.R \name{MCMChlogit} \alias{MCMChlogit} \title{Markov Chain Monte Carlo for the Hierarchical Binomial Linear Regression Model using the logit link function} \usage{ MCMChlogit(fixed, random, group, data, burnin = 5000, mcmc = 10000, thin = 10, verbose = 1, seed = NA, beta.start = NA, sigma2.start = NA, Vb.start = NA, mubeta = 0, Vbeta = 1e+06, r, R, nu = 0.001, delta = 0.001, FixOD = 0, ...) } \arguments{ \item{fixed}{A two-sided linear formula of the form 'y~x1+...+xp' describing the fixed-effects part of the model, with the response on the left of a '~' operator and the p fixed terms, separated by '+' operators, on the right. Response variable y must be 0 or 1 (Binomial process).} \item{random}{A one-sided formula of the form '~x1+...+xq' specifying the model for the random effects part of the model, with the q random terms, separated by '+' operators.} \item{group}{String indicating the name of the grouping variable in \code{data}, defining the hierarchical structure of the model.} \item{data}{A data frame containing the variables in the model.} \item{burnin}{The number of burnin iterations for the sampler.} \item{mcmc}{The number of Gibbs iterations for the sampler. Total number of Gibbs iterations is equal to \code{burnin+mcmc}. \code{burnin+mcmc} must be divisible by 10 and superior or equal to 100 so that the progress bar can be displayed.} \item{thin}{The thinning interval used in the simulation. The number of mcmc iterations must be divisible by this value.} \item{verbose}{A switch (0,1) which determines whether or not the progress of the sampler is printed to the screen. Default is 1: a progress bar is printed, indicating the step (in \%) reached by the Gibbs sampler.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister.} \item{beta.start}{The starting values for the \eqn{\beta} vector. This can either be a scalar or a p-length vector. The default value of NA will use the OLS \eqn{\beta} estimate of the corresponding Gaussian Linear Regression without random effects. If this is a scalar, that value will serve as the starting value mean for all of the betas.} \item{sigma2.start}{Scalar for the starting value of the residual error variance. The default value of NA will use the OLS estimates of the corresponding Gaussian Linear Regression without random effects.} \item{Vb.start}{The starting value for variance matrix of the random effects. This must be a square q-dimension matrix. Default value of NA uses an identity matrix.} \item{mubeta}{The prior mean of \eqn{\beta}. This can either be a scalar or a p-length vector. If this takes a scalar value, then that value will serve as the prior mean for all of the betas. The default value of 0 will use a vector of zeros for an uninformative prior.} \item{Vbeta}{The prior variance of \eqn{\beta}. This can either be a scalar or a square p-dimension matrix. If this takes a scalar value, then that value times an identity matrix serves as the prior variance of beta. Default value of 1.0E6 will use a diagonal matrix with very large variance for an uninformative flat prior.} \item{r}{The shape parameter for the Inverse-Wishart prior on variance matrix for the random effects. r must be superior or equal to q. Set r=q for an uninformative prior. See the NOTE for more details} \item{R}{The scale matrix for the Inverse-Wishart prior on variance matrix for the random effects. This must be a square q-dimension matrix. Use plausible variance regarding random effects for the diagonal of R. See the NOTE for more details} \item{nu}{The shape parameter for the Inverse-Gamma prior on the residual error variance. Default value is \code{nu=delta=0.001} for uninformative prior.} \item{delta}{The rate (1/scale) parameter for the Inverse-Gamma prior on the residual error variance. Default value is \code{nu=delta=0.001} for uninformative prior.} \item{FixOD}{A switch (0,1) which determines whether or not the variance for over-dispersion (sigma2) should be fixed (1) or not (0). Default is 0, parameter sigma2 is estimated. If FixOD=1, sigma2 is fixed to the value provided for \code{sigma2.start}.} \item{...}{further arguments to be passed} } \value{ \item{mcmc}{An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. The posterior sample of the deviance \eqn{D}, with \eqn{D=-2\log(\prod_i P(y_i|\theta_i))}, is also provided.} \item{theta.pred}{Predictive posterior mean for the inverse-logit of the latent variables. The approximation of Diggle et al. (2004) is used to marginalized with respect to over-dispersion terms: \deqn{E[\theta_i|\beta,b_i,\sigma^2]=\phi^{-1}((X_i\beta+W_ib_i)/\sqrt{(16\sqrt{3}/15\pi)^2\sigma^2+1})} } } \description{ MCMChlogit generates a sample from the posterior distribution of a Hierarchical Binomial Linear Regression Model using the logit link function and Algorithm 2 of Chib and Carlin (1999). This model uses a multivariate Normal prior for the fixed effects parameters, an Inverse-Wishart prior on the random effects variance matrix, and an Inverse-Gamma prior on the variance modelling over-dispersion. The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMChlogit} simulates from the posterior distribution sample using the blocked Gibbs sampler of Chib and Carlin (1999), Algorithm 2. The simulation is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. The model takes the following form: \deqn{y_i \sim \mathcal{B}ernoulli(\theta_i)} With latent variables \eqn{\phi(\theta_i)}, \eqn{\phi} being the logit link function: \deqn{\phi(\theta_i) = X_i \beta + W_i b_i + \varepsilon_i} Where each group \eqn{i} have \eqn{k_i} observations. Where the random effects: \deqn{b_i \sim \mathcal{N}_q(0,V_b)} And the over-dispersion terms: \deqn{\varepsilon_i \sim \mathcal{N}(0, \sigma^2 I_{k_i})} We assume standard, conjugate priors: \deqn{\beta \sim \mathcal{N}_p(\mu_{\beta},V_{\beta})} And: \deqn{\sigma^{2} \sim \mathcal{IG}amma(\nu, 1/\delta)} And: \deqn{V_b \sim \mathcal{IW}ishart(r, rR)} See Chib and Carlin (1999) for more details. \emph{NOTE:} We do not provide default parameters for the priors on the precision matrix for the random effects. When fitting one of these models, it is of utmost importance to choose a prior that reflects your prior beliefs about the random effects. Using the \code{dwish} and \code{rwish} functions might be useful in choosing these values. } \examples{ \dontrun{ #======================================== # Hierarchical Binomial Linear Regression #======================================== #== inv.logit function inv.logit <- function(x, min=0, max=1) { p <- exp(x)/(1+exp(x)) p <- ifelse( is.na(p) & !is.na(x), 1, p ) # fix problems with +Inf return(p*(max-min)+min) } #== Generating data # Constants nobs <- 1000 nspecies <- 20 species <- c(1:nspecies,sample(c(1:nspecies),(nobs-nspecies),replace=TRUE)) # Covariates X1 <- runif(n=nobs,min=-10,max=10) X2 <- runif(n=nobs,min=-10,max=10) X <- cbind(rep(1,nobs),X1,X2) W <- X # Target parameters # beta beta.target <- matrix(c(0.3,0.2,0.1),ncol=1) # Vb Vb.target <- c(0.5,0.05,0.05) # b b.target <- cbind(rnorm(nspecies,mean=0,sd=sqrt(Vb.target[1])), rnorm(nspecies,mean=0,sd=sqrt(Vb.target[2])), rnorm(nspecies,mean=0,sd=sqrt(Vb.target[3]))) # Response theta <- vector() Y <- vector() for (n in 1:nobs) { theta[n] <- inv.logit(X[n,]\%*\%beta.target+W[n,]\%*\%b.target[species[n],]) Y[n] <- rbinom(n=1,size=1,prob=theta[n]) } # Data-set Data <- as.data.frame(cbind(Y,theta,X1,X2,species)) plot(Data$X1,Data$theta) #== Call to MCMChlogit model <- MCMChlogit(fixed=Y~X1+X2, random=~X1+X2, group="species", data=Data, burnin=5000, mcmc=1000, thin=1,verbose=1, seed=NA, beta.start=0, sigma2.start=1, Vb.start=1, mubeta=0, Vbeta=1.0E6, r=3, R=diag(c(1,0.1,0.1)), nu=0.001, delta=0.001, FixOD=1) #== MCMC analysis # Graphics pdf("Posteriors-MCMChlogit.pdf") plot(model$mcmc) dev.off() # Summary summary(model$mcmc) # Predictive posterior mean for each observation model$theta.pred # Predicted-Observed plot(Data$theta,model$theta.pred) abline(a=0,b=1) ## #Not run ## #You can also compare with lme4 results ## #== lme4 resolution ## library(lme4) ## model.lme4 <- lmer(Y~X1+X2+(1+X1+X2|species),data=Data,family="binomial") ## summary(model.lme4) ## plot(fitted(model.lme4),model$theta.pred,main="MCMChlogit/lme4") ## abline(a=0,b=1) } } \references{ Siddhartha Chib and Bradley P. Carlin. 1999. ``On MCMC Sampling in Hierarchical Longitudinal Models.'' \emph{Statistics and Computing.} 9: 17-26. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Andrew D. Martin and Kyle L. Saunders. 2002. ``Bayesian Inference for Political Science Panel Data.'' Paper presented at the 2002 Annual Meeting of the American Political Science Association. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. Diggle P., Heagerty P., Liang K., and Zeger S. 2004. ``Analysis of Longitudinal Data.'' \emph{Oxford University Press}, 2sd Edition. } \seealso{ \code{\link[coda]{plot.mcmc}}, \code{\link[coda]{summary.mcmc}} } \author{ Ghislain Vieilledent } \keyword{Binomial} \keyword{MCMC} \keyword{bayesian} \keyword{glmm} \keyword{hierarchical} \keyword{logit} \keyword{mixed} \keyword{models} MCMCpack/man/MCMCprobit.Rd0000644000176200001440000001342313564573453014653 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCprobit.R \name{MCMCprobit} \alias{MCMCprobit} \title{Markov Chain Monte Carlo for Probit Regression} \usage{ MCMCprobit(formula, data = NULL, burnin = 1000, mcmc = 10000, thin = 1, verbose = 0, seed = NA, beta.start = NA, b0 = 0, B0 = 0, bayes.resid = FALSE, marginal.likelihood = c("none", "Laplace", "Chib95"), ...) } \arguments{ \item{formula}{Model formula.} \item{data}{Data frame.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of Gibbs iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of Gibbs iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number and the betas are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{beta.start}{The starting value for the \eqn{\beta} vector. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the starting value for all of the betas. The default value of NA will use the maximum likelihood estimate of \eqn{\beta} as the starting value.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of \eqn{\beta}. Default value of 0 is equivalent to an improper uniform prior on \eqn{\beta}.} \item{bayes.resid}{Should latent Bayesian residuals (Albert and Chib, 1995) be returned? Default is FALSE meaning no residuals should be returned. Alternatively, the user can specify an array of integers giving the observation numbers for which latent residuals should be calculated and returned. TRUE will return draws of latent residuals for all observations.} \item{marginal.likelihood}{How should the marginal likelihood be calculated? Options are: \code{none} in which case the marginal likelihood will not be calculated, \code{Laplace} in which case the Laplace approximation (see Kass and Raftery, 1995) is used, or \code{Chib95} in which case Chib (1995) method is used.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a probit regression model using the data augmentation approach of Albert and Chib (1993). The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMCprobit} simulates from the posterior distribution of a probit regression model using data augmentation. The simulation proper is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. The model takes the following form: \deqn{y_i \sim \mathcal{B}ernoulli(\pi_i)} Where the inverse link function: \deqn{\pi_i = \Phi(x_i'\beta)} We assume a multivariate Normal prior on \eqn{\beta}: \deqn{\beta \sim \mathcal{N}(b_0,B_0^{-1})} See Albert and Chib (1993) for estimation details. } \examples{ \dontrun{ data(birthwt) out1 <- MCMCprobit(low~as.factor(race)+smoke, data=birthwt, b0 = 0, B0 = 10, marginal.likelihood="Chib95") out2 <- MCMCprobit(low~age+as.factor(race), data=birthwt, b0 = 0, B0 = 10, marginal.likelihood="Chib95") out3 <- MCMCprobit(low~age+as.factor(race)+smoke, data=birthwt, b0 = 0, B0 = 10, marginal.likelihood="Chib95") BayesFactor(out1, out2, out3) plot(out3) summary(out3) } } \references{ Albert, J. H. and S. Chib. 1993. ``Bayesian Analysis of Binary and Polychotomous Response Data.'' \emph{J. Amer. Statist. Assoc.} 88, 669-679 Albert, J. H. and S. Chib. 1995. ``Bayesian Residual Analysis for Binary Response Regression Models.'' \emph{Biometrika.} 82, 747-759. Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Siddhartha Chib. 1995. ``Marginal Likelihood from the Gibbs Output.'' \emph{Journal of the American Statistical Association}. 90: 1313-1321. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. } \seealso{ \code{\link[coda]{plot.mcmc}},\code{\link[coda]{summary.mcmc}}, \code{\link[stats]{glm}} } \keyword{models} MCMCpack/man/plotHDPChangepoint.Rd0000644000176200001440000000152713564573453016410 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/hdp-utils.R \name{plotHDPChangepoint} \alias{plotHDPChangepoint} \title{Posterior Changepoint Probabilities from HDP-HMM} \usage{ plotHDPChangepoint(mcmcout, main = "Posterior Changepoint Probabilities", xlab = "Time", ylab = "", start = 1) } \arguments{ \item{mcmcout}{The \code{mcmc} object containing the posterior density sample from a changepoint model. Note that this must be from a HDP-HMM sampler.} \item{main}{Title of the plot} \item{xlab}{Label for the x-axis.} \item{ylab}{Label for the y-axis.} \item{start}{The time of the first observation to be shown in the time series plot.} } \description{ Plot the posterior density of regime change. } \seealso{ \code{\link{HDPHMMpoisson}}, \code{\link{HDPHMMnegbin}}, \code{\link{HDPHSMMnegbin}} } \keyword{hplot} MCMCpack/man/MCMChpoisson.Rd0000644000176200001440000002303113564573453015212 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMChpoisson.R \name{MCMChpoisson} \alias{MCMChpoisson} \title{Markov Chain Monte Carlo for the Hierarchical Poisson Linear Regression Model using the log link function} \usage{ MCMChpoisson(fixed, random, group, data, burnin = 5000, mcmc = 10000, thin = 10, verbose = 1, seed = NA, beta.start = NA, sigma2.start = NA, Vb.start = NA, mubeta = 0, Vbeta = 1e+06, r, R, nu = 0.001, delta = 0.001, FixOD = 0, ...) } \arguments{ \item{fixed}{A two-sided linear formula of the form 'y~x1+...+xp' describing the fixed-effects part of the model, with the response on the left of a '~' operator and the p fixed terms, separated by '+' operators, on the right. Response variable y must be 0 or 1 (Binomial process).} \item{random}{A one-sided formula of the form '~x1+...+xq' specifying the model for the random effects part of the model, with the q random terms, separated by '+' operators.} \item{group}{String indicating the name of the grouping variable in \code{data}, defining the hierarchical structure of the model.} \item{data}{A data frame containing the variables in the model.} \item{burnin}{The number of burnin iterations for the sampler.} \item{mcmc}{The number of Gibbs iterations for the sampler. Total number of Gibbs iterations is equal to \code{burnin+mcmc}. \code{burnin+mcmc} must be divisible by 10 and superior or equal to 100 so that the progress bar can be displayed.} \item{thin}{The thinning interval used in the simulation. The number of mcmc iterations must be divisible by this value.} \item{verbose}{A switch (0,1) which determines whether or not the progress of the sampler is printed to the screen. Default is 1: a progress bar is printed, indicating the step (in \%) reached by the Gibbs sampler.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister.} \item{beta.start}{The starting values for the \eqn{\beta} vector. This can either be a scalar or a p-length vector. The default value of NA will use the OLS \eqn{\beta} estimate of the corresponding Gaussian Linear Regression without random effects. If this is a scalar, that value will serve as the starting value mean for all of the betas.} \item{sigma2.start}{Scalar for the starting value of the residual error variance. The default value of NA will use the OLS estimates of the corresponding Gaussian Linear Regression without random effects.} \item{Vb.start}{The starting value for variance matrix of the random effects. This must be a square q-dimension matrix. Default value of NA uses an identity matrix.} \item{mubeta}{The prior mean of \eqn{\beta}. This can either be a scalar or a p-length vector. If this takes a scalar value, then that value will serve as the prior mean for all of the betas. The default value of 0 will use a vector of zeros for an uninformative prior.} \item{Vbeta}{The prior variance of \eqn{\beta}. This can either be a scalar or a square p-dimension matrix. If this takes a scalar value, then that value times an identity matrix serves as the prior variance of beta. Default value of 1.0E6 will use a diagonal matrix with very large variance for an uninformative flat prior.} \item{r}{The shape parameter for the Inverse-Wishart prior on variance matrix for the random effects. r must be superior or equal to q. Set r=q for an uninformative prior. See the NOTE for more details.} \item{R}{The scale matrix for the Inverse-Wishart prior on variance matrix for the random effects. This must be a square q-dimension matrix. Use plausible variance regarding random effects for the diagonal of R. See the NOTE for more details.} \item{nu}{The shape parameter for the Inverse-Gamma prior on the residual error variance. Default value is \code{nu=delta=0.001} for uninformative prior.} \item{delta}{The rate (1/scale) parameter for the Inverse-Gamma prior on the residual error variance. Default value is \code{nu=delta=0.001} for uninformative prior.} \item{FixOD}{A switch (0,1) which determines whether or not the variance for over-dispersion (sigma2) should be fixed (1) or not (0). Default is 0, parameter sigma2 is estimated. If FixOD=1, sigma2 is fixed to the value provided for \code{sigma2.start}.} \item{...}{further arguments to be passed} } \value{ \item{mcmc}{An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. The posterior sample of the deviance \eqn{D}, with \eqn{D=-2\log(\prod_i P(y_i|\lambda_i))}, is also provided.} \item{lambda.pred}{Predictive posterior mean for the exponential of the latent variables. The approximation of Diggle et al. (2004) is used to marginalized with respect to over-dispersion terms: \deqn{E[\lambda_i|\beta,b_i,\sigma^2]=\phi^{-1}((X_i \beta+W_i b_i)+0.5 \sigma^2)}} } \description{ MCMChpoisson generates a sample from the posterior distribution of a Hierarchical Poisson Linear Regression Model using the log link function and Algorithm 2 of Chib and Carlin (1999). This model uses a multivariate Normal prior for the fixed effects parameters, an Inverse-Wishart prior on the random effects variance matrix, and an Inverse-Gamma prior on the variance modelling over-dispersion. The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMChpoisson} simulates from the posterior distribution sample using the blocked Gibbs sampler of Chib and Carlin (1999), Algorithm 2. The simulation is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. The model takes the following form: \deqn{y_i \sim \mathcal{P}oisson(\lambda_i)} With latent variables \eqn{\phi(\lambda_i)}, \eqn{\phi} being the log link function: \deqn{\phi(\lambda_i) = X_i \beta + W_i b_i + \varepsilon_i} Where each group \eqn{i} have \eqn{k_i} observations. Where the random effects: \deqn{b_i \sim \mathcal{N}_q(0,V_b)} And the over-dispersion terms: \deqn{\varepsilon_i \sim \mathcal{N}(0, \sigma^2 I_{k_i})} We assume standard, conjugate priors: \deqn{\beta \sim \mathcal{N}_p(\mu_{\beta},V_{\beta})} And: \deqn{\sigma^{2} \sim \mathcal{IG}amma(\nu, 1/\delta)} And: \deqn{V_b \sim \mathcal{IW}ishart(r, rR)} See Chib and Carlin (1999) for more details. \emph{NOTE:} We do not provide default parameters for the priors on the precision matrix for the random effects. When fitting one of these models, it is of utmost importance to choose a prior that reflects your prior beliefs about the random effects. Using the \code{dwish} and \code{rwish} functions might be useful in choosing these values. } \examples{ \dontrun{ #======================================== # Hierarchical Poisson Linear Regression #======================================== #== Generating data # Constants nobs <- 1000 nspecies <- 20 species <- c(1:nspecies,sample(c(1:nspecies),(nobs-nspecies),replace=TRUE)) # Covariates X1 <- runif(n=nobs,min=-1,max=1) X2 <- runif(n=nobs,min=-1,max=1) X <- cbind(rep(1,nobs),X1,X2) W <- X # Target parameters # beta beta.target <- matrix(c(0.1,0.1,0.1),ncol=1) # Vb Vb.target <- c(0.05,0.05,0.05) # b b.target <- cbind(rnorm(nspecies,mean=0,sd=sqrt(Vb.target[1])), rnorm(nspecies,mean=0,sd=sqrt(Vb.target[2])), rnorm(nspecies,mean=0,sd=sqrt(Vb.target[3]))) # Response lambda <- vector() Y <- vector() for (n in 1:nobs) { lambda[n] <- exp(X[n,]\%*\%beta.target+W[n,]\%*\%b.target[species[n],]) Y[n] <- rpois(1,lambda[n]) } # Data-set Data <- as.data.frame(cbind(Y,lambda,X1,X2,species)) plot(Data$X1,Data$lambda) #== Call to MCMChpoisson model <- MCMChpoisson(fixed=Y~X1+X2, random=~X1+X2, group="species", data=Data, burnin=5000, mcmc=1000, thin=1,verbose=1, seed=NA, beta.start=0, sigma2.start=1, Vb.start=1, mubeta=0, Vbeta=1.0E6, r=3, R=diag(c(0.1,0.1,0.1)), nu=0.001, delta=0.001, FixOD=1) #== MCMC analysis # Graphics pdf("Posteriors-MCMChpoisson.pdf") plot(model$mcmc) dev.off() # Summary summary(model$mcmc) # Predictive posterior mean for each observation model$lambda.pred # Predicted-Observed plot(Data$lambda,model$lambda.pred) abline(a=0,b=1) ## #Not run ## #You can also compare with lme4 results ## #== lme4 resolution ## library(lme4) ## model.lme4 <- lmer(Y~X1+X2+(1+X1+X2|species),data=Data,family="poisson") ## summary(model.lme4) ## plot(fitted(model.lme4),model$lambda.pred,main="MCMChpoisson/lme4") ## abline(a=0,b=1) } } \references{ Siddhartha Chib and Bradley P. Carlin. 1999. ``On MCMC Sampling in Hierarchical Longitudinal Models.'' \emph{Statistics and Computing.} 9: 17-26. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Andrew D. Martin and Kyle L. Saunders. 2002. ``Bayesian Inference for Political Science Panel Data.'' Paper presented at the 2002 Annual Meeting of the American Political Science Association. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. } \seealso{ \code{\link[coda]{plot.mcmc}}, \code{\link[coda]{summary.mcmc}} } \author{ Ghislain Vieilledent } \keyword{MCMC} \keyword{Poisson} \keyword{bayesian} \keyword{glmm} \keyword{hierarchical} \keyword{mixed} \keyword{models} MCMCpack/man/make.breaklist.Rd0000644000176200001440000000232113564573453015603 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/make.breaklist.R \name{make.breaklist} \alias{make.breaklist} \title{Vector of break numbers} \usage{ make.breaklist(BF, threshold = 3) } \arguments{ \item{BF}{output of \code{testpanelSubjectBreak}.} \item{threshold}{The Bayes Factor threshold to pick the best model. If a Bayes factor of two models is smaller than \code{threshold}, the model with a smaller number of break is chosen to avoid the over-identification problem. Users can change threshold into any positive number. The default value of 3 is chosen as it indicates the existence of "substantial evidence" in favor of the model in the numerator according to Jeffreys' scale.} } \value{ Vector fo break numbers. } \description{ This function generates a vector of break numbers using the output of \code{testpanelSubjectBreak}. The function performs a pairwise comparison of models using Bayes Factors. } \references{ Jong Hee Park, 2011. ``A Unified Method for Dynamic and Cross-Sectional Heterogeneity: Introducing Hidden Markov Panel Models." Working Paper. Harold Jeffreys, 1961. The Theory of Probability. Oxford University Press. } \seealso{ \code{\link{testpanelSubjectBreak}} } MCMCpack/man/MCbinomialbeta.Rd0000644000176200001440000000326613564573453015566 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCmodels.R \name{MCbinomialbeta} \alias{MCbinomialbeta} \title{Monte Carlo Simulation from a Binomial Likelihood with a Beta Prior} \usage{ MCbinomialbeta(y, n, alpha = 1, beta = 1, mc = 1000, ...) } \arguments{ \item{y}{The number of successes in the independent Bernoulli trials.} \item{n}{The number of independent Bernoulli trials.} \item{alpha}{Beta prior distribution alpha parameter.} \item{beta}{Beta prior distribution beta parameter.} \item{mc}{The number of Monte Carlo draws to make.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a binomial likelihood with a Beta prior. } \details{ \code{MCbinomialbeta} directly simulates from the posterior distribution. This model is designed primarily for instructional use. \eqn{\pi} is the probability of success for each independent Bernoulli trial. We assume a conjugate Beta prior: \deqn{\pi \sim \mathcal{B}eta(\alpha, \beta)} \eqn{y} is the number of successes in \eqn{n} trials. By default, a uniform prior is used. } \examples{ \dontrun{ posterior <- MCbinomialbeta(3,12,mc=5000) summary(posterior) plot(posterior) grid <- seq(0,1,0.01) plot(grid, dbeta(grid, 1, 1), type="l", col="red", lwd=3, ylim=c(0,3.6), xlab="pi", ylab="density") lines(density(posterior), col="blue", lwd=3) legend(.75, 3.6, c("prior", "posterior"), lwd=3, col=c("red", "blue")) } } \seealso{ \code{\link[coda]{plot.mcmc}}, \code{\link[coda]{summary.mcmc}} } \keyword{models} MCMCpack/man/MCMChierEI.Rd0000644000176200001440000001472113564573453014523 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMChierEI.R \name{MCMChierEI} \alias{MCMChierEI} \title{Markov Chain Monte Carlo for Wakefield's Hierarchial Ecological Inference Model} \usage{ MCMChierEI(r0, r1, c0, c1, burnin = 5000, mcmc = 50000, thin = 1, verbose = 0, seed = NA, m0 = 0, M0 = 2.287656, m1 = 0, M1 = 2.287656, a0 = 0.825, b0 = 0.0105, a1 = 0.825, b1 = 0.0105, ...) } \arguments{ \item{r0}{\eqn{(ntables \times 1)} vector of row sums from row 0.} \item{r1}{\eqn{(ntables \times 1)} vector of row sums from row 1.} \item{c0}{\eqn{(ntables \times 1)} vector of column sums from column 0.} \item{c1}{\eqn{(ntables \times 1)} vector of column sums from column 1.} \item{burnin}{The number of burn-in scans for the sampler.} \item{mcmc}{The number of mcmc scans to be saved.} \item{thin}{The thinning interval used in the simulation. The number of mcmc iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 then every \code{verbose}th iteration will be printed to the screen.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{m0}{Prior mean of the \eqn{\mu_0} parameter.} \item{M0}{Prior variance of the \eqn{\mu_0} parameter.} \item{m1}{Prior mean of the \eqn{\mu_1} parameter.} \item{M1}{Prior variance of the \eqn{\mu_1} parameter.} \item{a0}{\code{a0/2} is the shape parameter for the inverse-gamma prior on the \eqn{\sigma^2_0} parameter.} \item{b0}{\code{b0/2} is the scale parameter for the inverse-gamma prior on the \eqn{\sigma^2_0} parameter.} \item{a1}{\code{a1/2} is the shape parameter for the inverse-gamma prior on the \eqn{\sigma^2_1} parameter.} \item{b1}{\code{b1/2} is the scale parameter for the inverse-gamma prior on the \eqn{\sigma^2_1} parameter.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the sample from the posterior distribution. This object can be summarized by functions provided by the coda package. } \description{ `MCMChierEI' is used to fit Wakefield's hierarchical ecological inference model for partially observed 2 x 2 contingency tables. } \details{ Consider the following partially observed 2 by 2 contingency table for unit \eqn{t} where \eqn{t=1,\ldots,ntables}: \tabular{llll}{ \tab | \eqn{Y=0} \tab | \eqn{Y=1} \tab | \cr --------- \tab ------------ \tab ------------ \tab ------------ \cr \eqn{X=0} \tab | \eqn{Y_{0t}} \tab | \tab | \eqn{r_{0t}} \cr --------- \tab ------------ \tab ------------ \tab ------------ \cr \eqn{X=1} \tab | \eqn{Y_{1t}} \tab | \tab | \eqn{r_{1t}} \cr --------- \tab ------------ \tab ------------ \tab ------------ \cr \tab | \eqn{c_{0t}} \tab | \eqn{c_{1t}} \tab | \eqn{N_t} } Where \eqn{r_{0t}}, \eqn{r_{1t}}, \eqn{c_{0t}}, \eqn{c_{1t}}, and \eqn{N_t} are non-negative integers that are observed. The interior cell entries are not observed. It is assumed that \eqn{Y_{0t}|r_{0t} \sim \mathcal{B}inomial(r_{0t}, p_{0t})} and \eqn{Y_{1t}|r_{1t} \sim \mathcal{B}inomial(r_{1t}, p_{1t})}. Let \eqn{\theta_{0t} = log(p_{0t}/(1-p_{0t}))}, and \eqn{\theta_{1t} = log(p_{1t}/(1-p_{1t}))}. The following prior distributions are assumed: \eqn{\theta_{0t} \sim \mathcal{N}(\mu_0, \sigma^2_0)}, \eqn{\theta_{1t} \sim \mathcal{N}(\mu_1, \sigma^2_1)}. \eqn{\theta_{0t}} is assumed to be a priori independent of \eqn{\theta_{1t}} for all t. In addition, we assume the following hyperpriors: \eqn{\mu_0 \sim \mathcal{N}(m_0, M_0)}, \eqn{\mu_1 \sim \mathcal{N}(m_1, M_1)}, \eqn{\sigma^2_0 \sim \mathcal{IG}(a_0/2, b_0/2)}, and \eqn{\sigma^2_1 \sim \mathcal{IG}(a_1/2, b_1/2)}. The default priors have been chosen to make the implied prior distribution for \eqn{p_{0}} and \eqn{p_{1}} \emph{approximately} uniform on (0,1). Inference centers on \eqn{p_0}, \eqn{p_1}, \eqn{\mu_0}, \eqn{\mu_1}, \eqn{\sigma^2_0}, and \eqn{\sigma^2_1}. Univariate slice sampling (Neal, 2003) along with Gibbs sampling is used to sample from the posterior distribution. See Section 5.4 of Wakefield (2003) for discussion of the priors used here. \code{MCMChierEI} departs from the Wakefield model in that the \code{mu0} and \code{mu1} are here assumed to be drawn from independent normal distributions whereas Wakefield assumes they are drawn from logistic distributions. } \examples{ \dontrun{ ## simulated data example set.seed(3920) n <- 100 r0 <- round(runif(n, 400, 1500)) r1 <- round(runif(n, 100, 4000)) p0.true <- pnorm(rnorm(n, m=0.5, s=0.25)) p1.true <- pnorm(rnorm(n, m=0.0, s=0.10)) y0 <- rbinom(n, r0, p0.true) y1 <- rbinom(n, r1, p1.true) c0 <- y0 + y1 c1 <- (r0+r1) - c0 ## plot data tomogplot(r0, r1, c0, c1) ## fit exchangeable hierarchical model post <- MCMChierEI(r0,r1,c0,c1, mcmc=40000, thin=5, verbose=100, seed=list(NA, 1)) p0meanHier <- colMeans(post)[1:n] p1meanHier <- colMeans(post)[(n+1):(2*n)] ## plot truth and posterior means pairs(cbind(p0.true, p0meanHier, p1.true, p1meanHier)) } } \references{ Jonathan C. Wakefield. 2004. ``Ecological Inference for 2 x 2 Tables.'' \emph{Journal of the Royal Statistical Society, Series A}. 167(3): 385445. Radford Neal. 2003. ``Slice Sampling" (with discussion). \emph{Annals of Statistics}, 31: 705-767. Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. } \seealso{ \code{\link{MCMCdynamicEI}}, \code{\link[coda]{plot.mcmc}},\code{\link[coda]{summary.mcmc}} } \keyword{models} MCMCpack/man/MCMCmetrop1R.Rd0000644000176200001440000002212213564573453015061 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCmetrop1R.R \name{MCMCmetrop1R} \alias{MCMCmetrop1R} \title{Metropolis Sampling from User-Written R function} \usage{ MCMCmetrop1R(fun, theta.init, burnin = 500, mcmc = 20000, thin = 1, tune = 1, verbose = 0, seed = NA, logfun = TRUE, force.samp = FALSE, V = NULL, optim.method = "BFGS", optim.lower = -Inf, optim.upper = Inf, optim.control = list(fnscale = -1, trace = 0, REPORT = 10, maxit = 500), ...) } \arguments{ \item{fun}{The unnormalized (log)density of the distribution from which to take a sample. This must be a function defined in R whose first argument is a continuous (possibly vector) variable. This first argument is the point in the state space at which the (log)density is to be evaluated. Additional arguments can be passed to \code{fun()} by inserting them in the call to \code{MCMCmetrop1R()}. See the Details section and the examples below for more information.} \item{theta.init}{Starting values for the sampling. Must be of the appropriate dimension. It must also be the case that \code{fun(theta.init, ...)} is greater than \code{-Inf} if \code{fun()} is a logdensity or greater than 0 if \code{fun()} is a density.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of MCMC iterations after burnin.} \item{thin}{The thinning interval used in the simulation. The number of MCMC iterations must be divisible by this value.} \item{tune}{The tuning parameter for the Metropolis sampling. Can be either a positive scalar or a \eqn{k}-vector, where \eqn{k} is the length of \eqn{\theta}.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the \eqn{\theta} vector, the function value, and the Metropolis acceptance rate are sent to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{logfun}{Logical indicating whether \code{fun} returns the natural log of a density function (TRUE) or a density (FALSE).} \item{force.samp}{Logical indicating whether the sampling should proceed if the Hessian calculated from the initial call to \code{optim} routine to maximize the (log)density is not negative definite. If \code{force.samp==TRUE} and the Hessian from \code{optim} is non-negative definite, the Hessian is rescaled by subtracting small values from it's main diagonal until it is negative definite. Sampling proceeds using this rescaled Hessian in place of the original Hessian from \code{optim}. By default, if \code{force.samp==FALSE} and the Hessian from \code{optim} is non-negative definite, an error message is printed and the call to \code{MCMCmetrop1R} is terminated. \emph{Please note that a non-negative Hessian at the mode is often an indication that the function of interest is not a proper density. Thus, \code{force.samp} should only be set equal to \code{TRUE} with great caution.}} \item{V}{The variance-covariance matrix for the Gaussian proposal distribution. Must be a square matrix or \code{NULL}. If a square matrix, \code{V} must have dimension equal to the length of \code{theta.init}. If \code{NULL}, \code{V} is calculated from \code{tune} and an initial call to \code{optim}. See the Details section below for more information. Unless the log-posterior is expensive to compute it will typically be best to use the default \code{V = NULL}.} \item{optim.method}{The value of the \code{method} parameter sent to \code{optim} during an initial maximization of \code{fun}. See \code{optim} for more details.} \item{optim.lower}{The value of the \code{lower} parameter sent to \code{optim} during an initial maximization of \code{fun}. See \code{optim} for more details.} \item{optim.upper}{The value of the \code{upper} parameter sent to \code{optim} during an initial maximization of \code{fun}. See \code{optim} for more details.} \item{optim.control}{The value of the \code{control} parameter sent to \code{optim} during an initial maximization of \code{fun}. See \code{optim} for more details.} \item{\dots}{Additional arguments.} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function allows a user to construct a sample from a user-defined continuous distribution using a random walk Metropolis algorithm. } \details{ MCMCmetrop1R produces a sample from a user-defined distribution using a random walk Metropolis algorithm with multivariate normal proposal distribution. See Gelman et al. (2003) and Robert & Casella (2004) for details of the random walk Metropolis algorithm. The proposal distribution is centered at the current value of \eqn{\theta} and has variance-covariance \eqn{V}. If \eqn{V} is specified by the user to be \code{NULL} then \eqn{V} is calculated as: \eqn{V = T (-1\cdot H)^{-1} T }, where \eqn{T} is a the diagonal positive definite matrix formed from the \code{tune} and \eqn{H} is the approximate Hessian of \code{fun} evaluated at its mode. This last calculation is done via an initial call to \code{optim}. } \examples{ \dontrun{ ## logistic regression with an improper uniform prior ## X and y are passed as args to MCMCmetrop1R logitfun <- function(beta, y, X){ eta <- X \%*\% beta p <- 1.0/(1.0+exp(-eta)) sum( y * log(p) + (1-y)*log(1-p) ) } x1 <- rnorm(1000) x2 <- rnorm(1000) Xdata <- cbind(1,x1,x2) p <- exp(.5 - x1 + x2)/(1+exp(.5 - x1 + x2)) yvector <- rbinom(1000, 1, p) post.samp <- MCMCmetrop1R(logitfun, theta.init=c(0,0,0), X=Xdata, y=yvector, thin=1, mcmc=40000, burnin=500, tune=c(1.5, 1.5, 1.5), verbose=500, logfun=TRUE) raftery.diag(post.samp) plot(post.samp) summary(post.samp) ## ################################################## ## negative binomial regression with an improper unform prior ## X and y are passed as args to MCMCmetrop1R negbinfun <- function(theta, y, X){ k <- length(theta) beta <- theta[1:(k-1)] alpha <- exp(theta[k]) mu <- exp(X \%*\% beta) log.like <- sum( lgamma(y+alpha) - lfactorial(y) - lgamma(alpha) + alpha * log(alpha/(alpha+mu)) + y * log(mu/(alpha+mu)) ) } n <- 1000 x1 <- rnorm(n) x2 <- rnorm(n) XX <- cbind(1,x1,x2) mu <- exp(1.5+x1+2*x2)*rgamma(n,1) yy <- rpois(n, mu) post.samp <- MCMCmetrop1R(negbinfun, theta.init=c(0,0,0,0), y=yy, X=XX, thin=1, mcmc=35000, burnin=1000, tune=1.5, verbose=500, logfun=TRUE, seed=list(NA,1)) raftery.diag(post.samp) plot(post.samp) summary(post.samp) ## ################################################## ## sample from a univariate normal distribution with ## mean 5 and standard deviation 0.1 ## ## (MCMC obviously not necessary here and this should ## really be done with the logdensity for better ## numerical accuracy-- this is just an illustration of how ## MCMCmetrop1R works with a density rather than logdensity) post.samp <- MCMCmetrop1R(dnorm, theta.init=5.3, mean=5, sd=0.1, thin=1, mcmc=50000, burnin=500, tune=2.0, verbose=5000, logfun=FALSE) summary(post.samp) } } \references{ Siddhartha Chib; Edward Greenberg. 1995. ``Understanding the Metropolis-Hastings Algorithm." \emph{The American Statistician}, 49, 327-335. Andrew Gelman, John B. Carlin, Hal S. Stern, and Donald B. Rubin. 2003. \emph{Bayesian Data Analysis}. 2nd Edition. Boca Raton: Chapman & Hall/CRC. Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. Christian P. Robert and George Casella. 2004. \emph{Monte Carlo Statistical Methods}. 2nd Edition. New York: Springer. } \seealso{ \code{\link[coda]{plot.mcmc}}, \code{\link[coda]{summary.mcmc}}, \code{\link[stats]{optim}}, \code{\link[mcmc]{metrop}} } \keyword{models} MCMCpack/man/HDPHMMnegbin.Rd0000644000176200001440000002205513564573453015055 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/HDPHMMnegbin.R \name{HDPHMMnegbin} \alias{HDPHMMnegbin} \title{Markov Chain Monte Carlo for sticky HDP-HMM with a Negative Binomial outcome distribution} \usage{ HDPHMMnegbin(formula, data = parent.frame(), K = 10, b0 = 0, B0 = 1, a.theta = 50, b.theta = 5, a.alpha = 1, b.alpha = 0.1, a.gamma = 1, b.gamma = 0.1, e = 2, f = 2, g = 10, burnin = 1000, mcmc = 1000, thin = 1, verbose = 0, seed = NA, beta.start = NA, P.start = NA, rho.start = NA, rho.step, nu.start = NA, gamma.start = 0.5, theta.start = 0.98, ak.start = 100, ...) } \arguments{ \item{formula}{Model formula.} \item{data}{Data frame.} \item{K}{The number of regimes under consideration. This should be larger than the hypothesized number of regimes in the data. Note that the sampler will likely visit fewer than \code{K} regimes.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of beta. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{a.theta, b.theta}{Paramaters for the Beta prior on \eqn{\theta}, which captures the strength of the self-transition bias.} \item{a.alpha, b.alpha}{Shape and scale parameters for the Gamma distribution on \eqn{\alpha + \kappa}.} \item{a.gamma, b.gamma}{Shape and scale parameters for the Gamma distribution on \eqn{\gamma}.} \item{e}{The hyperprior for the distribution \eqn{\rho} See details.} \item{f}{The hyperprior for the distribution \eqn{\rho}. See details.} \item{g}{The hyperprior for the distribution \eqn{\rho}. See details.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of Metropolis iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of mcmc iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the current beta vector, and the Metropolis acceptance rate are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{beta.start}{The starting value for the \eqn{\beta} vector. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the starting value for all of the betas. The default value of NA will use the maximum likelihood estimate of \eqn{\beta} as the starting value for all regimes.} \item{P.start}{Initial transition matrix between regimes. Should be a \code{K} by \code{K} matrix. If not provided, the default value will be place \code{theta.start} along the diagonal and the rest of the mass even distributed within rows.} \item{rho.start}{The starting value for the \eqn{\rho} variable. This can either be a scalar or a column vector with dimension equal to the number of regimes. If the value is scalar, it will be used for all regimes. The default value is a vector of ones.} \item{rho.step}{Tuning parameter for the slice sampling approach to sampling \eqn{rho}. Determines the size of the step-out used to find the correct slice to draw from. Lower values are more accurate, but will take longer (up to a fixed searching limit). Default is 0.1.} \item{nu.start}{The starting values for the random effect, \eqn{\nu}. The default value is a vector of ones.} \item{theta.start, ak.start, gamma.start}{Scalar starting values for the \eqn{\theta}, \eqn{\alpha + \kappa}, and \eqn{\gamma} parameters.} \item{...}{further arguments to be passed.} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a (sticky) HDP-HMM with a Negative Binomial outcome distribution (Fox et al, 2011). The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{HDPHMMnegbin} simulates from the posterior distribution of a sticky HDP-HMM with a Negative Binomial outcome distribution, allowing for multiple, arbitrary changepoints in the model. The details of the model are discussed in Blackwell (2017). The implementation here is based on a weak-limit approximation, where there is a large, though finite number of regimes that can be switched between. Unlike other changepoint models in \code{MCMCpack}, the HDP-HMM approach allows for the state sequence to return to previous visited states. The model takes the following form, where we show the fixed-limit version: \deqn{y_t \sim \mathcal{P}oisson(\nu_t\mu_t)} \deqn{\mu_t = x_t ' \beta_m,\;\; m = 1, \ldots, M} \deqn{\nu_t \sim \mathcal{G}amma(\rho_m, \rho_m)} Where \eqn{M} is an upper bound on the number of states and \eqn{\beta_m} and \eqn{\rho_m} are parameters when a state is \eqn{m} at \eqn{t}. The transition probabilities between states are assumed to follow a heirarchical Dirichlet process: \deqn{\pi_m \sim \mathcal{D}irichlet(\alpha\delta_1, \ldots, \alpha\delta_j + \kappa, \ldots, \alpha\delta_M)} \deqn{\delta \sim \mathcal{D}irichlet(\gamma/M, \ldots, \gamma/M)} The \eqn{\kappa} value here is the sticky parameter that encourages self-transitions. The sampler follows Fox et al (2011) and parameterizes these priors with \eqn{\alpha + \kappa} and \eqn{\theta = \kappa/(\alpha + \kappa)}, with the latter representing the degree of self-transition bias. Gamma priors are assumed for \eqn{(\alpha + \kappa)} and \eqn{\gamma}. We assume Gaussian distribution for prior of \eqn{\beta}: \deqn{\beta_m \sim \mathcal{N}(b_0,B_0^{-1}),\;\; m = 1, \ldots, M} The overdispersion parameters have a prior with the following form: \deqn{f(\rho_m|e,f,g) \propto \rho^{e-1}(\rho + g)^{-(e+f)}} The model is simulated via blocked Gibbs conditonal on the states. The \eqn{\beta} being simulated via the auxiliary mixture sampling method of Fuerhwirth-Schanetter et al. (2009). The \eqn{\rho} is updated via slice sampling. The \eqn{\nu_i} are updated their (conjugate) full conditional, which is also Gamma. The states are updated as in Fox et al (2011), supplemental materials. } \examples{ \dontrun{ n <- 150 reg <- 3 true.s <- gl(reg, n/reg, n) rho.true <- c(1.5, 0.5, 3) b1.true <- c(1, -2, 2) x1 <- runif(n, 0, 2) nu.true <- rgamma(n, rho.true[true.s], rho.true[true.s]) mu <- nu.true * exp(1 + x1 * b1.true[true.s]) y <- rpois(n, mu) posterior <- HDPHMMnegbin(y ~ x1, K = 10, verbose = 1000, e = 2, f = 2, g = 10, a.theta = 100, b.theta = 1, b0 = rep(0, 2), B0 = (1/9) * diag(2), rho.step = rep(0.75, times = 10), seed = list(NA, 2), theta.start = 0.95, gamma.start = 10, ak.start = 10) plotHDPChangepoint(posterior, ylab="Density", start=1) } } \references{ Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Sylvia Fruehwirth-Schnatter, Rudolf Fruehwirth, Leonhard Held, and Havard Rue. 2009. ``Improved auxiliary mixture sampling for hierarchical models of non-Gaussian data'', \emph{Statistics and Computing} 19(4): 479-492. \url{http://doi.org/10.1007/s11222-008-9109-4} Matthew Blackwell. 2017. ``Game Changers: Detecting Shifts in Overdispersed Count Data,'' \emph{Political Analysis} Forthcoming. \url{http://www.mattblackwell.org/files/papers/gamechangers-letter.pdf} Emily B. Fox, Erik B. Sudderth, Michael I. Jordan, and Alan S. Willsky. 2011.. ``A sticky HDP-HMM with application to speaker diarization.'' \emph{The Annals of Applied Statistics}, 5(2A), 1020-1056. \url{http://doi.org/10.1214/10-AOAS395SUPP} } \seealso{ \code{\link{MCMCnegbinChange}}, \code{\link{HDPHMMpoisson}} } \keyword{models} MCMCpack/man/HDPHMMpoisson.Rd0000644000176200001440000001714113564573453015305 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/HDPHMMpoisson.R \name{HDPHMMpoisson} \alias{HDPHMMpoisson} \title{Markov Chain Monte Carlo for sticky HDP-HMM with a Poisson outcome distribution} \usage{ HDPHMMpoisson(formula, data = parent.frame(), K = 10, b0 = 0, B0 = 1, a.alpha = 1, b.alpha = 0.1, a.gamma = 1, b.gamma = 0.1, a.theta = 50, b.theta = 5, burnin = 1000, mcmc = 1000, thin = 1, verbose = 0, seed = NA, beta.start = NA, P.start = NA, gamma.start = 0.5, theta.start = 0.98, ak.start = 100, ...) } \arguments{ \item{formula}{Model formula.} \item{data}{Data frame.} \item{K}{The number of regimes under consideration. This should be larger than the hypothesized number of regimes in the data. Note that the sampler will likely visit fewer than \code{K} regimes.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of beta. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{a.alpha, b.alpha}{Shape and scale parameters for the Gamma distribution on \eqn{\alpha + \kappa}.} \item{a.gamma, b.gamma}{Shape and scale parameters for the Gamma distribution on \eqn{\gamma}.} \item{a.theta, b.theta}{Paramaters for the Beta prior on \eqn{\theta}, which captures the strength of the self-transition bias.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of Metropolis iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of mcmc iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the current beta vector, and the Metropolis acceptance rate are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{beta.start}{The starting value for the \eqn{\beta} vector. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the starting value for all of the betas. The default value of NA will use the maximum likelihood estimate of \eqn{\beta} as the starting value for all regimes.} \item{P.start}{Initial transition matrix between regimes. Should be a \code{K} by \code{K} matrix. If not provided, the default value will be place \code{theta.start} along the diagonal and the rest of the mass even distributed within rows.} \item{theta.start, ak.start, gamma.start}{Scalar starting values for the \eqn{\theta}, \eqn{\alpha + \kappa}, and \eqn{\gamma} parameters.} \item{...}{further arguments to be passed.} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a (sticky) HDP-HMM with a Poisson outcome distribution (Fox et al, 2011). The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{HDPHMMpoisson} simulates from the posterior distribution of a sticky HDP-HMM with a Poisson outcome distribution, allowing for multiple, arbitrary changepoints in the model. The details of the model are discussed in Blackwell (2017). The implementation here is based on a weak-limit approximation, where there is a large, though finite number of regimes that can be switched between. Unlike other changepoint models in \code{MCMCpack}, the HDP-HMM approach allows for the state sequence to return to previous visited states. The model takes the following form, where we show the fixed-limit version: \deqn{y_t \sim \mathcal{P}oisson(\mu_t)} \deqn{\mu_t = x_t ' \beta_m,\;\; m = 1, \ldots, M} Where \eqn{M} is an upper bound on the number of states and \eqn{\beta_m} are parameters when a state is \eqn{m} at \eqn{t}. The transition probabilities between states are assumed to follow a heirarchical Dirichlet process: \deqn{\pi_m \sim \mathcal{D}irichlet(\alpha\delta_1, \ldots, \alpha\delta_j + \kappa, \ldots, \alpha\delta_M)} \deqn{\delta \sim \mathcal{D}irichlet(\gamma/M, \ldots, \gamma/M)} The \eqn{\kappa} value here is the sticky parameter that encourages self-transitions. The sampler follows Fox et al (2011) and parameterizes these priors with \eqn{\alpha + \kappa} and \eqn{\theta = \kappa/(\alpha + \kappa)}, with the latter representing the degree of self-transition bias. Gamma priors are assumed for \eqn{(\alpha + \kappa)} and \eqn{\gamma}. We assume Gaussian distribution for prior of \eqn{\beta}: \deqn{\beta_m \sim \mathcal{N}(b_0,B_0^{-1}),\;\; m = 1, \ldots, M} The model is simulated via blocked Gibbs conditonal on the states. The \eqn{\beta} being simulated via the auxiliary mixture sampling method of Fuerhwirth-Schanetter et al. (2009). The states are updated as in Fox et al (2011), supplemental materials. } \examples{ \dontrun{ n <- 150 reg <- 3 true.s <- gl(reg, n/reg, n) b1.true <- c(1, -2, 2) x1 <- runif(n, 0, 2) mu <- exp(1 + x1 * b1.true[true.s]) y <- rpois(n, mu) posterior <- HDPHMMpoisson(y ~ x1, K = 10, verbose = 1000, a.theta = 100, b.theta = 1, b0 = rep(0, 2), B0 = (1/9) * diag(2), seed = list(NA, 2), theta.start = 0.95, gamma.start = 10, ak.start = 10) plotHDPChangepoint(posterior, ylab="Density", start=1) } } \references{ Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Sylvia Fruehwirth-Schnatter, Rudolf Fruehwirth, Leonhard Held, and Havard Rue. 2009. ``Improved auxiliary mixture sampling for hierarchical models of non-Gaussian data'', \emph{Statistics and Computing} 19(4): 479-492. \url{http://doi.org/10.1007/s11222-008-9109-4} Matthew Blackwell. 2017. ``Game Changers: Detecting Shifts in Overdispersed Count Data,'' \emph{Political Analysis} Forthcoming. \url{http://www.mattblackwell.org/files/papers/gamechangers-letter.pdf} Emily B. Fox, Erik B. Sudderth, Michael I. Jordan, and Alan S. Willsky. 2011.. ``A sticky HDP-HMM with application to speaker diarization.'' \emph{The Annals of Applied Statistics}, 5(2A), 1020-1056. \url{http://doi.org/10.1214/10-AOAS395SUPP} } \seealso{ \code{\link{MCMCpoissonChange}}, \code{\link{HDPHMMnegbin}} } \keyword{models} MCMCpack/man/BayesFactor.Rd0000644000176200001440000000470113564573453015115 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/BayesFactors.R \name{BayesFactor} \alias{BayesFactor} \alias{is.BayesFactor} \title{Create an object of class BayesFactor from MCMCpack output} \usage{ BayesFactor(...) is.BayesFactor(BF) } \arguments{ \item{...}{MCMCpack output objects. These have to be of class \code{mcmc} and have a \code{logmarglike} attribute. In what follows, we let \code{M} denote the total number of models to be compared.} \item{BF}{An object to be checked for membership in class \code{BayesFactor}.} } \value{ An object of class \code{BayesFactor}. A \code{BayesFactor} object has four attributes. They are: \code{BF.mat} an \eqn{M \times M} matrix in which element \eqn{i,j} contains the Bayes factor for model \eqn{i} relative to model \eqn{j}; \code{BF.log.mat} an \eqn{M \times M} matrix in which element \eqn{i,j} contains the natural log of the Bayes factor for model \eqn{i} relative to model \eqn{j}; \code{BF.logmarglike} an \eqn{M} vector containing the log marginal likelihoods for models 1 through \eqn{M}; and \code{BF.call} an \eqn{M} element list containing the calls used to fit models 1 through \eqn{M}. } \description{ This function creates an object of class \code{BayesFactor} from MCMCpack output. } \examples{ \dontrun{ data(birthwt) model1 <- MCMCregress(bwt~age+lwt+as.factor(race) + smoke + ht, data=birthwt, b0=c(2700, 0, 0, -500, -500, -500, -500), B0=c(1e-6, .01, .01, 1.6e-5, 1.6e-5, 1.6e-5, 1.6e-5), c0=10, d0=4500000, marginal.likelihood="Chib95", mcmc=10000) model2 <- MCMCregress(bwt~age+lwt+as.factor(race) + smoke, data=birthwt, b0=c(2700, 0, 0, -500, -500, -500), B0=c(1e-6, .01, .01, 1.6e-5, 1.6e-5, 1.6e-5), c0=10, d0=4500000, marginal.likelihood="Chib95", mcmc=10000) model3 <- MCMCregress(bwt~as.factor(race) + smoke + ht, data=birthwt, b0=c(2700, -500, -500, -500, -500), B0=c(1e-6, 1.6e-5, 1.6e-5, 1.6e-5, 1.6e-5), c0=10, d0=4500000, marginal.likelihood="Chib95", mcmc=10000) BF <- BayesFactor(model1, model2, model3) print(BF) } } \seealso{ \code{\link{MCMCregress}} } \keyword{models} MCMCpack/man/xpnd.Rd0000644000176200001440000000205513564573453013664 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/utility.R \name{xpnd} \alias{xpnd} \title{Expand a Vector into a Symmetric Matrix} \usage{ xpnd(x, nrow = NULL) } \arguments{ \item{x}{A list of elements to expand into symmetric matrix.} \item{nrow}{The number of rows (and columns) in the returned matrix. Look into the details.} } \value{ An \eqn{(nrows \times nrows)} symmetric matrix. } \description{ This function takes a vector of appropriate length (typically created using \code{vech}) and creates a symmetric matrix. } \details{ This function is particularly useful when dealing with variance covariance matrices. Note that R stores matrices in column major order, and that the items in \code{x} will be recycled to fill the matrix if need be. The number of rows can be specified or automatically computed from the number of elements in a given object via \eqn{(-1 + \sqrt{(1 + 8 * length(x))}) / 2}. } \examples{ xpnd(c(1,2,3,4,4,5,6,7,8,9),4) xpnd(c(1,2,3,4,4,5,6,7,8,9)) } \seealso{ \code{\link{vech}} } \keyword{manip} MCMCpack/man/topmodels.Rd0000644000176200001440000000252313564573453014721 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/SSVSquantregsummary.R \name{topmodels} \alias{topmodels} \title{Shows an ordered list of the most frequently visited models sampled during quantile regression stochastic search variable selection (QR-SSVS).} \usage{ topmodels(qrssvs, nmodels = 5, abbreviate = FALSE, minlength = 3) } \arguments{ \item{qrssvs}{An object of class \code{qrssvs}. Typically this will be the \code{gamma} component of the list returned by \code{SSVSquantreg}.} \item{nmodels}{The number of models to tabulate.} \item{abbreviate}{Logical: should the names of the predictors be abbreviated?} \item{minlength}{If \code{abbreviate} is set to \code{TRUE}, the minimum length of the abbreviations.} } \value{ A table with the models and their associated posterior probability. The models are arranged in descending order of probability. } \description{ Given output from quantile regression stochastic search variable selection, this function returns a table of the 'best' models together with their associated empirical posterior probability. } \examples{ \dontrun{ set.seed(1) epsilon<-rnorm(100) set.seed(2) x<-matrix(rnorm(1000),100,10) y<-x[,1]+x[,10]+epsilon qrssvs<-SSVSquantreg(y~x) topmodels(qrssvs$gamma) } } \seealso{ \code{\link[MCMCpack]{SSVSquantreg}} } \author{ Craig Reed } \keyword{models} MCMCpack/man/PErisk.Rd0000644000176200001440000000410313564573453014104 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/data.R \docType{data} \name{PErisk} \alias{PErisk} \title{Political Economic Risk Data from 62 Countries in 1987} \format{A data frame with 62 observations on the following 9 variables. All data points are from 1987. See Quinn (2004) for more details. \describe{ \item{country}{a factor with levels \code{Argentina} through \code{Zimbabwe}} \item{courts}{an ordered factor with levels \code{0} < \code{1}.\code{courts} is an indicator of whether the country in question is judged to have an independent judiciary. From Henisz (2002).} \item{barb2}{a numeric vector giving the natural log of the black market premium in each country. The black market premium is coded as the black market exchange rate (local currency per dollar) divided by the official exchange rate minus 1. From Marshall, Gurr, and Harff (2002). } \item{prsexp2}{an ordered factor with levels \code{0} < \code{1} < \code{2} < \code{3} < \code{4} < \code{5}, giving the lack of expropriation risk. From Marshall, Gurr, and Harff (2002).} \item{prscorr2}{an ordered factor with levels \code{0} < \code{1} < \code{2} < \code{3} < \code{4} < \code{5}, measuring the lack of corruption. From Marshall, Gurr, and Harff (2002).} \item{gdpw2}{a numeric vector giving the natural log of real GDP per worker in 1985 international prices. From Alvarez et al. (1999).} }} \source{ Mike Alvarez, Jose Antonio Cheibub, Fernando Limongi, and Adam Przeworski. 1999. ``ACLP Political and Economic Database.'' \url{https://sites.google.com/site/joseantoniocheibub/datasets/democracy-and-development-aclp}. Witold J. Henisz. 2002. ``The Political Constraint Index (POLCON) Dataset.'' Monty G. Marshall, Ted Robert Gurr, and Barbara Harff. 2002. ``State Failure Task Force Problem Set.'' } \description{ Political Economic Risk Data from 62 Countries in 1987. } \references{ Kevin M. Quinn. 2004. ``Bayesian Factor Analysis for Mixed Ordinal and Continuous Response.'' \emph{Political Analyis}. 12: 338-353. } \keyword{datasets} MCMCpack/man/InvGamma.Rd0000644000176200001440000000241013564573453014405 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/distn.R \name{InvGamma} \alias{InvGamma} \alias{dinvgamma} \alias{rinvgamma} \title{The Inverse Gamma Distribution} \usage{ dinvgamma(x, shape, scale = 1) rinvgamma(n, shape, scale = 1) } \arguments{ \item{x}{Scalar location to evaluate density.} \item{shape}{Scalar shape parameter.} \item{scale}{Scalar scale parameter (default value one).} \item{n}{Number of draws from the distribution.} } \value{ \code{dinvgamma} evaluates the density at \code{x}. \code{rinvgamma} takes \code{n} draws from the inverse Gamma distribution. The parameterization is consistent with the Gamma Distribution in the stats package. } \description{ Density function and random generation from the inverse gamma distribution. } \details{ An inverse gamma random variable with shape \eqn{a} and scale \eqn{b} has mean \eqn{\frac{b}{a-1}} (assuming \eqn{a>1}) and variance \eqn{\frac{b^2}{(a-1)^2(a-2)}} (assuming \eqn{a>2}). } \examples{ density <- dinvgamma(4.2, 1.1) draws <- rinvgamma(10, 3.2) } \references{ Andrew Gelman, John B. Carlin, Hal S. Stern, and Donald B. Rubin. 2004. \emph{Bayesian Data Analysis}. 2nd Edition. Boca Raton: Chapman & Hall. } \seealso{ \code{\link[stats]{GammaDist}} } \keyword{distribution} MCMCpack/man/Wishart.Rd0000644000176200001440000000157013564573453014335 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/distn.R \name{Wishart} \alias{Wishart} \alias{dwish} \alias{rwish} \title{The Wishart Distribution} \usage{ rwish(v, S) dwish(W, v, S) } \arguments{ \item{v}{Degrees of freedom (scalar).} \item{S}{Inverse scale matrix \eqn{(p \times p)}.} \item{W}{Positive definite matrix W \eqn{(p \times p)}.} } \value{ \code{dwish} evaluates the density at positive definite matrix W. \code{rwish} generates one random draw from the distribution. } \description{ Density function and random generation from the Wishart distribution. } \details{ The mean of a Wishart random variable with \code{v} degrees of freedom and inverse scale matrix \code{S} is \eqn{vS}. } \examples{ density <- dwish(matrix(c(2,-.3,-.3,4),2,2), 3, matrix(c(1,.3,.3,1),2,2)) draw <- rwish(3, matrix(c(1,.3,.3,1),2,2)) } \keyword{distribution} MCMCpack/man/procrustes.Rd0000644000176200001440000000223413564573453015123 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/procrust.R \name{procrustes} \alias{procrustes} \title{Procrustes Transformation} \usage{ procrustes(X, Xstar, translation = FALSE, dilation = FALSE) } \arguments{ \item{X}{The matrix to be transformed.} \item{Xstar}{The target matrix.} \item{translation}{logical value indicating whether \code{X} should be translated.} \item{dilation}{logical value indicating whether \code{X} should be dilated.} } \value{ A list containing: \code{X.new} the matrix that is the Procrustes transformed version of \code{X}, \code{R} the rotation matrix, \code{tt} the translation vector, and \code{s} the scale factor. } \description{ This function performs a Procrustes transformation on a matrix \code{X} to minimize the squared distance between \code{X} and another matrix \code{Xstar}. } \details{ \code{R}, \code{tt}, and \code{s} are chosen so that: \deqn{s X R + 1 tt' \approx X^*} \code{X.new} is given by: \deqn{X_{new} = s X R + 1 tt'} } \references{ Borg and Groenen. 1997. \emph{Modern Multidimensional Scaling}. New York: Springer. pp. 340-342. } \seealso{ \code{\link{MCMCirtKd}} } \keyword{manip} MCMCpack/man/MCMCirtHier1d.Rd0000644000176200001440000003233213564573453015207 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCirtHier1d.R \name{MCMCirtHier1d} \alias{MCMCirtHier1d} \title{Markov Chain Monte Carlo for Hierarchical One Dimensional Item Response Theory Model, Covariates Predicting Latent Ideal Point (Ability)} \usage{ MCMCirtHier1d(datamatrix, Xjdata, burnin = 1000, mcmc = 20000, thin = 1, verbose = 0, seed = NA, theta.start = NA, a.start = NA, b.start = NA, beta.start = NA, b0 = 0, B0 = 0.01, c0 = 0.001, d0 = 0.001, ab0 = 0, AB0 = 0.25, store.item = FALSE, store.ability = TRUE, drop.constant.items = TRUE, marginal.likelihood = c("none", "Chib95"), px = TRUE, px_a0 = 10, px_b0 = 10, ...) } \arguments{ \item{datamatrix}{The matrix of data. Must be 0, 1, or missing values. The rows of \code{datamatrix} correspond to subjects and the columns correspond to items.} \item{Xjdata}{A \code{data.frame} containing second-level predictor covariates for ideal points \eqn{\theta}. Predictors are modeled as a linear regression on the mean vector of \eqn{\theta}; the posterior sample contains regression coefficients \eqn{\beta} and common variance \eqn{\sigma^2}. See Rivers (2003) for a thorough discussion of identification of IRT models.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of Gibbs iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of Gibbs iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 then every \code{verbose}th iteration will be printed to the screen.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{theta.start}{The starting values for the subject abilities (ideal points). This can either be a scalar or a column vector with dimension equal to the number of voters. If this takes a scalar value, then that value will serve as the starting value for all of the thetas. The default value of NA will choose the starting values based on an eigenvalue-eigenvector decomposition of the agreement score matrix formed from the \code{datamatrix}.} \item{a.start}{The starting values for the \eqn{a} difficulty parameters. This can either be a scalar or a column vector with dimension equal to the number of items. If this takes a scalar value, then that value will serve as the starting value for all \eqn{a}. The default value of NA will set the starting values based on a series of probit regressions that condition on the starting values of theta.} \item{b.start}{The starting values for the \eqn{b} discrimination parameters. This can either be a scalar or a column vector with dimension equal to the number of items. If this takes a scalar value, then that value will serve as the starting value for all \eqn{b}. The default value of NA will set the starting values based on a series of probit regressions that condition on the starting values of theta.} \item{beta.start}{The starting values for the \eqn{\beta} regression coefficients that predict the means of ideal points \eqn{\theta}. This can either be a scalar or a column vector with length equal to the number of covariates. If this takes a scalar value, then that value will serve as the starting value for all of the betas. The default value of NA will set the starting values based on a linear regression of the covariates on (either provided or generated) \code{theta.start}.} \item{b0}{The prior mean of \eqn{\beta}. Can be either a scalar or a vector of length equal to the number of subject covariates. If a scalar all means with be set to the passed value.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of beta. A default proper but diffuse value of .01 ensures finite marginal likelihood for model comparison. A value of 0 is equivalent to an improper uniform prior for beta.} \item{c0}{\eqn{c_0/2} is the shape parameter for the inverse Gamma prior on \eqn{\sigma^2} (the variance of \eqn{\theta}). The amount of information in the inverse Gamma prior is something like that from \eqn{c_0} pseudo-observations.} \item{d0}{\eqn{d_0/2} is the scale parameter for the inverse Gamma prior on \eqn{\sigma^2} (the variance of \eqn{\theta}). In constructing the inverse Gamma prior, \eqn{d_0} acts like the sum of squared errors from the \eqn{c_0} pseudo-observations.} \item{ab0}{The prior mean of \code{(a, b)}. Can be either a scalar or a 2-vector. If a scalar both means will be set to the passed value. The prior mean is assumed to be the same across all items.} \item{AB0}{The prior precision of \code{(a, b)}.This can either be ascalar or a 2 by 2 matrix. If this takes a scalar value, then that value times an identity matrix serves as the prior precision. The prior precision is assumed to be the same across all items.} \item{store.item}{A switch that determines whether or not to store the item parameters for posterior analysis. \emph{NOTE: In situations with many items storing the item parameters takes an enormous amount of memory, so \code{store.item} should only be \code{TRUE} if the chain is thinned heavily, or for applications with a small number of items}. By default, the item parameters are not stored.} \item{store.ability}{A switch that determines whether or not to store the ability parameters for posterior analysis. \emph{NOTE: In situations with many individuals storing the ability parameters takes an enormous amount of memory, so \code{store.ability} should only be \code{TRUE} if the chain is thinned heavily, or for applications with a small number of individuals}. By default, ability parameters are stored.} \item{drop.constant.items}{A switch that determines whether or not items that have no variation should be deleted before fitting the model. Default = TRUE.} \item{marginal.likelihood}{Should the marginal likelihood of the second-level model on ideal points be calculated using the method of Chib (1995)? It is stored as an attribute of the posterior \code{mcmc} object and suitable for comparison using \code{\link[MCMCpack]{BayesFactor}}.} \item{px}{Use Parameter Expansion to reduce autocorrelation in the chain? PX introduces an unidentified parameter \eqn{alpha} for the residual variance in the latent data (Liu and Wu 1999). Default = TRUE} \item{px_a0}{Prior shape parameter for the inverse-gamma distribution on \eqn{alpha}, the residual variance of the latent data. Default=10.} \item{px_b0}{Prior scale parameter for the inverse-gamma distribution on \eqn{alpha}, the residual variance of the latent data. Default = 10} \item{...}{further arguments to be passed} } \value{ An \code{mcmc} object that contains the sample from the posterior distribution. This object can be summarized by functions provided by the coda package. If \code{marginal.likelihood = "Chib95"} the object will have attribute \code{logmarglike}. } \description{ This function generates a sample from the posterior distribution of a one dimensional item response theory (IRT) model, with multivariate Normal priors on the item parameters, and a Normal-Inverse Gamma hierarchical prior on subject ideal points (abilities). The user supplies item-response data, subject covariates, and priors. Note that this identification strategy obviates the constraints used on theta in \code{\link[MCMCpack]{MCMCirt1d}}. A sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ If you are interested in fitting K-dimensional item response theory models, or would rather identify the model by placing constraints on the item parameters, please see \code{\link[MCMCpack]{MCMCirtKd}}. \code{MCMCirtHier1d} simulates from the posterior distribution using standard Gibbs sampling using data augmentation (a Normal draw for the subject abilities, a multivariate Normal draw for (second-level) subject ability predictors, an Inverse-Gamma draw for the (second-level) variance of subject abilities, a multivariate Normal draw for the item parameters, and a truncated Normal draw for the latent utilities). The simulation proper is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. The model takes the following form. We assume that each subject has an subject ability (ideal point) denoted \eqn{\theta_j} and that each item has a difficulty parameter \eqn{a_i} and discrimination parameter \eqn{b_i}. The observed choice by subject \eqn{j} on item \eqn{i} is the observed data matrix which is \eqn{(I \times J)}. We assume that the choice is dictated by an unobserved utility: \deqn{z_{i,j} = -\alpha_i + \beta_i \theta_j + \varepsilon_{i,j}} Where the errors are assumed to be distributed standard Normal. This constitutes the measurement or level-1 model. The subject abilities (ideal points) are modeled by a second level Normal linear predictor for subject covariates \code{Xjdata}, with common variance \eqn{\sigma^2}. The parameters of interest are the subject abilities (ideal points), item parameters, and second-level coefficients. We assume the following priors. For the subject abilities (ideal points): \deqn{\theta_j \sim \mathcal{N}(\mu_{\theta} ,T_{0}^{-1})} For the item parameters, the prior is: \deqn{\left[a_i, b_i \right]' \sim \mathcal{N}_2 (ab_{0},AB_{0}^{-1})} The model is identified by the proper priors on the item parameters and constraints placed on the ability parameters. As is the case with all measurement models, make sure that you have plenty of free memory, especially when storing the item parameters. } \examples{ \dontrun{ data(SupremeCourt) Xjdata <- data.frame(presparty= c(1,1,0,1,1,1,1,0,0), sex= c(0,0,1,0,0,0,0,1,0)) ## Parameter Expansion reduces autocorrelation. posterior1 <- MCMCirtHier1d(t(SupremeCourt), burnin=50000, mcmc=10000, thin=20, verbose=10000, Xjdata=Xjdata, marginal.likelihood="Chib95", px=TRUE) ## But, you can always turn it off. posterior2 <- MCMCirtHier1d(t(SupremeCourt), burnin=50000, mcmc=10000, thin=20, verbose=10000, Xjdata=Xjdata, #marginal.likelihood="Chib95", px=FALSE) ## Note that the hierarchical model has greater autocorrelation than ## the naive IRT model. posterior0 <- MCMCirt1d(t(SupremeCourt), theta.constraints=list(Scalia="+", Ginsburg="-"), B0.alpha=.2, B0.beta=.2, burnin=50000, mcmc=100000, thin=100, verbose=10000, store.item=FALSE) ## Randomly 10\% Missing -- this affects the expansion parameter, increasing ## the variance of the (unidentified) latent parameter alpha. scMiss <- SupremeCourt scMiss[matrix(as.logical(rbinom(nrow(SupremeCourt)*ncol(SupremeCourt), 1, .1)), dim(SupremeCourt))] <- NA posterior1.miss <- MCMCirtHier1d(t(scMiss), burnin=80000, mcmc=10000, thin=20, verbose=10000, Xjdata=Xjdata, marginal.likelihood="Chib95", px=TRUE) } } \references{ James H. Albert. 1992. ``Bayesian Estimation of Normal Ogive Item Response Curves Using Gibbs Sampling." \emph{Journal of Educational Statistics}. 17: 251--269. Joshua Clinton, Simon Jackman, and Douglas Rivers. 2004. ``The Statistical Analysis of Roll Call Data." \emph{American Political Science Review} 98: 355--370. Valen E. Johnson and James H. Albert. 1999. ``Ordinal Data Modeling." Springer: New York. Liu, Jun S. and Ying Nian Wu. 1999. ``Parameter Expansion for Data Augmentation.'' \emph{Journal of the American Statistical Association} 94: 1264--1274. Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. Douglas Rivers. 2004. ``Identification of Multidimensional Item-Response Models." Stanford University, typescript. } \seealso{ \code{\link[coda]{plot.mcmc}},\code{\link[coda]{summary.mcmc}}, \code{\link[MCMCpack]{MCMCirtKd}} } \author{ Michael Malecki, \email{mike@crunch.io}, \url{https://github.com/malecki}. } \keyword{models} MCMCpack/man/MCMCirtKdRob.Rd0000644000176200001440000003510013564573453015070 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCirtKdRob.R \name{MCMCirtKdRob} \alias{MCMCirtKdRob} \title{Markov Chain Monte Carlo for Robust K-Dimensional Item Response Theory Model} \usage{ MCMCirtKdRob(datamatrix, dimensions, item.constraints = list(), ability.constraints = list(), burnin = 500, mcmc = 5000, thin = 1, interval.method = "step", theta.w = 0.5, theta.mp = 4, alphabeta.w = 1, alphabeta.mp = 4, delta0.w = NA, delta0.mp = 3, delta1.w = NA, delta1.mp = 3, verbose = FALSE, seed = NA, theta.start = NA, alphabeta.start = NA, delta0.start = NA, delta1.start = NA, b0 = 0, B0 = 0, k0 = 0.1, k1 = 0.1, c0 = 1, d0 = 1, c1 = 1, d1 = 1, store.item = TRUE, store.ability = FALSE, drop.constant.items = TRUE, ...) } \arguments{ \item{datamatrix}{The matrix of data. Must be 0, 1, or missing values. It is of dimensionality subjects by items.} \item{dimensions}{The number of dimensions in the latent space.} \item{item.constraints}{List of lists specifying possible equality or simple inequality constraints on the item parameters. A typical entry in the list has one of three forms: \code{rowname=list(d,c)} which will constrain the dth item parameter for the item named rowname to be equal to c, \code{rowname=list(d,"+")} which will constrain the dth item parameter for the item named rowname to be positive, and \code{rowname=list(d, "-")} which will constrain the dth item parameter for the item named rowname to be negative. If datamatrix is a matrix without row names defaults names of ``V1", ``V2", ... , etc will be used. In a \eqn{K}-dimensional model, the first item parameter for item \eqn{i} is the difficulty parameter (\eqn{\alpha_i}), the second item parameter is the discrimation parameter on dimension 1 (\eqn{\beta_{i,1}}), the third item parameter is the discrimation parameter on dimension 2 (\eqn{\beta_{i,2}}), ..., and the \eqn{(K+1)}th item parameter is the discrimation parameter on dimension \eqn{K} (\eqn{\beta_{i,K}}). The item difficulty parameters (\eqn{\alpha}) should generally not be constrained.} \item{ability.constraints}{List of lists specifying possible equality or simple inequality constraints on the ability parameters. A typical entry in the list has one of three forms: \code{colname=list(d,c)} which will constrain the dth ability parameter for the subject named colname to be equal to c, \code{colname=list(d,"+")} which will constrain the dth ability parameter for the subject named colname to be positive, and \code{colname=list(d, "-")} which will constrain the dth ability parameter for the subject named colname to be negative. If datamatrix is a matrix without column names defaults names of ``V1", ``V2", ... , etc will be used.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of iterations for the sampler after burn-in.} \item{thin}{The thinning interval used in the simulation. The number of iterations must be divisible by this value.} \item{interval.method}{Method for finding the slicing interval. Can be equal to either \code{step} in which case the stepping out algorithm of Neal (2003) is used or \code{doubling} in which case the doubling procedure of Neal (2003) is used. The stepping out method tends to be faster on a per-iteration basis as it typically requires few function calls. The doubling method expands the initial interval more quickly which makes the Markov chain mix somewhat more quickly-- at least in some situations.} \item{theta.w}{The initial width of the slice sampling interval for each ability parameter (the elements of \eqn{\theta})} \item{theta.mp}{The parameter governing the maximum possible width of the slice interval for each ability parameter (the elements of \eqn{\theta}). If \code{interval.method="step"} then the maximum width is \code{theta.w * theta.mp}. If \code{interval.method="doubling"} then the maximum width is \code{theta.w * 2^theta.mp}.} \item{alphabeta.w}{The initial width of the slice sampling interval for each item parameter (the elements of \eqn{\alpha} and \eqn{\beta})} \item{alphabeta.mp}{The parameter governing the maximum possible width of the slice interval for each item parameters (the elements of \eqn{\alpha} and \eqn{\beta}). If \code{interval.method="step"} then the maximum width is \code{alphabeta.w * alphabeta.mp}. If \code{interval.method="doubling"} then the maximum width is \code{alphabeta.w * 2^alphabeta.mp}.} \item{delta0.w}{The initial width of the slice sampling interval for \eqn{\delta_0}} \item{delta0.mp}{The parameter governing the maximum possible width of the slice interval for \eqn{\delta_0}. If \code{interval.method="step"} then the maximum width is \code{delta0.w * delta0.mp}. If \code{interval.method="doubling"} then the maximum width is \code{delta0.w * 2^delta0.mp}.} \item{delta1.w}{The initial width of the slice sampling interval for \eqn{\delta_1}} \item{delta1.mp}{The parameter governing the maximum possible width of the slice interval for \eqn{\delta_1}. If \code{interval.method="step"} then the maximum width is \code{delta1.w * delta1.mp}. If \code{interval.method="doubling"} then the maximum width is \code{delta1.w * 2^delta1.mp}.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If verbose > 0, the iteration number with be printed to the screen every verbose'th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{theta.start}{The starting values for the ability parameters \eqn{\theta}. Can be either a scalar or a matrix with number of rows equal to the number of subjects and number of columns equal to the dimension \eqn{K} of the latent space. If \code{theta.start=NA} then starting values will be chosen that are 0 for unconstrained subjects, -0.5 for subjects with negative inequality constraints and 0.5 for subjects with positive inequality constraints.} \item{alphabeta.start}{The starting values for the \eqn{\alpha} and \eqn{\beta} difficulty and discrimination parameters. If \code{alphabeta.start} is set to a scalar the starting value for all unconstrained item parameters will be set to that scalar. If \code{alphabeta.start} is a matrix of dimension \eqn{(K+1) \times items} then the \code{alphabeta.start} matrix is used as the starting values (except for equality-constrained elements). If \code{alphabeta.start} is set to \code{NA} (the default) then starting values for unconstrained elements are set to values generated from a series of proportional odds logistic regression fits, and starting values for inequality constrained elements are set to either 1.0 or -1.0 depending on the nature of the constraints.} \item{delta0.start}{The starting value for the \eqn{\delta_0} parameter.} \item{delta1.start}{The starting value for the \eqn{\delta_1} parameter.} \item{b0}{The prior means of the \eqn{\alpha} and \eqn{\beta} difficulty and discrimination parameters, stacked for all items. If a scalar is passed, it is used as the prior mean for all items.} \item{B0}{The prior precisions (inverse variances) of the independent Normal prior on the item parameters. Can be either a scalar or a matrix of dimension \eqn{(K+1) \times items}.} \item{k0}{\eqn{\delta_0} is constrained to lie in the interval between 0 and \code{k0}.} \item{k1}{\eqn{\delta_1} is constrained to lie in the interval between 0 and \code{k1}.} \item{c0}{Parameter governing the prior for \eqn{\delta_0}. \eqn{\delta_0} divided by \code{k0} is assumed to be follow a beta distribution with first parameter \code{c0}.} \item{d0}{Parameter governing the prior for \eqn{\delta_0}. \eqn{\delta_0} divided by \code{k0} is assumed to be follow a beta distribution with second parameter \code{d0}.} \item{c1}{Parameter governing the prior for \eqn{\delta_1}. \eqn{\delta_1} divided by \code{k1} is assumed to be follow a beta distribution with first parameter \code{c1}.} \item{d1}{Parameter governing the prior for \eqn{\delta_1}. \eqn{\delta_1} divided by \code{k1} is assumed to be follow a beta distribution with second parameter \code{d1}.} \item{store.item}{A switch that determines whether or not to store the item parameters for posterior analysis. \emph{NOTE: This typically takes an enormous amount of memory, so should only be used if the chain is thinned heavily, or for applications with a small number of items}. By default, the item parameters are not stored.} \item{store.ability}{A switch that determines whether or not to store the subject abilities for posterior analysis. By default, the item parameters are all stored.} \item{drop.constant.items}{A switch that determines whether or not items that have no variation should be deleted before fitting the model. Default = TRUE.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a posterior sample from a Robust K-dimensional item response theory (IRT) model with logistic link, independent standard normal priors on the subject abilities (ideal points), and independent normal priors on the item parameters. The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMCirtKdRob} simulates from the posterior using the slice sampling algorithm of Neal (2003). The simulation proper is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. The model takes the following form. We assume that each subject has an subject ability (ideal point) denoted \eqn{\theta_j} \eqn{(K \times 1)}, and that each item has a scalar difficulty parameter \eqn{\alpha_i} and discrimination parameter \eqn{\beta_i} \eqn{(K \times 1)}. The observed choice by subject \eqn{j} on item \eqn{i} is the observed data matrix which is \eqn{(I \times J)}. The probability that subject \eqn{j} answers item \eqn{i} correctly is assumed to be: \deqn{\pi_{ij} = \delta_0 + (1 - \delta_0 - \delta_1) / (1+\exp(\alpha_i - \beta_i \theta_j))} This model was discussed in Bafumi et al. (2005). We assume the following priors. For the subject abilities (ideal points) we assume independent standard Normal priors: \deqn{\theta_{j,k} \sim \mathcal{N}(0,1)} These cannot be changed by the user. For each item parameter, we assume independent Normal priors: \deqn{\left[\alpha_i, \beta_i \right]' \sim \mathcal{N}_{(K+1)} (b_{0,i},B_{0,i})} Where \eqn{B_{0,i}} is a diagonal matrix. One can specify a separate prior mean and precision for each item parameter. We also assume \eqn{\delta_0 / k_0 \sim }\eqn{ \mathcal{B}eta(c_0, d_0)} and \eqn{\delta_1 / k_1 \sim }\eqn{ \mathcal{B}eta(c_1, d_1)}. The model is identified by constraints on the item parameters and / or ability parameters. See Rivers (2004) for a discussion of identification of IRT models. As is the case with all measurement models, make sure that you have plenty of free memory, especially when storing the item parameters. } \examples{ \dontrun{ ## Court example with ability (ideal point) and ## item (case) constraints data(SupremeCourt) post1 <- MCMCirtKdRob(t(SupremeCourt), dimensions=1, burnin=500, mcmc=5000, thin=1, B0=.25, store.item=TRUE, store.ability=TRUE, ability.constraints=list("Thomas"=list(1,"+"), "Stevens"=list(1,-4)), item.constraints=list("1"=list(2,"-")), verbose=50) plot(post1) summary(post1) ## Senate example with ability (ideal point) constraints data(Senate) namestring <- as.character(Senate$member) namestring[78] <- "CHAFEE1" namestring[79] <- "CHAFEE2" namestring[59] <- "SMITH.NH" namestring[74] <- "SMITH.OR" rownames(Senate) <- namestring post2 <- MCMCirtKdRob(Senate[,6:677], dimensions=1, burnin=1000, mcmc=5000, thin=1, ability.constraints=list("KENNEDY"=list(1,-4), "HELMS"=list(1, 4), "ASHCROFT"=list(1,"+"), "BOXER"=list(1,"-"), "KERRY"=list(1,"-"), "HATCH"=list(1,"+")), B0=0.1, store.ability=TRUE, store.item=FALSE, verbose=5, k0=0.15, k1=0.15, delta0.start=0.13, delta1.start=0.13) plot(post2) summary(post2) } } \references{ James H. Albert. 1992. ``Bayesian Estimation of Normal Ogive Item Response Curves Using Gibbs Sampling." \emph{Journal of Educational Statistics}. 17: 251-269. Joseph Bafumi, Andrew Gelman, David K. Park, and Noah Kaplan. 2005. ``Practical Issues in Implementing and Understanding Bayesian Ideal Point Estimation.'' \emph{Political Analysis}. Joshua Clinton, Simon Jackman, and Douglas Rivers. 2004. ``The Statistical Analysis of Roll Call Data." \emph{American Political Science Review}. 98: 355-370. Simon Jackman. 2001. ``Multidimensional Analysis of Roll Call Data via Bayesian Simulation.'' \emph{Political Analysis.} 9: 227-241. Valen E. Johnson and James H. Albert. 1999. \emph{Ordinal Data Modeling}. Springer: New York. Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Radford Neal. 2003. ``Slice Sampling'' (with discussion). \emph{Annals of Statistics}, 31: 705-767. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. Douglas Rivers. 2004. ``Identification of Multidimensional Item-Response Models." Stanford University, typescript. } \seealso{ \code{\link[coda]{plot.mcmc}},\code{\link[coda]{summary.mcmc}}, \code{\link[MCMCpack]{MCMCirt1d}}, \code{\link[MCMCpack]{MCMCirtKd}} } \keyword{models} MCMCpack/man/PostProbMod.Rd0000644000176200001440000000410113564573453015115 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/BayesFactors.R \name{PostProbMod} \alias{PostProbMod} \title{Calculate Posterior Probability of Model} \usage{ PostProbMod(BF, prior.probs = 1) } \arguments{ \item{BF}{An object of class \code{BayesFactor}.} \item{prior.probs}{The prior probabilities that each model is correct. Can be either a scalar or array. Must be positive. If the sum of the prior probabilities is not equal to 1 prior.probs will be normalized so that it does sum to unity.} } \value{ An array holding the posterior probabilities that each model under study is correct given that one of the models under study is correct. } \description{ This function takes an object of class \code{BayesFactor} and calculates the posterior probability that each model under study is correct given that one of the models under study is correct. } \examples{ \dontrun{ data(birthwt) post1 <- MCMCregress(bwt~age+lwt+as.factor(race) + smoke + ht, data=birthwt, b0=c(2700, 0, 0, -500, -500, -500, -500), B0=c(1e-6, .01, .01, 1.6e-5, 1.6e-5, 1.6e-5, 1.6e-5), c0=10, d0=4500000, marginal.likelihood="Chib95", mcmc=10000) post2 <- MCMCregress(bwt~age+lwt+as.factor(race) + smoke, data=birthwt, b0=c(2700, 0, 0, -500, -500, -500), B0=c(1e-6, .01, .01, 1.6e-5, 1.6e-5, 1.6e-5), c0=10, d0=4500000, marginal.likelihood="Chib95", mcmc=10000) post3 <- MCMCregress(bwt~as.factor(race) + smoke + ht, data=birthwt, b0=c(2700, -500, -500, -500, -500), B0=c(1e-6, 1.6e-5, 1.6e-5, 1.6e-5, 1.6e-5), c0=10, d0=4500000, marginal.likelihood="Chib95", mcmc=10000) BF <- BayesFactor(post1, post2, post3) mod.probs <- PostProbMod(BF) print(mod.probs) } } \seealso{ \code{\link{MCMCregress}} } \keyword{models} MCMCpack/man/SSVSquantreg.Rd0000644000176200001440000001477713564573453015276 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/SSVSquantreg.R \name{SSVSquantreg} \alias{SSVSquantreg} \title{Stochastic search variable selection for quantile regression} \usage{ SSVSquantreg(formula, data = NULL, tau = 0.5, include = NULL, burnin = 1000, mcmc = 10000, thin = 1, verbose = 0, seed = sample(1:1e+06, 1), pi0a0 = 1, pi0b0 = 1, ...) } \arguments{ \item{formula}{Model formula.} \item{data}{Data frame.} \item{tau}{The quantile of interest. Must be between 0 and 1. The default value of 0.5 corresponds to median regression model selection.} \item{include}{The predictor(s) that should definitely appear in the model. Can be specified by name, or their position in the formula (taking into account the intercept).} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of MCMC iterations after burnin.} \item{thin}{The thinning interval used in the simulation. The number of MCMC iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the most recently sampled values of \eqn{\gamma} and the associated values of \eqn{\beta} are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The default value for this argument is a random integer between 1 and 1,000,000. This default value ensures that if the function is used again with a different value of \eqn{\tau}, it is extremely unlikely that the seed will be identical. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{pi0a0, pi0b0}{Hyperparameters of the beta prior on \eqn{\pi_0}, the prior probability of including a predictor. Default values of (1,1) are equivalent to a uniform distribution.} \item{...}{Further arguments} } \value{ A list containing: \item{gamma}{The posterior sample of \eqn{\gamma}. This has associated summary and plot methods.} \item{beta}{The posterior sample of the associated regression parameters \eqn{\beta}. This can be analysed with functions from the coda package.} } \description{ This function uses stochastic search to select promising regression models at a fixed quantile \eqn{\tau}. Indicator variables \eqn{\gamma} are used to represent whether a predictor is included in the model or not. The user supplies the data and the prior distribution on the model size. A list is returned containing the posterior sample of \eqn{\gamma} and the associated regression parameters \eqn{\beta}. } \details{ \code{SSVSquantreg} implements stochastic search variable selection over a set of potential predictors to obtain promising models. The models considered take the following form: \deqn{Q_{\tau}(y_i|x_{i\gamma}) = x_{i\gamma} ' \beta_{\gamma},} where \eqn{Q_{\tau}(y_i|x_{i\gamma})} denotes the conditional \eqn{\tau}th quantile of \eqn{y_i} given \eqn{x_{i\gamma}}, \eqn{x_{i\gamma}} denotes \eqn{x_i} with those predictors \eqn{x_{ij}} for which \eqn{\gamma_j=0} removed and \eqn{\beta_{\gamma}} denotes the model specific regression parameters. The likelihood is formed based on the assumption of independent asymmetric Laplace distributions on the \eqn{y_i} with skewness parameter \eqn{\tau} and location parameters \eqn{ x_{i\gamma} ' \beta_{\gamma}}. This assumption ensures that the likelihood function is maximised by the \eqn{\tau}th conditional quantile of the response variable. The prior on each \eqn{\beta_j} is \deqn{(1-\gamma_j)\delta_0+\gamma_j\mbox{Cauchy}(0,1),} where \eqn{\delta_0} denotes a degenerate distribution with all mass at 0. A standard Cauchy distribution is chosen conditional on \eqn{\gamma_j=1}. This allows for a wider range of nonzero values of \eqn{\beta_j} than a standard Normal distribution, improving the robustness of the method. Each of the indicator variables \eqn{\gamma_j} is independently assigned a Bernoulli prior, with prior probability of inclusion \eqn{\pi_0}. This in turn is assigned a beta distribution, resulting in a beta-binomial prior on the model size. The user can supply the hyperparameters for the beta distribution. Starting values are randomly generated from the prior distribution. It is recommended to standardise any non-binary predictors in order to compare these predictors on the same scale. This can be achieved using the \code{scale} function. If it is certain that a predictor should be included, all predictors specified are brought to the first positions for computational convenience. The regression parameters associated with these predictors are given independent improper priors. Users may notice a small speed advantage if they specify the predictors that they feel certain should appear in the model, particularly for large models with a large number of observations. } \examples{ \dontrun{ set.seed(1) epsilon<-rnorm(100) set.seed(2) x<-matrix(rnorm(1000),100,10) y<-x[,1]+x[,10]+epsilon qrssvs<-SSVSquantreg(y~x) model.50pc<-SSVSquantreg(y~x) model.90pc<-SSVSquantreg(y~x,tau=0.9) summary(model.50pc) ## Intercept not in median probability model summary(model.90pc) ## Intercept appears in median probability model } } \references{ Craig Reed, David B. Dunson and Keming Yu. 2010. "Bayesian Variable Selection for Quantile Regression" Technical Report. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.2.} \url{http://scythe.lsa.umich.edu}. Keming Yu and Jin Zhang. 2005. "A Three Parameter Asymmetric Laplace Distribution and it's extensions." \emph{Communications in Statistics - Theory and Methods}, 34, 1867-1879. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. } \seealso{ \code{\link[MCMCpack]{MCMCquantreg}}, \code{\link[MCMCpack]{summary.qrssvs}}, \code{\link[MCMCpack]{plot.qrssvs}}, \code{\link[MCMCpack]{mptable}}, \code{\link[MCMCpack]{topmodels}}, \code{\link[base]{scale}}, \code{\link[quantreg]{rq}} } \author{ Craig Reed } \keyword{models} MCMCpack/man/mptable.Rd0000644000176200001440000000162513564573453014341 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/SSVSquantregsummary.R \name{mptable} \alias{mptable} \title{Calculate the marginal posterior probabilities of predictors being included in a quantile regression model.} \usage{ mptable(qrssvs) } \arguments{ \item{qrssvs}{An object of class \code{qrssvs}. Typically this will be the \code{gamma} component of the list returned by \code{SSVSquantreg}.} } \value{ A table with the predictors listed together with their posterior marginal posterior probability of inclusion. } \description{ This function extracts the marginal probability table produced by \code{summary.qrssvs}. } \examples{ \dontrun{ set.seed(1) epsilon<-rnorm(100) set.seed(2) x<-matrix(rnorm(1000),100,10) y<-x[,1]+x[,10]+epsilon qrssvs<-SSVSquantreg(y~x) mptable(qrssvs$gamma) } } \seealso{ \code{\link[MCMCpack]{SSVSquantreg}} } \author{ Craig Reed } \keyword{models} MCMCpack/man/MCMCSVDreg.Rd0000644000176200001440000001317413564573453014511 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCSVDreg.R \name{MCMCSVDreg} \alias{MCMCSVDreg} \title{Markov Chain Monte Carlo for SVD Regression} \usage{ MCMCSVDreg(formula, data = NULL, burnin = 1000, mcmc = 10000, thin = 1, verbose = 0, seed = NA, tau2.start = 1, g0 = 0, a0 = 0.001, b0 = 0.001, c0 = 2, d0 = 2, w0 = 1, beta.samp = FALSE, intercept = TRUE, ...) } \arguments{ \item{formula}{Model formula. Predictions are returned for elements of y that are coded as NA.} \item{data}{Data frame.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of MCMC iterations after burnin.} \item{thin}{The thinning interval used in the simulation. The number of MCMC iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the \eqn{\beta} vector, and the error variance are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{tau2.start}{The starting values for the \eqn{\tau^2} vector. Can be either a scalar or a vector. If a scalar is passed then that value will be the starting value for all elements of \eqn{\tau^2}.} \item{g0}{The prior mean of \eqn{\gamma}. This can either be a scalar or a column vector with dimension equal to the number of gammas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{a0}{\eqn{a_0/2} is the shape parameter for the inverse Gamma prior on \eqn{\sigma^2} (the variance of the disturbances). The amount of information in the inverse Gamma prior is something like that from \eqn{a_0} pseudo-observations.} \item{b0}{\eqn{b_0/2} is the scale parameter for the inverse Gamma prior on \eqn{\sigma^2} (the variance of the disturbances). In constructing the inverse Gamma prior, \eqn{b_0} acts like the sum of squared errors from the \eqn{a_0} pseudo-observations.} \item{c0}{\eqn{c_0/2} is the shape parameter for the inverse Gamma prior on \eqn{\tau_i^2}.} \item{d0}{\eqn{d_0/2} is the scale parameter for the inverse Gamma prior on \eqn{\tau_i^2}.} \item{w0}{The prior probability that \eqn{\gamma_i = 0}. Can be either a scalar or an \eqn{N} vector where \eqn{N} is the number of observations.} \item{beta.samp}{Logical indicating whether the sampled elements of beta should be stored and returned.} \item{intercept}{Logical indicating whether the original design matrix should include a constant term.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a linear regression model with Gaussian errors in which the design matrix has been decomposed with singular value decomposition.The sampling is done via the Gibbs sampling algorithm. The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ The model takes the following form: \deqn{y = X \beta + \varepsilon} Where the errors are assumed to be iid Gaussian: \deqn{\varepsilon_{i} \sim \mathcal{N}(0, \sigma^2)} Let \eqn{N} denote the number of rows of \eqn{X} and \eqn{P} the number of columns of \eqn{X}. Unlike the standard regression setup where \eqn{N >> P} here it is the case that \eqn{P >> N}. To deal with this problem a singular value decomposition of \eqn{X'} is performed: \eqn{X' = ADF} and the regression model becomes \deqn{y = F'D \gamma + \varepsilon} where \eqn{\gamma = A' \beta} We assume the following priors: \deqn{\sigma^{-2} \sim \mathcal{G}amma(a_0/2, b_0/2)} \deqn{\tau^{-2} \sim \mathcal{G}amma(c_0/2, d_0/2)} \deqn{\gamma_i \sim w0_i \delta_0 + (1-w0_i) \mathcal{N}(g0_i, \sigma^2 \tau_i^2/ d_i^2)} where \eqn{\delta_0} is a unit point mass at 0 and \eqn{d_i} is the \eqn{i}th diagonal element of \eqn{D}. } \references{ Mike West, Josheph Nevins, Jeffrey Marks, Rainer Spang, and Harry Zuzan. 2000. ``DNA Microarray Data Analysis and Regression Modeling for Genetic Expression Profiling." Duke ISDS working paper. Gottardo, Raphael, and Adrian Raftery. 2004. ``Markov chain Monte Carlo with mixtures of singular distributions.'' Statistics Department, University of Washington, Technical Report 470. Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. } \seealso{ \code{\link[coda]{plot.mcmc}}, \code{\link[coda]{summary.mcmc}}, \code{\link[stats]{lm}} } \keyword{models} MCMCpack/man/plot.qrssvs.Rd0000644000176200001440000000266013564573453015233 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/SSVSquantregsummary.R \name{plot.qrssvs} \alias{plot.qrssvs} \title{Plot output from quantile regression stochastic search variable selection (QR-SSVS).} \usage{ \method{plot}{qrssvs}(x, ...) } \arguments{ \item{x}{An object of class \code{qrssvs}. Typically this will be the \code{gamma} component of the list returned by \code{SSVSquantreg}.} \item{...}{Further arguments} } \value{ An object with class \code{"trellis"}. The associated \code{\link[lattice:update.trellis]{update}} and \code{\link[lattice:print.trellis]{print}} methods are documented in the "Lattice" package. } \description{ This function produces a Trellis plot of the predictors on the y-axis versus the marginal posterior probability of inclusion on the x-axis. } \examples{ \dontrun{ set.seed(1) epsilon<-rnorm(100) set.seed(2) x<-matrix(rnorm(1000),100,10) y<-x[,1]+x[,10]+epsilon qrssvs<-SSVSquantreg(y~x) plot(qrssvs$gamma) ## Modify the graph by increasing the fontsize on the axes qrssvsplot<-plot(qrssvs$gamma) update(qrssvsplot, scales=list(cex=3)) } } \references{ Deepayan Sarkar. 2008. \emph{lattice: Lattice Graphics.} R package version 0.17-17 } \seealso{ \code{\link[MCMCpack]{SSVSquantreg}}, \code{\link[MCMCpack]{mptable}}, \code{\link[lattice:Lattice]{Lattice}} for a brief introduction to lattice displays and links to further documentation. } \author{ Craig Reed } \keyword{models} MCMCpack/man/HMMpanelFE.Rd0000644000176200001440000001576013564573453014576 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/HMMpanelFE.R \name{HMMpanelFE} \alias{HMMpanelFE} \title{Markov Chain Monte Carlo for the Hidden Markov Fixed-effects Model} \usage{ HMMpanelFE(subject.id, y, X, m, mcmc = 1000, burnin = 1000, thin = 1, verbose = 0, b0 = 0, B0 = 0.001, c0 = 0.001, d0 = 0.001, delta0 = 0, Delta0 = 0.001, a = NULL, b = NULL, seed = NA, ...) } \arguments{ \item{subject.id}{A numeric vector indicating the group number. It should start from 1.} \item{y}{The response variable.} \item{X}{The model matrix excluding the constant.} \item{m}{A vector of break numbers for each subject in the panel.} \item{mcmc}{The number of MCMC iterations after burn-in.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of MCMC iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0, the iteration number and the posterior density samples are printed to the screen every \code{verbose}th iteration.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of beta. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{c0}{\eqn{c_0/2} is the shape parameter for the inverse Gamma prior on \eqn{\sigma^2} (the variance of the disturbances). The amount of information in the inverse Gamma prior is something like that from \eqn{c_0} pseudo-observations.} \item{d0}{\eqn{d_0/2} is the scale parameter for the inverse Gamma prior on \eqn{\sigma^2} (the variance of the disturbances). In constructing the inverse Gamma prior, \eqn{d_0} acts like the sum of squared errors from the \eqn{c_0} pseudo-observations.} \item{delta0}{The prior mean of \eqn{\alpha}.} \item{Delta0}{The prior precision of \eqn{\alpha}.} \item{a}{\eqn{a} is the shape1 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{b}{\eqn{b} is the shape2 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{seed}{The seed for the random number generator. If NA, current R system seed is used.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. The object contains an attribute \code{sigma} storage matrix that contains time-varying residual variance, an attribute \code{state} storage matrix that contains posterior samples of hidden states, and an attribute \code{delta} storage matrix containing time-varying intercepts. } \description{ HMMpanelFE generates a sample from the posterior distribution of the fixed-effects model with varying individual effects model discussed in Park (2011). The code works for both balanced and unbalanced panel data as long as there is no missing data in the middle of each group. This model uses a multivariate Normal prior for the fixed effects parameters and varying individual effects, an Inverse-Gamma prior on the residual error variance, and Beta prior for transition probabilities. The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{HMMpanelFE} simulates from the fixed-effect hidden Markov pbject level: \deqn{\varepsilon_{it} \sim \mathcal{N}(\alpha_{im}, \sigma^2_{im})} We assume standard, semi-conjugate priors: \deqn{\beta \sim \mathcal{N}(b_0,B_0^{-1})} And: \deqn{\sigma^{-2} \sim \mathcal{G}amma(c_0/2, d_0/2)} And: \deqn{\alpha \sim \mathcal{N}(delta_0,Delta_0^{-1})} \eqn{\beta}, \eqn{\alpha} and \eqn{\sigma^{-2}} are assumed \emph{a priori} independent. And: \deqn{p_{mm} \sim \mathcal{B}eta(a, b),\;\; m = 1, \ldots, M} Where \eqn{M} is the number of states. OLS estimates are used for starting values. } \examples{ \dontrun{ ## data generating set.seed(1974) N <- 30 T <- 80 NT <- N*T ## true parameter values true.beta <- c(1, 1) true.sigma <- 3 x1 <- rnorm(NT) x2 <- runif(NT, 2, 4) ## group-specific breaks break.point = rep(T/2, N); break.sigma=c(rep(1, N)); break.list <- rep(1, N) X <- as.matrix(cbind(x1, x2), NT, ); y <- rep(NA, NT) id <- rep(1:N, each=NT/N) K <- ncol(X); true.beta <- as.matrix(true.beta, K, 1) ## compute the break probability ruler <- c(1:T) W.mat <- matrix(NA, T, N) for (i in 1:N){ W.mat[, i] <- pnorm((ruler-break.point[i])/break.sigma[i]) } Weight <- as.vector(W.mat) ## draw time-varying individual effects and sample y j = 1 true.sigma.alpha <- 30 true.alpha1 <- true.alpha2 <- rep(NA, N) for (i in 1:N){ Xi <- X[j:(j+T-1), ] true.mean <- Xi \%*\% true.beta weight <- Weight[j:(j+T-1)] true.alpha1[i] <- rnorm(1, 0, true.sigma.alpha) true.alpha2[i] <- -1*true.alpha1[i] y[j:(j+T-1)] <- ((1-weight)*true.mean + (1-weight)*rnorm(T, 0, true.sigma) + (1-weight)*true.alpha1[i]) + (weight*true.mean + weight*rnorm(T, 0, true.sigma) + weight*true.alpha2[i]) j <- j + T } ## extract the standardized residuals from the OLS with fixed-effects FEols <- lm(y ~ X + as.factor(id) -1 ) resid.all <- rstandard(FEols) time.id <- rep(1:80, N) ## model fitting G <- 100 BF <- testpanelSubjectBreak(subject.id=id, time.id=time.id, resid= resid.all, max.break=3, minimum = 10, mcmc=G, burnin = G, thin=1, verbose=G, b0=0, B0=1/100, c0=2, d0=2, Time = time.id) ## get the estimated break numbers estimated.breaks <- make.breaklist(BF, threshold=3) ## model fitting out <- HMMpanelFE(subject.id = id, y, X=X, m = estimated.breaks, mcmc=G, burnin=G, thin=1, verbose=G, b0=0, B0=1/1000, c0=2, d0=2, delta0=0, Delta0=1/1000) ## print out the slope estimate ## true values are 1 and 1 summary(out) ## compare them with the result from the constant fixed-effects summary(FEols) } } \references{ Jong Hee Park, 2012. ``Unified Method for Dynamic and Cross-Sectional Heterogeneity: Introducing Hidden Markov Panel Models.'' \emph{American Journal of Political Science}.56: 1040-1054. Siddhartha Chib. 1998. ``Estimation and comparison of multiple change-point models.'' \emph{Journal of Econometrics}. 86: 221-241. } \keyword{models} MCMCpack/man/summaryqrssvs.Rd0000644000176200001440000000303613564573453015672 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/SSVSquantregsummary.R \name{summaryqrssvs} \alias{summaryqrssvs} \alias{summary.qrssvs} \alias{print.summary.qrssvs} \title{Summarising the results of quantile regression stochastic search variable selection (QR-SSVS).} \usage{ \method{summary}{qrssvs}(object, ...) } \arguments{ \item{object}{An object of class \code{qrssvs}. Typically this will be the \code{gamma} component of the list returned by \code{SSVSquantreg}.} \item{...}{Further arguments.} } \description{ This function produces a table of predictors and their associated marginal posterior probability of inclusion. It also returns the median probability model (see the details section). } \details{ The median probability model is defined to be the model that contains any predictor with marginal posterior probability greater than or equal to 0.5. If the goal is to select a single model e.g. for prediction, Barbieri and Berger (2004) recommend the median probability model. In some cases, this will coincide with the maximum probability model. } \examples{ \dontrun{ set.seed(1) epsilon<-rnorm(100) set.seed(2) x<-matrix(rnorm(1000),100,10) y<-x[,1]+x[,10]+epsilon qrssvs<-SSVSquantreg(y~x) summary(qrssvs$gamma) } } \references{ Maria M. Barbieri, and James O. Berger (2004). "Optimal predictive model selection". \emph{Annals of Statistics}, 32, 870-897. } \seealso{ \code{\link[MCMCpack]{SSVSquantreg}}, \code{\link[MCMCpack]{mptable}}, \code{\link[MCMCpack]{topmodels}} } \author{ Craig Reed } \keyword{models} MCMCpack/man/Senate.Rd0000644000176200001440000000146213564573453014133 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/data.R \docType{data} \name{Senate} \alias{Senate} \title{106th U.S. Senate Roll Call Vote Matrix} \format{The dataframe contains roll call data for all Senators in the 106th Senate. The first column (id) is the ICPSR member ID number, the second column (statecode) is the ICPSR state code, the third column (party) is the member's state name, and the fourth column (member) is the member's name. This is followed by all roll call votes (including unanimous ones) in the 106th. Nay votes are coded 0, yea votes are coded 1, and NAs are missing votes.} \source{ Keith Poole. 2005. \emph{106th Roll Call Vote Data}. } \description{ This dataframe contains a matrix of votes cast by U.S. Senators in the 106th Congress. } \keyword{datasets} MCMCpack/man/MCMCfactanal.Rd0000644000176200001440000002065613564573453015133 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCfactanal.R \name{MCMCfactanal} \alias{MCMCfactanal} \title{Markov Chain Monte Carlo for Normal Theory Factor Analysis Model} \usage{ MCMCfactanal(x, factors, lambda.constraints = list(), data = NULL, burnin = 1000, mcmc = 20000, thin = 1, verbose = 0, seed = NA, lambda.start = NA, psi.start = NA, l0 = 0, L0 = 0, a0 = 0.001, b0 = 0.001, store.scores = FALSE, std.var = TRUE, ...) } \arguments{ \item{x}{Either a formula or a numeric matrix containing the manifest variables.} \item{factors}{The number of factors to be fitted.} \item{lambda.constraints}{List of lists specifying possible simple equality or inequality constraints on the factor loadings. A typical entry in the list has one of three forms: \code{varname=list(d,c)} which will constrain the dth loading for the variable named \code{varname} to be equal to c, \code{varname=list(d,"+")} which will constrain the dth loading for the variable named \code{varname} to be positive, and \code{varname=list(d, "-")} which will constrain the dth loading for the variable named \code{varname} to be negative. If x is a matrix without column names defaults names of ``V1",``V2", ... , etc will be used.} \item{data}{A data frame.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number and the factor loadings and uniquenesses are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{lambda.start}{Starting values for the factor loading matrix Lambda. If \code{lambda.start} is set to a scalar the starting value for all unconstrained loadings will be set to that scalar. If \code{lambda.start} is a matrix of the same dimensions as Lambda then the \code{lambda.start} matrix is used as the starting values (except for equality-constrained elements). If \code{lambda.start} is set to \code{NA} (the default) then starting values for unconstrained elements are set to 0, and starting values for inequality constrained elements are set to either 0.5 or -0.5 depending on the nature of the constraints.} \item{psi.start}{Starting values for the uniquenesses. If \code{psi.start} is set to a scalar then the starting value for all diagonal elements of \code{Psi} are set to this value. If \code{psi.start} is a \eqn{k}-vector (where \eqn{k} is the number of manifest variables) then the staring value of \code{Psi} has \code{psi.start} on the main diagonal. If \code{psi.start} is set to \code{NA} (the default) the starting values of all the uniquenesses are set to 0.5.} \item{l0}{The means of the independent Normal prior on the factor loadings. Can be either a scalar or a matrix with the same dimensions as \code{Lambda}.} \item{L0}{The precisions (inverse variances) of the independent Normal prior on the factor loadings. Can be either a scalar or a matrix with the same dimensions as \code{Lambda}.} \item{a0}{Controls the shape of the inverse Gamma prior on the uniqueness. The actual shape parameter is set to \code{a0/2}. Can be either a scalar or a \eqn{k}-vector.} \item{b0}{Controls the scale of the inverse Gamma prior on the uniquenesses. The actual scale parameter is set to \code{b0/2}. Can be either a scalar or a \eqn{k}-vector.} \item{store.scores}{A switch that determines whether or not to store the factor scores for posterior analysis. \emph{NOTE: This takes an enormous amount of memory, so should only be used if the chain is thinned heavily, or for applications with a small number of observations}. By default, the factor scores are not stored.} \item{std.var}{If \code{TRUE} (the default) the manifest variables are rescaled to have zero mean and unit variance. Otherwise, the manifest variables are rescaled to have zero mean but retain their observed variances.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the sample from the posterior distribution. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a normal theory factor analysis model. Normal priors are assumed on the factor loadings and factor scores while inverse Gamma priors are assumed for the uniquenesses. The user supplies data and parameters for the prior distributions, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ The model takes the following form: \deqn{x_i = \Lambda \phi_i + \epsilon_i} \deqn{\epsilon_i \sim \mathcal{N}(0,\Psi)} where \eqn{x_i} is the \eqn{k}-vector of observed variables specific to observation \eqn{i}, \eqn{\Lambda} is the \eqn{k \times d} matrix of factor loadings, \eqn{\phi_i} is the \eqn{d}-vector of latent factor scores, and \eqn{\Psi} is a diagonal, positive definite matrix. Traditional factor analysis texts refer to the diagonal elements of \eqn{\Psi} as uniquenesses. The implementation used here assumes independent conjugate priors for each element of \eqn{\Lambda} each \eqn{\phi_i}, and each diagonal element of \eqn{\Psi}. More specifically we assume: \deqn{\Lambda_{ij} \sim \mathcal{N}(l_{0_{ij}}, L_{0_{ij}}^{-1}), i=1,\ldots,k, j=1,\ldots,d} \deqn{\phi_i \sim \mathcal{N}(0, I), i=1,\dots,n} \deqn{\Psi_{ii} \sim \mathcal{IG}(a_{0_i}/2, b_{0_i}/2), i=1,\ldots,k} \code{MCMCfactanal} simulates from the posterior distribution using standard Gibbs sampling. The simulation proper is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. As is the case with all measurement models, make sure that you have plenty of free memory, especially when storing the scores. } \examples{ \dontrun{ ### An example using the formula interface data(swiss) posterior <- MCMCfactanal(~Agriculture+Examination+Education+Catholic +Infant.Mortality, factors=2, lambda.constraints=list(Examination=list(1,"+"), Examination=list(2,"-"), Education=c(2,0), Infant.Mortality=c(1,0)), verbose=0, store.scores=FALSE, a0=1, b0=0.15, data=swiss, burnin=5000, mcmc=50000, thin=20) plot(posterior) summary(posterior) ### An example using the matrix interface Y <- cbind(swiss$Agriculture, swiss$Examination, swiss$Education, swiss$Catholic, swiss$Infant.Mortality) colnames(Y) <- c("Agriculture", "Examination", "Education", "Catholic", "Infant.Mortality") post <- MCMCfactanal(Y, factors=2, lambda.constraints=list(Examination=list(1,"+"), Examination=list(2,"-"), Education=c(2,0), Infant.Mortality=c(1,0)), verbose=0, store.scores=FALSE, a0=1, b0=0.15, burnin=5000, mcmc=50000, thin=20) } } \references{ Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. } \seealso{ \code{\link[coda]{plot.mcmc}},\code{\link[coda]{summary.mcmc}},\code{\link[stats]{factanal}} } \keyword{models} MCMCpack/man/InvWishart.Rd0000644000176200001440000000163213564573453015011 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/distn.R \name{InvWishart} \alias{InvWishart} \alias{diwish} \alias{riwish} \title{The Inverse Wishart Distribution} \usage{ riwish(v, S) diwish(W, v, S) } \arguments{ \item{v}{Degrees of freedom (scalar).} \item{S}{Scale matrix \eqn{(p \times p)}.} \item{W}{Positive definite matrix W \eqn{(p \times p)}.} } \value{ \code{diwish} evaluates the density at positive definite matrix W. \code{riwish} generates one random draw from the distribution. } \description{ Density function and random generation from the Inverse Wishart distribution. } \details{ The mean of an inverse Wishart random variable with \code{v} degrees of freedom and scale matrix \code{S} is \eqn{(v-p-1)^{-1}S}. } \examples{ density <- diwish(matrix(c(2,-.3,-.3,4),2,2), 3, matrix(c(1,.3,.3,1),2,2)) draw <- riwish(3, matrix(c(1,.3,.3,1),2,2)) } \keyword{distribution} MCMCpack/man/NoncenHypergeom.Rd0000644000176200001440000000341513564573453016014 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/distn.R \name{NoncenHypergeom} \alias{NoncenHypergeom} \alias{rnoncenhypergeom} \alias{dnoncenhypergeom} \title{The Noncentral Hypergeometric Distribution} \source{ J. G. Liao and Ori Rosen. 2001. ``Fast and Stable Algorithms for Computing and Sampling From the Noncentral Hypergeometric Distribution." \emph{The American Statistician.} 55: 366-369. } \usage{ dnoncenhypergeom(x = NA, n1, n2, m1, psi) rnoncenhypergeom(n, n1, n2, m1, psi) } \arguments{ \item{x}{The location to evaluate the density. If \code{x} is NA, then a matrix is returned with the density evaluated at all possible points.} \item{n1}{The size of group one.} \item{n2}{The size of group two.} \item{m1}{The observed number of positive outcomes (in both groups).} \item{psi}{Odds ratio.} \item{n}{The number of draws to make from the distribution.} } \value{ \code{dnoncenhypergeom} evaluates the density at point \code{x}, or a matrix with the first column containing the possible values of the random variable, and the second column containing the probabilities. \code{rnoncenhypergeom} returns a list of \code{n} random draws from the distribution. } \description{ Evaluates the density at a single point or all points, and generate random draws from the Noncentral Hypergeometric distribution. } \details{ The Noncentral Hypergeometric is particularly useful for conditional inference for \eqn{(2 \times 2)} tables. We use the parameterization and algorithms of Liao and Rosen (2001). The underlying R code is based on their published code. See their article for details of the parameterization. } \examples{ density <- dnoncenhypergeom(NA, 500, 500, 500, 6.0) draws <- rnoncenhypergeom(10, 500, 500, 500, 6.0) } \keyword{distribution} MCMCpack/man/MCMCdynamicIRT1d.Rd0000644000176200001440000002714613564573453015613 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCdynamicIRT1d-b.R, R/MCMCdynamicIRT1d.R \name{MCMCdynamicIRT1d_b} \alias{MCMCdynamicIRT1d_b} \alias{MCMCdynamicIRT1d} \title{Markov Chain Monte Carlo for Dynamic One Dimensional Item Response Theory Model} \usage{ MCMCdynamicIRT1d_b(datamatrix, item.time.map, theta.constraints = list(), burnin = 1000, mcmc = 20000, thin = 1, verbose = 0, seed = NA, theta.start = NA, alpha.start = NA, beta.start = NA, tau2.start = 1, a0 = 0, A0 = 0.1, b0 = 0, B0 = 0.1, c0 = -1, d0 = -1, e0 = 0, E0 = 1, store.ability = TRUE, store.item = TRUE, ...) MCMCdynamicIRT1d(datamatrix, item.time.map, theta.constraints = list(), burnin = 1000, mcmc = 20000, thin = 1, verbose = 0, seed = NA, theta.start = NA, alpha.start = NA, beta.start = NA, tau2.start = 1, a0 = 0, A0 = 0.1, b0 = 0, B0 = 0.1, c0 = -1, d0 = -1, e0 = 0, E0 = 1, store.ability = TRUE, store.item = TRUE, ...) } \arguments{ \item{datamatrix}{The matrix of data. Must be 0, 1, or missing values. The rows of \code{datamatrix} correspond to subjects and the columns correspond to items.} \item{item.time.map}{A vector that relates each item to a time period. Each element of \code{item.time.map} gives the time period of the corresponding column of \code{datamatrix}. It is assumed that the minimum value of \code{item.time.map} is 1.} \item{theta.constraints}{A list specifying possible simple equality or inequality constraints on the ability parameters. A typical entry in the list has one of three forms: \code{varname=c} which will constrain the ability parameter for the subject named \code{varname} to be equal to c, \code{varname="+"} which will constrain the ability parameter for the subject named \code{varname} to be positive, and \code{varname="-"} which will constrain the ability parameter for the subject named \code{varname} to be negative. If x is a matrix without row names defaults names of ``V1",``V2", ... , etc will be used. See Rivers (2003) for a thorough discussion of identification of IRT models.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of Gibbs iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of Gibbs iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 then every \code{verbose}th iteration will be printed to the screen.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{theta.start}{The starting values for the subject abilities (ideal points). This can either be a scalar or a column vector with dimension equal to the number of voters. If this takes a scalar value, then that value will serve as the starting value for all of the thetas. The default value of NA will choose the starting values based on an eigenvalue-eigenvector decomposition of the aggreement score matrix formed from the \code{datamatrix}.} \item{alpha.start}{The starting values for the \eqn{\alpha} difficulty parameters. This can either be a scalar or a column vector with dimension equal to the number of items. If this takes a scalar value, then that value will serve as the starting value for all of the alphas. The default value of NA will set the starting values based on a series of probit regressions that condition on the starting values of theta.} \item{beta.start}{The starting values for the \eqn{\beta} discrimination parameters. This can either be a scalar or a column vector with dimension equal to the number of items. If this takes a scalar value, then that value will serve as the starting value for all of the betas. The default value of NA will set the starting values based on a series of probit regressions that condition on the starting values of theta.} \item{tau2.start}{The starting values for the evolution variances (the variance of the random walk increments for the ability parameters / ideal points. Order corresponds to the rows of \code{datamatrix}.} \item{a0}{A vector containing the prior mean of each of the difficulty parameters \eqn{\alpha}. Should have as many elements as items / roll calls. Order corresponds to the columns of \code{datamatrix}. If a scalar is passed it is assumed that all elements of \code{a0} are equal to the scalar.} \item{A0}{A vector containing the prior precision (inverse variance) of each of the difficulty parameters \eqn{\alpha}. Should have as many elements as items / roll calls. Order corresponds to the columns of \code{datamatrix}. If a scalar is passed it is assumed that all elements of \code{A0} are equal to the scalar.} \item{b0}{A vector containing the prior mean of each of the discrimination parameters \eqn{\beta}. Should have as many elements as items / roll calls. Order corresponds to the columns of \code{datamatrix}. If a scalar is passed it is assumed that all elements of \code{b0} are equal to the scalar.} \item{B0}{A vector containing the prior precision (inverse variance) of each of the discrimination parameters \eqn{\beta}. Should have as many elements as items / roll calls. Order corresponds to the columns of \code{datamatrix}. If a scalar is passed it is assumed that all elements of \code{B0} are equal to the scalar.} \item{c0}{\eqn{c_{0/2}} is the shape parameter for the inverse Gamma prior on \eqn{\tau^2} (the variance of the random walk increments). The amount of information in the inverse Gamma prior is something like that from \eqn{c_0} pseudo-observations. \code{c0} can be either a vector with an element for each subject or a scalar. If \code{c0} is negative then \eqn{\tau^2} is not estimated-- the values in \code{tau2.start} are used throughout the sampling.} \item{d0}{\eqn{d_{0/2}} is the scale parameter for the inverse Gamma prior on \eqn{\tau^2} (the variance of the random walk increments). In constructing the inverse Gamma prior, \eqn{d_0} acts like the sum of squared errors from the \eqn{c_0} pseudo-observations. \code{d0} can be either a vector with an element for each subject or a scalar. If \code{d0} is negative then \eqn{\tau^2} is not estimated-- the values in \code{tau2.start} are used throughout the sampling.} \item{e0}{A vector containing the prior mean of the initial ability parameter / ideal point for each subject. Should have as many elements as subjects. Order corresponds to the rows of \code{datamatrix}. If a scalar is passed it is assumed that all elements of \code{e0} are equal to the scalar.} \item{E0}{A vector containing the prior variance of the initial ability parameter / ideal point for each subject. Should have as many elements as subjects. Order corresponds to the rows of \code{datamatrix}. If a scalar is passed it is assumed that all elements of \code{E0} are equal to the scalar.} \item{store.ability}{A switch that determines whether or not to store the ability parameters for posterior analysis. \emph{NOTE}: In situations with many individuals storing the ability parameters takes an enormous amount of memory, so \code{store.ability} should only be \code{TRUE} if the chain is thinned heavily, or for applications with a small number of individuals. By default, the item parameters are stored.} \item{store.item}{A switch that determines whether or not to store the item parameters for posterior analysis. \emph{NOTE}: In situations with many items storing the item parameters takes an enormous amount of memory, so \code{store.item} should only be \code{FALSE} if the chain is thinned heavily, or for applications with a small number of items. By default, the item parameters are not stored.} \item{\dots}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a dynamic one dimensional item response theory (IRT) model, with Normal random walk priors on the subject abilities (ideal points), and multivariate Normal priors on the item parameters. The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMCdynamicIRT1d} simulates from the posterior distribution using the algorithm of Martin and Quinn (2002). The simulation proper is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. The model takes the following form. We assume that each subject has an subject ability (ideal point) denoted \eqn{\theta_{j,t}} (where \eqn{j} indexes subjects and \eqn{t} indexes time periods) and that each item has a difficulty parameter \eqn{\alpha_i} and discrimination parameter \eqn{\beta_i}. The observed choice by subject \eqn{j} on item \eqn{i} is the observed data matrix which is \eqn{(I \times J)}. We assume that the choice is dictated by an unobserved utility: \deqn{z_{i,j,t} = -\alpha_i + \beta_i \theta_{j,t} + \varepsilon_{i,j,t}} Where the disturbances are assumed to be distributed standard Normal. The parameters of interest are the subject abilities (ideal points) and the item parameters. We assume the following priors. For the subject abilities (ideal points): \deqn{\theta_{j,t} \sim \mathcal{N}(\theta_{j,t-1}, \tau^2_j)} with \deqn{\theta_{j,0} \sim \mathcal{N}(e0, E0)}. The evolution variance has the following prior: \deqn{\tau^2_j \sim \mathcal{IG}(c0/2, d0/2)}. For the item parameters in the standard model, the prior is: \deqn{\alpha_i \sim \mathcal{N}(a0, A0^{-1})} and \deqn{\beta_i \sim \mathcal{N}(b0, B0^{-1})}. The model is identified by the proper priors on the item parameters and constraints placed on the ability parameters. As is the case with all measurement models, make sure that you have plenty of free memory, especially when storing the item parameters. } \examples{ \dontrun{ data(Rehnquist) ## assign starting values theta.start <- rep(0, 9) theta.start[2] <- -3 ## Stevens theta.start[7] <- 2 ## Thomas out <- MCMCdynamicIRT1d(t(Rehnquist[,1:9]), item.time.map=Rehnquist$time, theta.start=theta.start, mcmc=50000, burnin=20000, thin=5, verbose=500, tau2.start=rep(0.1, 9), e0=0, E0=1, a0=0, A0=1, b0=0, B0=1, c0=-1, d0=-1, store.item=FALSE, theta.constraints=list(Stevens="-", Thomas="+")) summary(out) } } \references{ Andrew D. Martin and Kevin M. Quinn. 2002. "Dynamic Ideal Point Estimation via Markov Chain Monte Carlo for the U.S. Supreme Court, 1953-1999." \emph{Political Analysis.} 10: 134-153. Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. } \seealso{ \code{\link[coda]{plot.mcmc}},\code{\link[coda]{summary.mcmc}}, \code{\link[MCMCpack]{MCMCirt1d}} } \author{ Kevin M. Quinn } \keyword{models} MCMCpack/man/MCMCprobitChange.Rd0000644000176200001440000001643713564573453015771 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCprobitChange.R \name{MCMCprobitChange} \alias{MCMCprobitChange} \title{Markov Chain Monte Carlo for a linear Gaussian Multiple Changepoint Model} \usage{ MCMCprobitChange(formula, data = parent.frame(), m = 1, burnin = 10000, mcmc = 10000, thin = 1, verbose = 0, seed = NA, beta.start = NA, P.start = NA, b0 = NULL, B0 = NULL, a = NULL, b = NULL, marginal.likelihood = c("none", "Chib95"), ...) } \arguments{ \item{formula}{Model formula.} \item{data}{Data frame.} \item{m}{The number of changepoints.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of MCMC iterations after burnin.} \item{thin}{The thinning interval used in the simulation. The number of MCMC iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the \eqn{\beta} vector, and the error variance are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{beta.start}{The starting values for the \eqn{\beta} vector. This can either be a scalar or a column vector with dimension equal to the number of betas. The default value of of NA will use the MLE estimate of \eqn{\beta} as the starting value. If this is a scalar, that value will serve as the starting value mean for all of the betas.} \item{P.start}{The starting values for the transition matrix. A user should provide a square matrix with dimension equal to the number of states. By default, draws from the \code{Beta(0.9, 0.1)} are used to construct a proper transition matrix for each raw except the last raw.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of beta. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{a}{\eqn{a} is the shape1 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{b}{\eqn{b} is the shape2 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{marginal.likelihood}{How should the marginal likelihood be calculated? Options are: \code{none} in which case the marginal likelihood will not be calculated, and \code{Chib95} in which case the method of Chib (1995) is used.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. The object contains an attribute \code{prob.state} storage matrix that contains the probability of \eqn{state_i} for each period, the log-likelihood of the model (\code{loglike}), and the log-marginal likelihood of the model (\code{logmarglike}). } \description{ This function generates a sample from the posterior distribution of a linear Gaussian model with multiple changepoints. The function uses the Markov chain Monte Carlo method of Chib (1998). The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMCprobitChange} simulates from the posterior distribution of a probit regression model with multiple parameter breaks. The simulation is based on Chib (1998) and Park (2011). The model takes the following form: \deqn{\Pr(y_t = 1) = \Phi(x_i'\beta_m) \;\; m = 1, \ldots, M} Where \eqn{M} is the number of states, and \eqn{\beta_m} is a parameter when a state is \eqn{m} at \eqn{t}. We assume Gaussian distribution for prior of \eqn{\beta}: \deqn{\beta_m \sim \mathcal{N}(b_0,B_0^{-1}),\;\; m = 1, \ldots, M} And: \deqn{p_{mm} \sim \mathcal{B}eta(a, b),\;\; m = 1, \ldots, M} Where \eqn{M} is the number of states. } \examples{ \dontrun{ set.seed(1973) x1 <- rnorm(300, 0, 1) true.beta <- c(-.5, .2, 1) true.alpha <- c(.1, -1., .2) X <- cbind(1, x1) ## set two true breaks at 100 and 200 true.phi1 <- pnorm(true.alpha[1] + x1[1:100]*true.beta[1]) true.phi2 <- pnorm(true.alpha[2] + x1[101:200]*true.beta[2]) true.phi3 <- pnorm(true.alpha[3] + x1[201:300]*true.beta[3]) ## generate y y1 <- rbinom(100, 1, true.phi1) y2 <- rbinom(100, 1, true.phi2) y3 <- rbinom(100, 1, true.phi3) Y <- as.ts(c(y1, y2, y3)) ## fit multiple models with a varying number of breaks out0 <- MCMCprobitChange(formula=Y~X-1, data=parent.frame(), m=0, mcmc=1000, burnin=1000, thin=1, verbose=1000, b0 = 0, B0 = 10, a = 1, b = 1, marginal.likelihood = c("Chib95")) out1 <- MCMCprobitChange(formula=Y~X-1, data=parent.frame(), m=1, mcmc=1000, burnin=1000, thin=1, verbose=1000, b0 = 0, B0 = 10, a = 1, b = 1, marginal.likelihood = c("Chib95")) out2 <- MCMCprobitChange(formula=Y~X-1, data=parent.frame(), m=2, mcmc=1000, burnin=1000, thin=1, verbose=1000, b0 = 0, B0 = 10, a = 1, b = 1, marginal.likelihood = c("Chib95")) out3 <- MCMCprobitChange(formula=Y~X-1, data=parent.frame(), m=3, mcmc=1000, burnin=1000, thin=1, verbose=1000, b0 = 0, B0 = 10, a = 1, b = 1, marginal.likelihood = c("Chib95")) ## find the most reasonable one BayesFactor(out0, out1, out2, out3) ## draw plots using the "right" model plotState(out2) plotChangepoint(out2) } } \references{ Jong Hee Park. 2011. ``Changepoint Analysis of Binary and Ordinal Probit Models: An Application to Bank Rate Policy Under the Interwar Gold Standard." \emph{Political Analysis}. 19: 188-204. Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Siddhartha Chib. 1998. ``Estimation and comparison of multiple change-point models.'' \emph{Journal of Econometrics}. 86: 221-241. Albert, J. H. and S. Chib. 1993. ``Bayesian Analysis of Binary and Polychotomous Response Data.'' \emph{J. Amer. Statist. Assoc.} 88, 669-679 } \seealso{ \code{\link{plotState}}, \code{\link{plotChangepoint}} } \keyword{models} MCMCpack/man/Dirichlet.Rd0000644000176200001440000000222113564573453014615 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/distn.R \name{Dirichlet} \alias{Dirichlet} \alias{ddirichlet} \alias{rdirichlet} \title{The Dirichlet Distribution} \usage{ ddirichlet(x, alpha) rdirichlet(n, alpha) } \arguments{ \item{x}{A vector containing a single deviate or matrix containing one random deviate per row.} \item{alpha}{Vector of shape parameters, or matrix of shape parameters corresponding to the number of draw.} \item{n}{Number of random vectors to generate.} } \value{ \code{ddirichlet} gives the density. \code{rdirichlet} returns a matrix with \code{n} rows, each containing a single Dirichlet random deviate. } \description{ Density function and random generation from the Dirichlet distribution. } \details{ The Dirichlet distribution is the multidimensional generalization of the beta distribution. } \examples{ density <- ddirichlet(c(.1,.2,.7), c(1,1,1)) draws <- rdirichlet(20, c(1,1,1) ) } \seealso{ \code{\link[stats]{Beta}} } \author{ Code is taken from Greg's Miscellaneous Functions (gregmisc). His code was based on code posted by Ben Bolker to R-News on 15 Dec 2000. } \keyword{distribution} MCMCpack/man/MCMCnegbin.Rd0000644000176200001440000001462113564573453014617 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCnegbin.R \name{MCMCnegbin} \alias{MCMCnegbin} \title{Markov Chain Monte Carlo for Negative Binomial Regression} \usage{ MCMCnegbin(formula, data = parent.frame(), b0 = 0, B0 = 1, e = 2, f = 2, g = 10, burnin = 1000, mcmc = 1000, thin = 1, verbose = 0, seed = NA, beta.start = NA, rho.start = NA, rho.step = 0.1, nu.start = NA, marginal.likelihood = c("none", "Chib95"), ...) } \arguments{ \item{formula}{Model formula.} \item{data}{Data frame.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of \eqn{\beta}. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{e}{The hyperprior for the distribution \eqn{\rho}. See details.} \item{f}{The hyperprior for the distribution \eqn{\rho}. See details.} \item{g}{The hyperprior for the distribution \eqn{\rho}. See details.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of Metropolis iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of mcmc iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the current beta vector, and the Metropolis acceptance rate are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{beta.start}{The starting value for the \eqn{\beta} vector. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the starting value for all of the betas. The default value of NA will use the maximum likelihood estimate of \eqn{\beta} as the starting value.} \item{rho.start}{The starting value for the \eqn{\rho} variable. The default value is 1.} \item{rho.step}{Tuning parameter for the slice sampling approach to sampling \eqn{rho}. Determines the size of the step-out used to find the correct slice to draw from. Lower values are more accurate, but will take longer (up to a fixed searching limit). Default is 0.1.} \item{nu.start}{The starting values for the random effect, \eqn{\nu}. The default value is a vector of ones.} \item{marginal.likelihood}{How should the marginal likelihood be calculated? Options are: \code{none} in which case the marginal likelihood will not be calculated or \code{Laplace} in which case the Laplace approximation (see Kass and Raftery, 1995) is used.} \item{...}{further arguments to be passed.} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a Negative Binomial regression model via auxiliary mixture sampling. The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMCnegbin} simulates from the posterior distribution of a Negative Binomial regression model using a combination of auxiliary mixture sampling and slice sampling. The simulation proper is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. The model takes the following form: \deqn{y_i \sim \mathcal{P}oisson(\nu_i\mu_i)} Where the inverse link function: \deqn{\mu_i = \exp(x_i'\beta)} We assume a multivariate Normal prior on \eqn{\beta}: \deqn{\beta \sim \mathcal{N}(b_0,B_0^{-1})} The unit-level random effect that handles overdispersion is assumed to be distributed Gamma: \deqn{\nu_i \sim \mathcal{G}amma(\rho, \rho)} The overdispersion parameter has a prior with the following form: \deqn{f(\rho|e,f,g) \propto \rho^{e-1}(\rho + g)^{-(e+f)}} The model is simulated via blocked Gibbs, with the the \eqn{\beta} being simulated via the auxiliary mixture sampling method of Fuerhwirth-Schanetter et al. (2009). The \eqn{\rho} is updated via slice sampling. The \eqn{\nu_i} are updated their (conjugate) full conditional, which is also Gamma. } \examples{ \dontrun{ n <- 150 mcmcs <- 5000 burnin <- 5000 thin <- 5 x1 <- runif(n, 0, 2) rho.true <- 1.5 nu.true <- rgamma(n, rho.true, rho.true) mu <- nu.true * exp(1 + x1 * 1) y <- rpois(n, mu) posterior <- MCMCnegbin(y ~ x1) plot(posterior) summary(posterior) } } \references{ Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. Sylvia Fruehwirth-Schnatter, Rudolf Fruehwirth, Leonhard Held, and Havard Rue. 2009. ``Improved auxiliary mixture sampling for hierarchical models of non-Gaussian data'', \emph{Statistics and Computing} 19(4): 479-492. \url{http://doi.org/10.1007/s11222-008-9109-4} } \seealso{ \code{\link[coda]{plot.mcmc}},\code{\link[coda]{summary.mcmc}}, \code{\link[MASS]{glm.nb}} } \keyword{models} MCMCpack/man/MCnormalnormal.Rd0000644000176200001440000000321613564573453015634 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCmodels.R \name{MCnormalnormal} \alias{MCnormalnormal} \title{Monte Carlo Simulation from a Normal Likelihood (with known variance) with a Normal Prior} \usage{ MCnormalnormal(y, sigma2, mu0, tau20, mc = 1000, ...) } \arguments{ \item{y}{The data.} \item{sigma2}{The known variance of y.} \item{mu0}{The prior mean of mu.} \item{tau20}{The prior variance of mu.} \item{mc}{The number of Monte Carlo draws to make.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a Normal likelihood (with known variance) with a Normal prior. } \details{ \code{MCnormalnormal} directly simulates from the posterior distribution. This model is designed primarily for instructional use. \eqn{\mu} is the parameter of interest of the Normal distribution. We assume a conjugate normal prior: \deqn{\mu \sim \mathcal{N}(\mu_0, \tau^2_0)} \eqn{y} is a vector of observed data. } \examples{ \dontrun{ y <- c(2.65, 1.80, 2.29, 2.11, 2.27, 2.61, 2.49, 0.96, 1.72, 2.40) posterior <- MCMCpack:::MCnormalnormal(y, 1, 0, 1, 5000) summary(posterior) plot(posterior) grid <- seq(-3,3,0.01) plot(grid, dnorm(grid, 0, 1), type="l", col="red", lwd=3, ylim=c(0,1.4), xlab="mu", ylab="density") lines(density(posterior), col="blue", lwd=3) legend(-3, 1.4, c("prior", "posterior"), lwd=3, col=c("red", "blue")) } } \seealso{ \code{\link[coda]{plot.mcmc}}, \code{\link[coda]{summary.mcmc}} } \keyword{models} MCMCpack/man/MCMCpoissonChange.Rd0000644000176200001440000002064013564573453016153 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCpoissonChange.R \name{MCMCpoissonChange} \alias{MCMCpoissonChange} \title{Markov Chain Monte Carlo for a Poisson Regression Changepoint Model} \usage{ MCMCpoissonChange(formula, data = parent.frame(), m = 1, b0 = 0, B0 = 1, a = NULL, b = NULL, c0 = NA, d0 = NA, lambda.mu = NA, lambda.var = NA, burnin = 1000, mcmc = 1000, thin = 1, verbose = 0, seed = NA, beta.start = NA, P.start = NA, marginal.likelihood = c("none", "Chib95"), ...) } \arguments{ \item{formula}{Model formula.} \item{data}{Data frame.} \item{m}{The number of changepoints.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of beta. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{a}{\eqn{a} is the shape1 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{b}{\eqn{b} is the shape2 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{c0}{\eqn{c_0} is the shape parameter for Gamma prior on \eqn{\lambda} (the mean). When there is no covariate, this should be provided by users. No default value is provided.} \item{d0}{\eqn{d_0} is the scale parameter for Gamma prior on \eqn{\lambda} (the mean). When there is no covariate, this should be provided by users. No default value is provided.} \item{lambda.mu}{The mean of the Gamma prior on \eqn{\lambda}. \eqn{sigma.mu} and \eqn{sigma.var} allow users to choose the Gamma prior by choosing its mean and variance.} \item{lambda.var}{The variacne of the Gamma prior on \eqn{\lambda}. \eqn{sigma.mu} and \eqn{sigma.var} allow users to choose the Gamma prior by choosing its mean and variance.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of MCMC iterations after burn-in.} \item{thin}{The thinning interval used in the simulation. The number of MCMC iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0, the iteration number and the posterior density samples are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, current R system seed is used.} \item{beta.start}{The starting values for the beta vector. This can either be a scalar or a column vector with dimension equal to the number of betas. The default value of NA will use draws from the Uniform distribution with the same boundary with the data as the starting value. If this is a scalar, that value will serve as the starting value mean for all of the betas. When there is no covariate, the log value of means should be used.} \item{P.start}{The starting values for the transition matrix. A user should provide a square matrix with dimension equal to the number of states. By default, draws from the \code{Beta(0.9, 0.1)} are used to construct a proper transition matrix for each raw except the last raw.} \item{marginal.likelihood}{How should the marginal likelihood be calculated? Options are: \code{none} in which case the marginal likelihood will not be calculated, and \code{Chib95} in which case the method of Chib (1995) is used.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. The object contains an attribute \code{prob.state} storage matrix that contains the probability of \eqn{state_i} for each period, and the log-marginal likelihood of the model (\code{logmarglike}). } \description{ This function generates a sample from the posterior distribution of a Poisson regression model with multiple changepoints. The function uses the Markov chain Monte Carlo method of Chib (1998). The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMCpoissonChange} simulates from the posterior distribution of a Poisson regression model with multiple changepoints using the methods of Chib (1998) and Fruhwirth-Schnatter and Wagner (2006). The details of the model are discussed in Park (2010). The model takes the following form: \deqn{y_t \sim \mathcal{P}oisson(\mu_t)} \deqn{\mu_t = x_t ' \beta_m,\;\; m = 1, \ldots, M} Where \eqn{M} is the number of states and \eqn{\beta_m} is paramters when a state is \eqn{m} at \eqn{t}. We assume Gaussian distribution for prior of \eqn{\beta}: \deqn{\beta_m \sim \mathcal{N}(b_0,B_0^{-1}),\;\; m = 1, \ldots, M} And: \deqn{p_{mm} \sim \mathcal{B}eta(a, b),\;\; m = 1, \ldots, M} Where \eqn{M} is the number of states. } \examples{ \dontrun{ set.seed(11119) n <- 150 x1 <- runif(n, 0, 0.5) true.beta1 <- c(1, 1) true.beta2 <- c(1, -2) true.beta3 <- c(1, 2) ## set true two breaks at (50, 100) true.s <- rep(1:3, each=n/3) mu1 <- exp(1 + x1[true.s==1]*1) mu2 <- exp(1 + x1[true.s==2]*-2) mu3 <- exp(1 + x1[true.s==3]*2) y <- as.ts(c(rpois(n/3, mu1), rpois(n/3, mu2), rpois(n/3, mu3))) formula = y ~ x1 ## fit multiple models with a varying number of breaks model0 <- MCMCpoissonChange(formula, m=0, mcmc = 1000, burnin = 1000, verbose = 500, b0 = rep(0, 2), B0 = 5*diag(2), marginal.likelihood = "Chib95") model1 <- MCMCpoissonChange(formula, m=1, mcmc = 1000, burnin = 1000, verbose = 500, b0 = rep(0, 2), B0 = 5*diag(2), marginal.likelihood = "Chib95") model2 <- MCMCpoissonChange(formula, m=2, mcmc = 1000, burnin = 1000, verbose = 500, b0 = rep(0, 2), B0 = 5*diag(2), marginal.likelihood = "Chib95") model3 <- MCMCpoissonChange(formula, m=3, mcmc = 1000, burnin = 1000, verbose = 500, b0 = rep(0, 2), B0 = 5*diag(2), marginal.likelihood = "Chib95") model4 <- MCMCpoissonChange(formula, m=4, mcmc = 1000, burnin = 1000, verbose = 500, b0 = rep(0, 2), B0 = 5*diag(2), marginal.likelihood = "Chib95") model5 <- MCMCpoissonChange(formula, m=5, mcmc = 1000, burnin = 1000, verbose = 500, b0 = rep(0, 2), B0 = 5*diag(2), marginal.likelihood = "Chib95") ## find the most reasonable one print(BayesFactor(model0, model1, model2, model3, model4, model5)) ## draw plots using the "right" model par(mfrow=c(attr(model2, "m") + 1, 1), mai=c(0.4, 0.6, 0.3, 0.05)) plotState(model2, legend.control = c(1, 0.6)) plotChangepoint(model2, verbose = TRUE, ylab="Density", start=1, overlay=TRUE) ## No covariate case model2.1 <- MCMCpoissonChange(y ~ 1, m = 2, c0 = 2, d0 = 1, mcmc = 1000, burnin = 1000, verbose = 500, marginal.likelihood = "Chib95") print(BayesFactor(model2, model2.1)) } } \references{ Jong Hee Park. 2010. ``Structural Change in the U.S. Presidents' Use of Force Abroad.'' \emph{American Journal of Political Science} 54: 766-782. Sylvia Fruhwirth-Schnatter and Helga Wagner 2006. ``Auxiliary Mixture Sampling for Parameter-driven Models of Time Series of Counts with Applications to State Space Modelling.'' \emph{Biometrika}. 93:827--841. Siddhartha Chib. 1998. ``Estimation and comparison of multiple change-point models.'' \emph{Journal of Econometrics}. 86: 221-241. Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Siddhartha Chib. 1995. ``Marginal Likelihood from the Gibbs Output.'' \emph{Journal of the American Statistical Association}. 90: 1313-1321. } \seealso{ \code{\link{MCMCbinaryChange}}, \code{\link{plotState}}, \code{\link{plotChangepoint}} } \keyword{models} MCMCpack/man/MCMCnegbinChange.Rd0000644000176200001440000002164513564573453015731 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCnegbinChange.R \name{MCMCnegbinChange} \alias{MCMCnegbinChange} \title{Markov Chain Monte Carlo for Negative Binomial Regression Changepoint Model} \usage{ MCMCnegbinChange(formula, data = parent.frame(), m = 1, fixed.m = TRUE, b0 = 0, B0 = 1, a = NULL, b = NULL, e = 2, f = 2, g = 10, burnin = 1000, mcmc = 1000, thin = 1, verbose = 0, seed = NA, beta.start = NA, P.start = NA, rho.start = NA, rho.step, nu.start = NA, marginal.likelihood = c("none", "Chib95"), ...) } \arguments{ \item{formula}{Model formula.} \item{data}{Data frame.} \item{m}{The number of changepoints.} \item{fixed.m}{A logical indicator for whether or not the number of changepoints in the sampler should be exactly equal to \code{m} or if that is simply an upper bound. Setting \code{fixed.m} to \code{FALSE} is equivalent to assuming a weak-limit approximation to a Dirichlet process mixture.} \item{b0}{The prior mean of \eqn{\beta}. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.} \item{B0}{The prior precision of \eqn{\beta}. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of beta. Default value of 0 is equivalent to an improper uniform prior for beta.} \item{a}{\eqn{a} is the shape1 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{b}{\eqn{b} is the shape2 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{e}{The hyperprior for the distribution \eqn{\rho} See details.} \item{f}{The hyperprior for the distribution \eqn{\rho}. See details.} \item{g}{The hyperprior for the distribution \eqn{\rho}. See details.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of Metropolis iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of mcmc iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number, the current beta vector, and the Metropolis acceptance rate are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{beta.start}{The starting value for the \eqn{\beta} vector. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the starting value for all of the betas. The default value of NA will use the maximum likelihood estimate of \eqn{\beta} as the starting value for all regimes.} \item{P.start}{The starting values for the transition matrix. A user should provide a square matrix with dimension equal to the number of states. By default, draws from the \code{Beta(0.9, 0.1)} are used to construct a proper transition matrix for each raw except the last raw.} \item{rho.start}{The starting value for the \eqn{\rho} variable. This can either be a scalar or a column vector with dimension equal to the number of regimes. If the value is scalar, it will be used for all regimes. The default value is a vector of ones.} \item{rho.step}{Tuning parameter for the slice sampling approach to sampling \eqn{rho}. Determines the size of the step-out used to find the correct slice to draw from. Lower values are more accurate, but will take longer (up to a fixed searching limit). Default is 0.1.} \item{nu.start}{The starting values for the random effect, \eqn{\nu}. The default value is a vector of ones.} \item{marginal.likelihood}{How should the marginal likelihood be calculated? Options are: \code{none} in which case the marginal likelihood will not be calculated or \code{Laplace} in which case the Laplace approximation (see Kass and Raftery, 1995) is used.} \item{...}{further arguments to be passed.} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of a Negative Binomial regression model with multiple changepoints. For the changepoints, the sampler uses the Markov Chain Monte Carlo method of Chib (1998). The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMCnegbinChange}simulates from the posterior distribution of a Negative Binomial regression model with multiple changepoints using the methods of Chib (1998) and Fruehwirth-Schnatter et al (2009). The details of the model are discussed in Blackwell (2017). The model takes the following form: \deqn{y_t \sim \mathcal{P}oisson(\nu_t\mu_t)} \deqn{\mu_t = x_t ' \beta_m,\;\; m = 1, \ldots, M} \deqn{\nu_t \sim \mathcal{G}amma(\rho_m, \rho_m)} Where \eqn{M} is the number of states and \eqn{\beta_m} and \eqn{\rho_m} are parameters when a state is \eqn{m} at \eqn{t}. We assume Gaussian distribution for prior of \eqn{\beta}: \deqn{\beta_m \sim \mathcal{N}(b_0,B_0^{-1}),\;\; m = 1, \ldots, M} And: \deqn{p_{mm} \sim \mathcal{B}eta(a, b),\;\; m = 1, \ldots, M} Where \eqn{M} is the number of states. The overdispersion parameters have a prior with the following form: \deqn{f(\rho_m|e,f,g) \propto \rho^{e-1}(\rho + g)^{-(e+f)}} The model is simulated via blocked Gibbs conditonal on the states. The \eqn{\beta} being simulated via the auxiliary mixture sampling method of Fuerhwirth-Schanetter et al. (2009). The \eqn{\rho} is updated via slice sampling. The \eqn{\nu_i} are updated their (conjugate) full conditional, which is also Gamma. The states are updated as in Chib (1998) } \examples{ \dontrun{ n <- 150 reg <- 3 true.s <- gl(reg, n/reg, n) rho.true <- c(1.5, 0.5, 3) b0.true <- c(1, 3, 1) b1.true <- c(1, -2, 2) x1 <- runif(n, 0, 2) nu.true <- rgamma(n, rho.true[true.s], rho.true[true.s]) mu <- nu.true * exp(b0.true[true.s] + x1 * b1.true[true.s]) y <- rpois(n, mu) posterior <- MCMCnegbinChange(y ~ x1, m = 2, verbose = 1000, marginal.likelihood = "Chib95", e = 2, f = 2, g = 10, b0 = rep(0, 2), B0 = (1/9) * diag(2), rho.step = rep(0.75, times = 3), seed = list(NA, 2)) par(mfrow=c(attr(posterior, "m") + 1, 1), mai=c(0.4, 0.6, 0.3, 0.05)) plotState(posterior, legend.control = c(1, 0.6)) plotChangepoint(posterior, verbose = TRUE, ylab="Density", start=1, overlay=TRUE) open.ended <- MCMCnegbinChange(y ~ x1, m = 10, verbose = 1000, fixed.m = FALSE, mcmc = 2000, burnin = 2000, e = 2, f = 2, g = 10, a = 100, b = 1, b0 = rep(0, 2), B0 = (1/9) * diag(2), rho.step = 0.75, seed = list(NA, 2)) plotState(open.ended, legend.control = c(1, 0.6)) } } \references{ Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. ``MCMCpack: Markov Chain Monte Carlo in R.'', \emph{Journal of Statistical Software}. 42(9): 1-21. \url{http://www.jstatsoft.org/v42/i09/}. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Sylvia Fruehwirth-Schnatter, Rudolf Fruehwirth, Leonhard Held, and Havard Rue. 2009. ``Improved auxiliary mixture sampling for hierarchical models of non-Gaussian data'', \emph{Statistics and Computing} 19(4): 479-492. \url{http://doi.org/10.1007/s11222-008-9109-4} Matthew Blackwell. 2017. ``Game Changers: Detecting Shifts in Overdispersed Count Data,'' \emph{Political Analysis} Forthcoming. \url{http://www.mattblackwell.org/files/papers/gamechangers-letter.pdf} } \seealso{ \code{\link{MCMCpoissonChange}}, \code{\link{plotState}}, \code{\link{plotChangepoint}} } \keyword{models} MCMCpack/man/testpanelSubjectBreak.Rd0000644000176200001440000001407313621126150017160 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/testpanelSubjectBreak.R \name{testpanelSubjectBreak} \alias{testpanelSubjectBreak} \title{A Test for the Subject-level Break using a Unitivariate Linear Regression Model with Breaks} \usage{ testpanelSubjectBreak(subject.id, time.id, resid, max.break = 2, minimum = 10, mcmc = 1000, burnin = 1000, thin = 1, verbose = 0, b0, B0, c0, d0, a = NULL, b = NULL, seed = NA, Time = NULL, ps.out = FALSE, ...) } \arguments{ \item{subject.id}{A numeric vector indicating the group number. It should start from 1.} \item{time.id}{A numeric vector indicating the time unit. It should start from 1.} \item{resid}{A vector of panel residuals.} \item{max.break}{An upper bound of break numbers for the test.} \item{minimum}{A minimum length of time series for the test. The test will skip a subject with a time series shorter than this.} \item{mcmc}{The number of MCMC iterations after burn-in.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of MCMC iterations must be divisible by this value.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0, the iteration number and the posterior density samples are printed to the screen every \code{verbose}th iteration.} \item{b0}{The prior mean of the residual mean.} \item{B0}{The prior precision of the residual variance} \item{c0}{\eqn{c_0/2} is the shape parameter for the inverse Gamma prior on \eqn{\sigma^2}. The amount of information in the inverse Gamma prior is something like that from \eqn{c_0} pseudo-observations.} \item{d0}{\eqn{d_0/2} is the scale parameter for the inverse Gamma prior on \eqn{\sigma^2}.} \item{a}{\eqn{a} is the shape1 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{b}{\eqn{b} is the shape2 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.} \item{seed}{The seed for the random number generator. If NA, current R system seed is used.} \item{Time}{Times of the observations. This will be used to find the time of the first observations in panel residuals.} \item{ps.out}{If ps.out == TRUE, state probabilities are exported. If the number of panel subjects is huge, users can turn it off to save memory.} \item{...}{further arguments to be passed} } \value{ The returned object is a matrix containing log marginal likelihoods for all HMMs. The dimension of the returned object is the number of panel subjects by max.break + 1. If psout == TRUE, the returned object has an array attribute \code{psout} containing state probabilities for all HMMs. } \description{ testpanelSubjectBreak fits a unitivariate linear regression model with parametric breaks using panel residuals to test the existence of subject-level breaks in panel residuals. The details are discussed in Park (2011). } \details{ \code{testpanelSubjectBreak} fits a univariate linear regression model for subject-level residuals from a panel model. The details are discussed in Park (2011). The model takes the following form: \deqn{e_{it} = \alpha_{im} + \varepsilon_{it}\;\; m = 1, \ldots, M} The errors are assumed to be time-varying at the subject level: \deqn{\varepsilon_{it} \sim \mathcal{N}(0, \sigma^2_{im})} We assume standard, semi-conjugate priors: \deqn{\beta \sim \mathcal{N}(b_0,B_0^{-1})} And: \deqn{\sigma^{-2} \sim \mathcal{G}amma(c_0/2, d_0/2)} Where \eqn{\beta} and \eqn{\sigma^{-2}} are assumed \emph{a priori} independent. And: \deqn{p_{mm} \sim \mathcal{B}eta(a, b),\;\; m = 1, \ldots, M} Where \eqn{M} is the number of states. OLS estimates are used for starting values. } \examples{ \dontrun{ set.seed(1974) N <- 30 T <- 80 NT <- N*T ## true parameter values true.beta <- c(1, 1) true.sigma <- 3 x1 <- rnorm(NT) x2 <- runif(NT, 2, 4) ## group-specific breaks break.point = rep(T/2, N); break.sigma=c(rep(1, N)); break.list <- rep(1, N) X <- as.matrix(cbind(x1, x2), NT, ); y <- rep(NA, NT) id <- rep(1:N, each=NT/N) K <- ncol(X); true.beta <- as.matrix(true.beta, K, 1) ## compute the break probability ruler <- c(1:T) W.mat <- matrix(NA, T, N) for (i in 1:N){ W.mat[, i] <- pnorm((ruler-break.point[i])/break.sigma[i]) } Weight <- as.vector(W.mat) ## draw time-varying individual effects and sample y j = 1 true.sigma.alpha <- 30 true.alpha1 <- true.alpha2 <- rep(NA, N) for (i in 1:N){ Xi <- X[j:(j+T-1), ] true.mean <- Xi \%*\% true.beta weight <- Weight[j:(j+T-1)] true.alpha1[i] <- rnorm(1, 0, true.sigma.alpha) true.alpha2[i] <- -1*true.alpha1[i] y[j:(j+T-1)] <- ((1-weight)*true.mean + (1-weight)*rnorm(T, 0, true.sigma) + (1-weight)*true.alpha1[i]) + (weight*true.mean + weight*rnorm(T, 0, true.sigma) + weight*true.alpha2[i]) j <- j + T } ## extract the standardized residuals from the OLS with fixed-effects FEols <- lm(y ~ X + as.factor(id) -1 ) resid.all <- rstandard(FEols) time.id <- rep(1:80, N) ## model fitting G <- 1000 BF <- testpanelSubjectBreak(subject.id=id, time.id=time.id, resid= resid.all, max.break=3, minimum = 10, mcmc=G, burnin = G, thin=1, verbose=G, b0=0, B0=1/100, c0=2, d0=2, Time = time.id) ## estimated break numbers ## thresho estimated.breaks <- make.breaklist(BF, threshold=3) ## print all posterior model probabilities print(attr(BF, "model.prob")) } } \references{ Jong Hee Park, 2012. ``Unified Method for Dynamic and Cross-Sectional Heterogeneity: Introducing Hidden Markov Panel Models.'' \emph{American Journal of Political Science}.56: 1040-1054. Siddhartha Chib. 1998. ``Estimation and comparison of multiple change-point models.'' \emph{Journal of Econometrics}. 86: 221-241. } \keyword{models} MCMCpack/man/MCMChregress.Rd0000644000176200001440000002100113564573453015165 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMChregress.R \name{MCMChregress} \alias{MCMChregress} \title{Markov Chain Monte Carlo for the Hierarchical Gaussian Linear Regression Model} \usage{ MCMChregress(fixed, random, group, data, burnin = 1000, mcmc = 10000, thin = 10, verbose = 1, seed = NA, beta.start = NA, sigma2.start = NA, Vb.start = NA, mubeta = 0, Vbeta = 1e+06, r, R, nu = 0.001, delta = 0.001, ...) } \arguments{ \item{fixed}{A two-sided linear formula of the form 'y~x1+...+xp' describing the fixed-effects part of the model, with the response on the left of a '~' operator and the p fixed terms, separated by '+' operators, on the right.} \item{random}{A one-sided formula of the form '~x1+...+xq' specifying the model for the random effects part of the model, with the q random terms, separated by '+' operators.} \item{group}{String indicating the name of the grouping variable in \code{data}, defining the hierarchical structure of the model.} \item{data}{A data frame containing the variables in the model.} \item{burnin}{The number of burnin iterations for the sampler.} \item{mcmc}{The number of Gibbs iterations for the sampler. Total number of Gibbs iterations is equal to \code{burnin+mcmc}. \code{burnin+mcmc} must be divisible by 10 and superior or equal to 100 so that the progress bar can be displayed.} \item{thin}{The thinning interval used in the simulation. The number of mcmc iterations must be divisible by this value.} \item{verbose}{A switch (0,1) which determines whether or not the progress of the sampler is printed to the screen. Default is 1: a progress bar is printed, indicating the step (in \%) reached by the Gibbs sampler.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister.} \item{beta.start}{The starting values for the \eqn{\beta} vector. This can either be a scalar or a p-length vector. The default value of NA will use the OLS \eqn{\beta} estimate of the corresponding Gaussian Linear Regression without random effects. If this is a scalar, that value will serve as the starting value mean for all of the betas.} \item{sigma2.start}{Scalar for the starting value of the residual error variance. The default value of NA will use the OLS estimates of the corresponding Gaussian Linear Regression without random effects.} \item{Vb.start}{The starting value for variance matrix of the random effects. This must be a square q-dimension matrix. Default value of NA uses an identity matrix.} \item{mubeta}{The prior mean of \eqn{\beta}. This can either be a scalar or a p-length vector. If this takes a scalar value, then that value will serve as the prior mean for all of the betas. The default value of 0 will use a vector of zeros for an uninformative prior.} \item{Vbeta}{The prior variance of \eqn{\beta}. This can either be a scalar or a square p-dimension matrix. If this takes a scalar value, then that value times an identity matrix serves as the prior variance of beta. Default value of 1.0E6 will use a diagonal matrix with very large variance for an uninformative flat prior.} \item{r}{The shape parameter for the Inverse-Wishart prior on variance matrix for the random effects. r must be superior or equal to q. Set r=q for an uninformative prior. See the NOTE for more details} \item{R}{The scale matrix for the Inverse-Wishart prior on variance matrix for the random effects. This must be a square q-dimension matrix. Use plausible variance regarding random effects for the diagonal of R. See the NOTE for more details} \item{nu}{The shape parameter for the Inverse-Gamma prior on the residual error variance. Default value is \code{nu=delta=0.001} for uninformative prior.} \item{delta}{The rate (1/scale) parameter for the Inverse-Gamma prior on the residual error variance. Default value is \code{nu=delta=0.001} for uninformative prior.} \item{...}{further arguments to be passed} } \value{ \item{mcmc}{An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. The posterior sample of the deviance \eqn{D}, with \eqn{D=-2\log(\prod_i P(y_i|\beta,b_i,\sigma^2))}, is also provided.} \item{Y.pred}{Predictive posterior mean for each observation.} } \description{ MCMChregress generates a sample from the posterior distribution of a Hierarchical Gaussian Linear Regression Model using Algorithm 2 of Chib and Carlin (1999). This model uses a multivariate Normal prior for the fixed effects parameters, an Inverse-Wishart prior on the random effects variance matrix, and an Inverse-Gamma prior on the residual error variance. The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ \code{MCMChregress} simulates from the posterior distribution sample using the blocked Gibbs sampler of Chib and Carlin (1999), Algorithm 2. The simulation is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. The model takes the following form: \deqn{y_i = X_i \beta + W_i b_i + \varepsilon_i} Where each group \eqn{i} have \eqn{k_i} observations. Where the random effects: \deqn{b_i \sim \mathcal{N}_q(0,V_b)} And the errors: \deqn{\varepsilon_i \sim \mathcal{N}(0, \sigma^2 I_{k_i})} We assume standard, conjugate priors: \deqn{\beta \sim \mathcal{N}_p(\mu_{\beta},V_{\beta})} And: \deqn{\sigma^{2} \sim \mathcal{IG}amma(\nu, 1/\delta)} And: \deqn{V_b \sim \mathcal{IW}ishart(r, rR)} See Chib and Carlin (1999) for more details. \emph{NOTE:} We do not provide default parameters for the priors on the precision matrix for the random effects. When fitting one of these models, it is of utmost importance to choose a prior that reflects your prior beliefs about the random effects. Using the \code{dwish} and \code{rwish} functions might be useful in choosing these values. } \examples{ \dontrun{ #======================================== # Hierarchical Gaussian Linear Regression #======================================== #== Generating data # Constants nobs <- 1000 nspecies <- 20 species <- c(1:nspecies,sample(c(1:nspecies),(nobs-nspecies),replace=TRUE)) # Covariates X1 <- runif(n=nobs,min=0,max=10) X2 <- runif(n=nobs,min=0,max=10) X <- cbind(rep(1,nobs),X1,X2) W <- X # Target parameters # beta beta.target <- matrix(c(0.1,0.3,0.2),ncol=1) # Vb Vb.target <- c(0.5,0.2,0.1) # b b.target <- cbind(rnorm(nspecies,mean=0,sd=sqrt(Vb.target[1])), rnorm(nspecies,mean=0,sd=sqrt(Vb.target[2])), rnorm(nspecies,mean=0,sd=sqrt(Vb.target[3]))) # sigma2 sigma2.target <- 0.02 # Response Y <- vector() for (n in 1:nobs) { Y[n] <- rnorm(n=1, mean=X[n,]\%*\%beta.target+W[n,]\%*\%b.target[species[n],], sd=sqrt(sigma2.target)) } # Data-set Data <- as.data.frame(cbind(Y,X1,X2,species)) plot(Data$X1,Data$Y) #== Call to MCMChregress model <- MCMChregress(fixed=Y~X1+X2, random=~X1+X2, group="species", data=Data, burnin=1000, mcmc=1000, thin=1,verbose=1, seed=NA, beta.start=0, sigma2.start=1, Vb.start=1, mubeta=0, Vbeta=1.0E6, r=3, R=diag(c(1,0.1,0.1)), nu=0.001, delta=0.001) #== MCMC analysis # Graphics pdf("Posteriors-MCMChregress.pdf") plot(model$mcmc) dev.off() # Summary summary(model$mcmc) # Predictive posterior mean for each observation model$Y.pred # Predicted-Observed plot(Data$Y,model$Y.pred) abline(a=0,b=1) } } \references{ Siddhartha Chib and Bradley P. Carlin. 1999. ``On MCMC Sampling in Hierarchical Longitudinal Models.'' \emph{Statistics and Computing.} 9: 17-26. Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. \emph{Scythe Statistical Library 1.0.} \url{http://scythe.lsa.umich.edu}. Andrew D. Martin and Kyle L. Saunders. 2002. ``Bayesian Inference for Political Science Panel Data.'' Paper presented at the 2002 Annual Meeting of the American Political Science Association. Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. ``Output Analysis and Diagnostics for MCMC (CODA)'', \emph{R News}. 6(1): 7-11. \url{https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf}. } \seealso{ \code{\link[coda]{plot.mcmc}}, \code{\link[coda]{summary.mcmc}} } \author{ Ghislain Vieilledent } \keyword{Gaussian} \keyword{MCMC} \keyword{bayesian} \keyword{hierarchical} \keyword{mixed} \keyword{models} MCMCpack/man/plotChangepoint.Rd0000644000176200001440000000231213564573453016045 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/btsutil.R \name{plotChangepoint} \alias{plotChangepoint} \title{Posterior Density of Regime Change Plot} \usage{ plotChangepoint(mcmcout, main = "Posterior Density of Regime Change Probabilities", xlab = "Time", ylab = "", verbose = FALSE, start = 1, overlay = FALSE) } \arguments{ \item{mcmcout}{The \code{mcmc} object containing the posterior density sample from a changepoint model. Note that this must have a \code{prob.state} attribute.} \item{main}{Title of the plot} \item{xlab}{Label for the x-axis.} \item{ylab}{Label for the y-axis.} \item{verbose}{If \code{verbose=TRUE}, expected changepoints are printed.} \item{start}{The time of the first observation to be shown in the time series plot.} \item{overlay}{If \code{overlay=TRUE}, the probability of each regime change is drawn separately, which will be useful to draw multiple plots in one screen. See the example in \code{MCMCpoissonChange}. Otherwise, multiple plots of regime change probabilities will be drawn.} } \description{ Plot the posterior density of regime change. } \seealso{ \code{\link{MCMCpoissonChange}}, \code{\link{MCMCbinaryChange}} } \keyword{hplot} MCMCpack/man/MCMCordfactanal.Rd0000644000176200001440000002223013564573453015626 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/MCMCordfactanal.R \name{MCMCordfactanal} \alias{MCMCordfactanal} \title{Markov Chain Monte Carlo for Ordinal Data Factor Analysis Model} \usage{ MCMCordfactanal(x, factors, lambda.constraints = list(), data = parent.frame(), burnin = 1000, mcmc = 20000, thin = 1, tune = NA, verbose = 0, seed = NA, lambda.start = NA, l0 = 0, L0 = 0, store.lambda = TRUE, store.scores = FALSE, drop.constantvars = TRUE, ...) } \arguments{ \item{x}{Either a formula or a numeric matrix containing the manifest variables.} \item{factors}{The number of factors to be fitted.} \item{lambda.constraints}{List of lists specifying possible equality or simple inequality constraints on the factor loadings. A typical entry in the list has one of three forms: \code{varname=list(d,c)} which will constrain the dth loading for the variable named varname to be equal to c, \code{varname=list(d,"+")} which will constrain the dth loading for the variable named varname to be positive, and \code{varname=list(d, "-")} which will constrain the dth loading for the variable named varname to be negative. If x is a matrix without column names defaults names of ``V1", ``V2", ... , etc will be used. Note that, unlike \code{MCMCfactanal}, the \eqn{\Lambda} matrix used here has \code{factors}+1 columns. The first column of \eqn{\Lambda} corresponds to negative item difficulty parameters and should generally not be constrained.} \item{data}{A data frame.} \item{burnin}{The number of burn-in iterations for the sampler.} \item{mcmc}{The number of iterations for the sampler.} \item{thin}{The thinning interval used in the simulation. The number of iterations must be divisible by this value.} \item{tune}{The tuning parameter for the Metropolis-Hastings sampling. Can be either a scalar or a \eqn{k}-vector. Must be strictly positive.} \item{verbose}{A switch which determines whether or not the progress of the sampler is printed to the screen. If \code{verbose} is greater than 0 the iteration number and the Metropolis-Hastings acceptance rate are printed to the screen every \code{verbose}th iteration.} \item{seed}{The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of \code{rep(12345,6)} is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.} \item{lambda.start}{Starting values for the factor loading matrix Lambda. If \code{lambda.start} is set to a scalar the starting value for all unconstrained loadings will be set to that scalar. If \code{lambda.start} is a matrix of the same dimensions as Lambda then the \code{lambda.start} matrix is used as the starting values (except for equality-constrained elements). If \code{lambda.start} is set to \code{NA} (the default) then starting values for unconstrained elements in the first column of Lambda are based on the observed response pattern, the remaining unconstrained elements of Lambda are set to , and starting values for inequality constrained elements are set to either 1.0 or -1.0 depending on the nature of the constraints.} \item{l0}{The means of the independent Normal prior on the factor loadings. Can be either a scalar or a matrix with the same dimensions as \code{Lambda}.} \item{L0}{The precisions (inverse variances) of the independent Normal prior on the factor loadings. Can be either a scalar or a matrix with the same dimensions as \code{Lambda}.} \item{store.lambda}{A switch that determines whether or not to store the factor loadings for posterior analysis. By default, the factor loadings are all stored.} \item{store.scores}{A switch that determines whether or not to store the factor scores for posterior analysis. \emph{NOTE: This takes an enormous amount of memory, so should only be used if the chain is thinned heavily, or for applications with a small number of observations}. By default, the factor scores are not stored.} \item{drop.constantvars}{A switch that determines whether or not manifest variables that have no variation should be deleted before fitting the model. Default = TRUE.} \item{...}{further arguments to be passed} } \value{ An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package. } \description{ This function generates a sample from the posterior distribution of an ordinal data factor analysis model. Normal priors are assumed on the factor loadings and factor scores while improper uniform priors are assumed on the cutpoints. The user supplies data and parameters for the prior distributions, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package. } \details{ The model takes the following form: Let \eqn{i=1,\ldots,N} index observations and \eqn{j=1,\ldots,K} index response variables within an observation. The typical observed variable \eqn{x_{ij}} is ordinal with a total of \eqn{C_j} categories. The distribution of \eqn{X} is governed by a \eqn{N \times K} matrix of latent variables \eqn{X^*} and a series of cutpoints \eqn{\gamma}. \eqn{X^*} is assumed to be generated according to: \deqn{x^*_i = \Lambda \phi_i + \epsilon_i} \deqn{\epsilon_i \sim \mathcal{N}(0,I)} where \eqn{x^*_i} is the \eqn{k}-vector of latent variables specific to observation \eqn{i}, \eqn{\Lambda} is the \eqn{k \times d} matrix of factor loadings, and \eqn{\phi_i} is the \eqn{d}-vector of latent factor scores. It is assumed that the first element of \eqn{\phi_i} is equal to 1 for all \eqn{i}. The probability that the \eqn{j}th variable in observation \eqn{i} takes the value \eqn{c} is: \deqn{\pi_{ijc} = \Phi(\gamma_{jc} - \Lambda'_j\phi_i) - \Phi(\gamma_{j(c-1)} - \Lambda'_j\phi_i) } The implementation used here assumes independent conjugate priors for each element of \eqn{\Lambda} and each \eqn{\phi_i}. More specifically we assume: \deqn{\Lambda_{ij} \sim \mathcal{N}(l_{0_{ij}}, L_{0_{ij}}^{-1}), i=1,\ldots,k, j=1,\ldots,d} \deqn{\phi_{i(2:d)} \sim \mathcal{N}(0, I), i=1,\dots,n} The standard two-parameter item response theory model with probit link is a special case of the model sketched above. \code{MCMCordfactanal} simulates from the posterior distribution using a Metropolis-Hastings within Gibbs sampling algorithm. The algorithm employed is based on work by Cowles (1996). Note that the first element of \eqn{\phi_i} is a 1. As a result, the first column of \eqn{\Lambda} can be interpretated as item difficulty parameters. Further, the first element \eqn{\gamma_1} is normalized to zero, and thus not returned in the mcmc object. The simulation proper is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample. As is the case with all measurement models, make sure that you have plenty of free memory, especially when storing the scores. } \examples{ \dontrun{ data(painters) new.painters <- painters[,1:4] cuts <- apply(new.painters, 2, quantile, c(.25, .50, .75)) for (i in 1:4){ new.painters[new.painters[,i]