ebook img

Introducing Monte Carlo methods with R PDF

297 Pages·2010·9.121 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Introducing Monte Carlo methods with R

Use R! Advisors: · · RobertGentleman KurtHornik GiovanniParmigiani Forothertitlespublishedinthisseries,goto http://www.springer.com/series/6991 · Christian P. Robert George Casella Introducing Monte Carlo Methods with R 123 ChristianP.Robert GeorgeCasella Universite´ParisDauphine DepartmentofStatistics UMRCNRS7534 UniversityofFlorida CEREMADE 103Griffin-FloydHall placeduMare´chaldeLattre GainesvilleFL32611-8545 deTassigny USA 75775Pariscedex16 [email protected]fl.edu France [email protected] SeriesEditors RobertGentleman KurtHornik DepartmentofBioinformatics DepartmentofStatistikandMathematik andComputationalBiology Wirtshchaftsuniversita¨tWienAugasse2-6 GenentechSouthSanFrancisco A-1090Wien CA94080 Austria USA GiovanniParmigiani DepartmentofBiostatistics andComputationalBiology Dana-FarberCancerInstitute 44BinneyStreet Boston,MA02115 USA ISBN978-1-4419-1575-7 e-ISBN978-1-4419-1576-4 DOI10.1007/978-1-4419-1576-4 SpringerNewYorkDordrechtHeidelbergLondon LibraryofCongressControlNumber:2009941076 (cid:2)c SpringerScience+BusinessMedia,LLC2010 Allrightsreserved.Thisworkmaynotbetranslatedorcopiedinwholeorinpartwithoutthewrittenpermissionofthe publisher(SpringerScience+BusinessMedia,LLC,233SpringStreet,NewYork,NY10013,USA),exceptforbrief excerptsinconnectionwithreviewsorscholarlyanalysis.Useinconnectionwithanyformofinformationstorageand retrieval,electronicadaptation,computersoftware,orbysimilarordissimilarmethodologynowknownorhereafter developedisforbidden. Theuseinthispublicationoftradenames,trademarks,servicemarks,andsimilarterms,eveniftheyarenotidentified assuch,isnottobetakenasanexpressionofopinionastowhetherornottheyaresubjecttoproprietaryrights. Printedonacid-freepaper SpringerispartofSpringerScience+BusinessMedia(www.springer.com) v To our parents, who taught us much in many ways. vi “What if you haven’t the data?” “Then we shall proceed directly to the brandy and cigars.” Lyndsay Faye The Case of Colonel Warbuton’s Madness Preface “After that, it was down to attitude.” Ian Rankin Black & Blue Thepurposeofthisbookistoprovideaself-containedentryintoMonteCarlo computational techniques. First and foremost, it must not be confused with a programming addendum to our earlier book Monte Carlo Statistical Meth- ods whose second edition came out in 2004. The current book has a different purpose, namely to make a general audience familiar with the programming aspects of Monte Carlo methodology through practical implementation. Not only have we introduced R at the core of this book, but the emphasis and contentshavechangeddrasticallyfromMonte Carlo Statistical Methods,even though the overall vision remains the same. Theoretical foundations are in- tentionally avoided in the current book. Indeed, the emphasis on practice is a major feature of this book in that its primary audience consists of graduate students in statistics, biostatistics, engineering, etc., who need to learn how to use simulation methods as a tool to analyze their experiments and/or datasets. The book should appeal to scientists in all fields, given the versatility of these Monte Carlo tools. It can also be used for a more classical statistics audience when aimed at teaching a quick entry into modern computational methods based on R, at the end of an undergraduate program for example, even though this may prove challenging for some students. The choice of the programming language R, as opposed to faster alterna- tives such as Matlab or C and more structured constructs such as BUGS, is due to its pedagogical simplicity and its versatility. Readers can easily con- duct experiments in their own programming language by translating the ex- amplesprovidedinthisbook.(Obviously,thebookcanalsosupplementother textbooks on Bayesian modeling at the graduate level, including our books Bayesian Choice(Robert,2001)andMonte CarloStatistical Methods(Robert viii Preface and Casella, 2004).) This book can also be viewed as a companion to, rather than a competitor of, Jim Albert’s Use R! book Bayesian Computation with R(Albert,2009).Indeed,takenasapair,thesetwobookscanprovideafairly thorough introduction to Monte Carlo methods and Bayesian modeling. Westressthat,ataproductionlevel(thatis,whenusingadvancedMonte Carlo techniques or analyzing large datasets), R cannot be recommended as the default language, but the expertise gained from this book should make the switch to another language seamless. Contrary to usual practice, many exercises are interspersed within the chapters rather than postponed until the end of each chapter. There are two reasonsforthisstylisticchoice.First,theresultsordevelopmentscontainedin those exercises are often relevant for upcoming points in the chapter. Second, they signal to the student (or to any reader) that some pondering over the previouspagesmaybeusefulbeforemovingtothefollowingtopicandsomay act as self-checking gateways. Additional exercises are found at the end of eachchapter,withabridgedsolutionsoftheodd-numberedexercisesprovided on our Webpages as well as Springer’s. Thanks We are immensely grateful to colleagues and friends for their help with this book,inparticulartothefollowingpeople:EdGeorgeforhiscommentsonthe generalpurposeofthebookandsomeexercisesinparticular;JimHobertand FernandoQuintanaforhelpfuldiscussionsontheMonteCarloEM;Alessandra Iacobucci for signaling in due time a fatal blunder; Jean-Michel Marin for lettingusrecyclethefirstchapterofBayesian Core(MarinandRobert,2007) into our introduction to R and for numerous pieces of R advice, as well as pedagogical suggestions; Antonietta Mira for pointing out mistakes during a session of an MCMC conference in Warwick; Fran¸cois Perron for inviting CPR to Montr´eal and thus providing him with a time window to complete Chapter8(onlyshortenedbyanice-climbingafternooninQu´eb´ec!),andalso Franc¸ois Perron and Cl´ementine Trimont for testing the whole book from the perspectives of a professor and a student, respectively; Martyn Plummer for answering queries about coda; Jeff Rosenthal for very helpful exchanges on amcmc; Dimitris Rizopoulos for providing Exercise 7.21; and Phil Spector from Berkeley for making available his detailed and helpful notes and slides on R and C, now partly published as Spector (2009). Comments from both reviewers were especially useful in finalizing the book. We are also grateful to John Kimmel of Springer for his advice and efficiency, as well as for creating thevisionaryUseR!seriesandsupportingthedevelopmentoftheR language that way. From a distance, we also wish to thank Professors Gentleman and Ihaka for creating the R language and for doing it in open-source, as well as the entire R community for contributing endlessly to its development. Sceaux and Gainesville Christian P. Robert and George Casella October 18, 2009 Contents Preface ........................................................ vii List of Figures................................................. xiii List of Examples...............................................xvii 1 Basic R Programming ..................................... 1 1.1 Introduction ............................................ 2 1.2 Getting started.......................................... 3 1.3 R objects ............................................... 5 1.3.1 The vector class ................................... 6 1.3.2 The matrix, array, and factor classes.................. 9 1.3.3 The list and data.frame classes ...................... 12 1.4 Probability distributions in R ............................. 14 1.5 Basic and not-so-basic statistics ........................... 14 1.6 Graphical facilities....................................... 26 1.7 Writing new R functions.................................. 31 1.8 Input and output in R.................................... 35 1.9 Administration of R objects............................... 36 1.10 The mcsm package....................................... 36 1.11 Additional exercises...................................... 37 2 Random Variable Generation .............................. 41 2.1 Introduction ............................................ 42 2.1.1 Uniform simulation ................................ 42 2.1.2 The inverse transform.............................. 44 2.2 General transformation methods........................... 46 2.2.1 A normal generator................................ 47 2.2.2 Discrete distributions .............................. 48 2.2.3 Mixture representations ............................ 50 2.3 Accept–reject methods ................................... 51 x Contents 2.4 Additional exercises...................................... 57 3 Monte Carlo Integration................................... 61 3.1 Introduction ............................................ 62 3.2 Classical Monte Carlo integration.......................... 65 3.3 Importance sampling..................................... 69 3.3.1 An arbitrary change of reference measure............. 69 3.3.2 Sampling importance resampling .................... 75 3.3.3 Selection of the importance function ................. 78 3.4 Additional exercises...................................... 86 4 Controlling and Accelerating Convergence................. 89 4.1 Introduction ............................................ 90 4.2 Monitoring variation..................................... 91 4.3 Asymptotic variance of importance sampling estimators ...... 92 4.4 Effective sample size and perplexity........................ 98 4.5 Simultaneous monitoring .................................100 4.6 Rao–Blackwellization and deconditioning ...................107 4.7 Acceleration methods ....................................111 4.7.1 Correlated simulations .............................111 4.7.2 Antithetic variables................................113 4.7.3 Control variates...................................116 4.8 Additional exercises......................................122 5 Monte Carlo Optimization.................................125 5.1 Introduction ............................................126 5.2 Numerical optimization methods ..........................127 5.3 Stochastic search ........................................130 5.3.1 A basic solution...................................130 5.3.2 Stochastic gradient methods ........................136 5.3.3 Simulated annealing ...............................140 5.4 Stochastic approximation.................................146 5.4.1 Optimizing Monte Carlo approximations .............146 5.4.2 Missing-data models and demarginalization...........150 5.4.3 The EM algorithm ................................152 5.4.4 Monte Carlo EM ..................................157 5.5 Additional exercises......................................163 6 Metropolis–Hastings Algorithms...........................167 6.1 Introduction ............................................168 6.2 A peek at Markov chain theory............................168 6.3 Basic Metropolis–Hastingsalgorithms ......................170 6.3.1 A generic Markov chain Monte Carlo algorithm .......171 6.3.2 The independent Metropolis–Hastings algorithm ......175 6.4 A selection of candidates .................................182

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.