{"id":133,"date":"2016-06-11T07:33:29","date_gmt":"2016-06-11T07:33:29","guid":{"rendered":"http:\/\/www.uncertain-future.org.uk\/?page_id=133"},"modified":"2016-06-11T07:53:35","modified_gmt":"2016-06-11T07:53:35","slug":"monte-carlo-markov-chain-methods","status":"publish","type":"page","link":"http:\/\/www.uncertain-future.org.uk\/?page_id=133","title":{"rendered":"Monte Carlo Markov Chain methods"},"content":{"rendered":"<p>These routines represent an implementation of an adaptive Monte Carlo Markov Chain method to a hydrological modelling example (using the same model and data as the earlier GLUE Routines). \u00a0It makes use of a statistical likelihood function based on an error model that includes a mean bias, constant variance and autocorrelation. \u00a0It allows for the Box-Cox transformation of residuals to more closely match the assumptions of the error model on which the likelihood function is derived.<\/p>\n<p><u>Libraries<\/u><\/p>\n<p>These routines require the R libraries CODA, MASS and LATTICE<\/p>\n<p>There is also a general stand-alone R library called MCMC.<\/p>\n<p><u>Download<\/u><\/p>\n<p>Download sample code and data file for MCMC routines\u00a0[<a href=\"http:\/\/www.uncertain-future.org.uk\/wp-content\/uploads\/2016\/06\/R-MCMC.zip\"><em>Here<\/em><\/a>]<\/p>\n<p><u>Procedure<\/u><\/p>\n<p><strong>Stages in the formal Bayes Analysis (programs modified from originals written by Paul Smith, Lancaster University)<\/strong><\/p>\n<ul>\n<li><strong> Initialise the process:\u00a0\u00a0\u00a0<\/strong>load the\u00a0MCMCSetup.Rsource<\/li>\n<\/ul>\n<p>This will run set-up code automatically.\u00a0 If you open it for editing you will see that you can change the minimum, maximum and initial values of the PDM model parameters (something to play with later, use the defaults for now)<\/p>\n<ul>\n<li><strong>Fit an appropriate error transformation:\u00a0<\/strong>load the\u00a0BoxCox.Rsource.<\/li>\n<\/ul>\n<p>This program carries out an initial (trial and error) estimate of the form of error model to use based on Box-Cox transformation to a zero-mean Gaussian autoregressive model.\u00a0 It first uses a least square optimisation of the model parameters to provide a \u201cbest-fit\u201d model for calculating the residual series (which can take a couple of minutes).\u00a0\u00a0 The routine provides graphics of the autocorrelation function (ACF) and quantile-quantile plots before and after transformation to illustrate how well the (optimised) transformed model errors conform to the Gaussian assumption.<\/p>\n<p>You can try this with different values of the Box-Cox parameters by using the call:<\/p>\n<p>BoxCox(lambda,alpha)<\/p>\n<p>Default values of the parameters are (1,0) which gives no transformation.<\/p>\n<ul>\n<li><strong>Run the MCMC Identification algorithm:\u00a0<\/strong>load the\u00a0MCMCrun.Rsource<\/li>\n<\/ul>\n<p>This will run automatically using the most recent values of lambda and alpha in the Box-Cox transformation but will take some time!!\u00a0\u00a0 It is running multiple iterations of the chain in moving from the prior distribution to the posterior distribution of the parameters.<\/p>\n<p>This routine provides graphics of the way in each the parameters change after each MCMC iteration, together with a plot of the 95% prediction quantiles (from both parameter and residual error) for discharge (these calculations also take some time \u2013 quantiles are being calculated over all posterior model samples at every time step).<\/p>\n<p><strong>Things to play with in these programs<\/strong><\/p>\n<p><strong>\u00a0<\/strong>Open\u00a0MCMCsetup.R\u00a0for editing. \u00a0\u00a0\u00a0There you will see that the vectors of minimum, maximum and initial values of the parameters are set.\u00a0 The default values will give reasonable results, but try changing values to see whether it makes a big impact on the resulting error model and posterior distributions.\u00a0\u00a0 In general, the initial parameter values will affect the resulting optimisation, so it is always worth trying multiple starting points.<\/p>\n<p>You can also try out different Box-Cox transforms before running\u00a0\u00a0MCMCrun.R.\u00a0\u00a0 Note, however, in doing so that the best error model at the parameter set found by a least squares optimisation might not be the best throughout the posterior density space.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>These routines represent an implementation of an adaptive Monte Carlo Markov Chain method to a hydrological modelling example (using the same model and data as the earlier GLUE Routines). \u00a0It makes use of a statistical likelihood function based on an error model that includes a mean bias, constant variance and autocorrelation. \u00a0It allows for the &hellip; <a href=\"http:\/\/www.uncertain-future.org.uk\/?page_id=133\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Monte Carlo Markov Chain methods<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":28,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-133","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.uncertain-future.org.uk\/index.php?rest_route=\/wp\/v2\/pages\/133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.uncertain-future.org.uk\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.uncertain-future.org.uk\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.uncertain-future.org.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.uncertain-future.org.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=133"}],"version-history":[{"count":3,"href":"http:\/\/www.uncertain-future.org.uk\/index.php?rest_route=\/wp\/v2\/pages\/133\/revisions"}],"predecessor-version":[{"id":145,"href":"http:\/\/www.uncertain-future.org.uk\/index.php?rest_route=\/wp\/v2\/pages\/133\/revisions\/145"}],"up":[{"embeddable":true,"href":"http:\/\/www.uncertain-future.org.uk\/index.php?rest_route=\/wp\/v2\/pages\/28"}],"wp:attachment":[{"href":"http:\/\/www.uncertain-future.org.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}