Package gibbs.met. February 19, 2015

Similar documents
Package gibbs.met documentation

Package atmcmc. February 19, 2015

Package dirmcmc. R topics documented: February 27, 2017

Markov chain Monte Carlo methods

Package ECctmc. May 1, 2018

Package HI. February 19, 2015

Package HMMCont. February 19, 2015

Package binomlogit. February 19, 2015

Package MfUSampler. June 13, 2017

Package hsiccca. February 20, 2015

Package BPHO documentation

Package cgh. R topics documented: February 19, 2015

Package dkdna. June 1, Description Compute diffusion kernels on DNA polymorphisms, including SNP and bi-allelic genotypes.

Bayesian Estimation for Skew Normal Distributions Using Data Augmentation

Package sbf. R topics documented: February 20, Type Package Title Smooth Backfitting Version Date Author A. Arcagni, L.

Package GGMselect. February 1, 2018

Package r2d2. February 20, 2015

Package glassomix. May 30, 2013

Package clusternomics

Package bayesdccgarch

Multivariate Normal Random Numbers

Package cwm. R topics documented: February 19, 2015

Package RYoudaoTranslate

Package EDFIR. R topics documented: July 17, 2015

Package longclust. March 18, 2018

Package gamm4. July 25, Index 10

Package bisect. April 16, 2018

Package dissutils. August 29, 2016

Markov Chain Monte Carlo (part 1)

Package CombinePortfolio

The boa Package. May 3, 2005

Package mmtsne. July 28, 2017

Package INLABMA. February 4, 2017

Package FPDclustering

Package smoothmest. February 20, 2015

Package Bergm. R topics documented: September 25, Type Package

Package SparseFactorAnalysis

Package MultiMeta. February 19, 2015

Package FisherEM. February 19, 2015

Package TBSSurvival. January 5, 2017

Package texteffect. November 27, 2017

Package DPBBM. September 29, 2016

Package SSLASSO. August 28, 2018

Package imgur. R topics documented: December 20, Type Package. Title Share plots using the imgur.com image hosting service. Version 0.1.

Package pnmtrem. February 20, Index 9

Overview. Monte Carlo Methods. Statistics & Bayesian Inference Lecture 3. Situation At End Of Last Week

Package gsscopu. R topics documented: July 2, Version Date

Computer vision: models, learning and inference. Chapter 10 Graphical Models

Package MultiOrd. May 21, 2016

Package Combine. R topics documented: September 4, Type Package Title Game-Theoretic Probability Combination Version 1.

Package naivebayes. R topics documented: January 3, Type Package. Title High Performance Implementation of the Naive Bayes Algorithm

Package lgarch. September 15, 2015

Assignment 2. Unsupervised & Probabilistic Learning. Maneesh Sahani Due: Monday Nov 5, 2018

Monte Carlo sampling

Package DCEM. September 30, 2018

Package batchmeans. R topics documented: July 4, Version Date

Package mcmcse. February 15, 2013

Package weco. May 4, 2018

Debugging MCMC Code. Charles J. Geyer. April 15, 2017

Package munfold. R topics documented: February 8, Type Package. Title Metric Unfolding. Version Date Author Martin Elff

MCMC Methods for data modeling

Package clustvarsel. April 9, 2018

Package spatialtaildep

Package beast. March 16, 2018

Package gee. June 29, 2015

Package NORTARA. February 19, 2015

Package blockmatrix. February 19, 2015

Package spark. July 21, 2017

Package snn. August 23, 2015

Package esabcv. May 29, 2015

Package flsa. February 19, 2015

Package RCA. R topics documented: February 29, 2016

Package EMC. February 19, 2015

Package samplesizelogisticcasecontrol

Package lmesplines. R topics documented: February 20, Version

Package longitudinal

Package restlos. June 18, 2013

Package sparsereg. R topics documented: March 10, Type Package

Package tpr. R topics documented: February 20, Type Package. Title Temporal Process Regression. Version

Package SPIn. R topics documented: February 19, Type Package

Package RobustGaSP. R topics documented: September 11, Type Package

Package diagis. January 25, 2018

Package sensory. R topics documented: February 23, Type Package

Package comphclust. February 15, 2013

Package qrfactor. February 20, 2015

Package mrm. December 27, 2016

Quantitative Biology II!

Package CLA. February 6, 2018

JMP Book Descriptions

Package Kernelheaping

Package BAMBI. R topics documented: August 28, 2017

Descriptive and Graphical Analysis of the Data

