Plotting and knitr options, (can generally be ignored)
source("~/.knitr_defaults.R") #opts_knit$set(upload.fun = socialR::flickr.url) library(knitcitations) library(nonparametricbayes) opts_chunk$set(external=TRUE) read_chunk("external-chunks.R")
f <- RickerAllee p <- c(1, 10, 5) K <- 10 # approx, a li'l' less allee <- 5 # approx, a li'l' less
Various parameters defining noise dynamics, grid, and policy costs.
Mean predictions
Estimate the Gaussian Process (nonparametric Bayesian fit)
Show traces and posteriors against priors
We use the JAGS Gibbs sampler, a recent open source BUGS
implementation with an R interface that works on most platforms.
We initialize the usual MCMC parameters; see ?jags
for details.
All parametric Bayesian estimates use the following basic parameters for the JAGS MCMC:
We will use the same priors for process and observation noise in each model,
We initiate the MCMC chain (init_p
) using the true values of the
parameters p
from the simulation. While impossible in real data, this
gives the parametric Bayesian approach the best chance at succeeding.
y
is the timeseries (recall obs
has the $x_t$, $x_{t+1}$ pairs)
The actual model is defined in a model.file
that contains an R function
that is automatically translated into BUGS code by R2WinBUGS. The file
defines the priors and the model. We write the file from R as follows:
Write the priors into a list for later reference
We define which parameters to keep track of, and set the initial values of parameters in the transformed space used by the MCMC. We use logarithms to maintain strictly positive values of parameters where appropriate.
R notes: this strips classes from the mcmc.list
object (so that we have list of matrices; objects that reshape2::melt
can handle intelligently), and then combines chains into one array. In this array each parameter is given its value at each sample from the posterior (index) for each chain.
Reshape the posterior parameter distribution data, transform back into original space, and calculate the mean parameters and mean function
Compute prior curves
We define which parameters to keep track of, and set the initial values of parameters in the transformed space used by the MCMC.
Reshape posteriors data, transform back, calculate mode and corresponding function.
Convergence diagnostics for parametric bayes
This shows only the mean predictions. For the Bayesian cases, we can instead loop over the posteriors of the parameters (or samples from the GP posterior) to get the distribution of such curves in each case.
Compute the optimal policy under each model using stochastic dynamic programming. We begin with the policy based on the GP model,
Determine the optimal policy based on the allen and MLE models
Determine the optimal policy based on Bayesian Allen model
Bayesian Ricker
Bayesian Myers model
Assemble the data
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.