Package bayeslongitudinal

Package flexcwm. May 20, 2018

Bayesian Statistics Group 8th March Slice samplers. (A very brief introduction) The basic idea

Package lira. October 27, 2017

Package bsam. July 1, 2017

Package mnormt. April 2, 2015

Package MixSim. April 29, 2017

Package bayescl. April 14, 2017

Transcription:

Version 1.1-3 Title Naive Gibbs Sampling with Metropolis Steps Author Longhai Li <longhai@math.usask.ca> Package gibbs.met February 19, 2015 Maintainer Longhai Li <longhai@math.usask.ca> Depends R (>= 2.5.1) Description This package provides two generic functions for performing Markov chain sampling in a naive way for a user-defined target distribution, which involves only continuous variables. The function ``gibbs_met'' performs Gibbs sampling with each 1-dimensional distribution sampled with Metropolis update using Gaussian proposal distribution centered at the previous state. The function ``met_gaussian'' updates the whole state with Metropolis method using independent Gaussian proposal distribution centered at the previous state. The sampling is carried out without considering any special tricks for improving efficiency. This package is aimed at only routine applications of MCMC in moderate-dimensional problems. License GPL (>= 2) URL \{}url{http://www.r-project.org\protect\t1\textbraceright, \{}url{http://math.usask.ca/~longhai\protect\t1\textbraceright Repository CRAN Date/Publication 2012-10-29 08:58:54 NeedsCompilation no R topics documented: gibbs-metropolis...................................... 2 Index 6 1

2 gibbs-metropolis gibbs-metropolis Gibbs sampling with Metropolis steps and multivariate Metropolis sampling Description The function gibbs_met performs Gibbs sampling with each 1-dimensional distribution sampled with Metropolis update using Gaussian proposal distribution centered at the previous state. The function met_gaussian updates the whole state with Metropolis method using independent Gaussian proposal distribution centered at the previous state. The sampling is carried out without considering any special tricks for improving efficiency. The functions are written for routine applications in moderate-dimensional problems. Usage gibbs_met(log_f,no_var,ini_value, iters,iters_per.iter=1,iters_met,stepsizes_met,...) met_gaussian(log_f, no_var, ini_value, iters,iters_per.iter=1,stepsizes_met,...) Arguments log_f no_var the log of the density function from which one wants to sample. the number of variables to be sampled. ini_value the initial value. iters,iters_per.iter Run iters super-transition, each consisting of iters_per.iter single Markov chain update (using Gibbs sampling or Metropolis sampling). Only the state at the end of each super-transition is saved and returned. iters_met stepsizes_met iterations of updating each 1-dim conditional distribution with Metropolis method in Gibbs sampling using the function gibbs_met. a vector of length no_var, with stepsizes_met[i] being the standard deviation of Gaussian proposal for updating i th variable, which is used either in Gibbs sampling for sampling from the i th conditional distribution, or used in multivariate Metropolis sampling (using the function met_gaussian) for i th variable.... extra arguments needed to compute log_f. Value a matrix with dim (iters +1) * no_var is returned, with each row for an iteration

gibbs-metropolis 3 Examples ## demonstration by sampling from bivariate normal distributions ## the function computing the log density function of multivariate normal ## x --- a vector, the p.d.f at x will be computed ## mu --- the mean vector of multivariate normal distribution ## A --- the inverse covariance matrix of multivariate normal distribution log_pdf_mnormal <- function(x, mu, A) { 0.5 * (-length(mu)*log(2*pi)+sum(log(svd(a)$d))-sum(t(a*(x-mu))*(x-mu)) ) } ## sampling from a bivariate normal distribution with correlation 0.1, ## both marginal standard deviations 1, mean vector (0,5) A <- solve(matrix(c(1,0.1,0.1,1),2,2)) mc_mvn <- gibbs_met(log_f=log_pdf_mnormal,no_var=2, ini_value=c(0,0),iters=400,iters_met=2, stepsizes_met=c(0.5,0.5), mu=c(0,5), A = A) postscript("mc_mvn_lowcor.eps",width=7,height=8,horiz=false) par(mfrow=c(2,2), oma=c(0,0,1,0)) ## looking at the trace of Markov chain in the first 100 iterations plot(mc_mvn[1:100,1],mc_mvn[1:100,2],type="b",pch=20, main="markov chain trace of both variables") plot(mc_mvn[,1],type="b",pch=20, main="markov chain trace of the 1st variable") ## looking at the QQ plot of the samples for a variable qqnorm(mc_mvn[-(1:50),1],main="normal QQ plot of the 1st variable") ## looking at the ACF of the samples for a variable acf(mc_mvn[,1],main="acf plot of the 1st variable") title(main="gibbs sampling for a bivariate normal with correlation 0.1", outer=true) dev.off() ## checking the correlation of samples cat("the sample correlation is",cor(mc_mvn[-(1:50),1],mc_mvn[-(1:50),2]),"\n") ## demonstration by sampling from a mixture bivariate normal distribution

4 gibbs-metropolis ## the function computing the log density function of mixture multivariate normal ## x --- a vector, the p.d.f at x will be computed ## mu1,mu2 --- the mean vectors of multivariate normal distributions ## A1,A2 --- the inverse covariance matrice of multivariate normal distributions ## mixture proportion is 0.5 log_pdf_twonormal <- function(x, mu1, A1, mu2, A2) { log_sum_exp(c(log_pdf_mnormal(x,mu1,a1),log_pdf_mnormal(x,mu2,a2)) ) } log_sum_exp <- function(lx) { ml <- max(lx) ml + log(sum(exp(lx-ml))) } ## set parameters defining a mixture bivariate distribution A1 <- solve(matrix(c(1,0.1,0.1,1),2,2)) A2 <- solve(matrix(c(1,0.1,0.1,1),2,2)) mu1 <- c(0,0) mu2 <-c(4,4) ## performing Gibbs sampling mc_mvn <- gibbs_met(log_f=log_pdf_twonormal,no_var=2,ini_value=c(0,0), iters=400,iters_met=2,stepsizes_met=c(0.5,0.5), mu1=mu1,mu2=mu2,a1=a1,a2=a2) postscript("mc_mvn_closemix.eps",width=7,height=8,horiz=false) par(mfrow=c(2,2), oma=c(0,0,2,0)) ## looking at the trace of Markov chain in the first 100 iterations plot(mc_mvn[,1],mc_mvn[,2],type="b",pch=20, main="markov chain trace of both variables") plot(mc_mvn[,1],type="b",pch=20, main="markov chain trace of the 1st variable") plot(mc_mvn[,2],type="b",pch=20, main="markov chain trace of the 2nd variable") ## looking at the ACF of the samples for a variable acf(mc_mvn[,1],main="acf plot of the 1st variable") title(main="gibbs sampling for a mixture of two bivariate normal distributions with locations (0,0) and (4,4)", outer=true) dev.off() ## checking the correlation of samples cat("the sample correlation is",cor(mc_mvn[-(1:50),1],mc_mvn[-(1:50),2]),"\n") ###############################################################################

gibbs-metropolis 5 ## Sampling from a mixture bivariate normal distribution with Metropolis method ############################################################################### ## set parameters defining a mixture bivariate distribution A1 <- solve(matrix(c(1,0.1,0.1,1),2,2)) A2 <- solve(matrix(c(1,0.1,0.1,1),2,2)) mu1 <- c(0,0) mu2 <-c(6,6) ## performing Gibbs sampling mc_mvn <- met_gaussian(log_f=log_pdf_twonormal,no_var=2,ini_value=c(0,0), iters=400,iters_per.iter=2,stepsizes=c(1,1), mu1=mu1,mu2=mu2,a1=a1,a2=a2) postscript("mc_mvn_farmix_met.eps",width=7,height=8,horiz=false) par(mfrow=c(2,2), oma=c(0,0,2,0)) ## looking at the trace of Markov chain in the first 100 iterations plot(mc_mvn[,1],mc_mvn[,2],type="b",pch=20, main="markov chain trace of both variables") plot(mc_mvn[,1],type="b",pch=20, main="markov chain trace of the 1st variable") plot(mc_mvn[,2],type="b",pch=20, main="markov chain trace of the 2nd variable") ## looking at the ACF of the samples for a variable acf(mc_mvn[,1],main="acf plot of the 1st variable") title(main="sampling with Metropolis method for a mixture of two bivariate normal distributions with locations (0,0) and (6,6)", outer=true) dev.off() ## checking the correlation of samples cat("the sample correlation is",cor(mc_mvn[-(1:50),1],mc_mvn[-(1:50),2]),"\n")

Index Topic multivariate gibbs-metropolis, 2 begin.gibbs.met (gibbs-metropolis), 2 gibbs-metropolis, 2 gibbs_met (gibbs-metropolis), 2 met_gaussian (gibbs-metropolis), 2 6