Skip to content

Commit

Permalink
fixed myers_jags run, loads knitr_defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
cboettig committed May 29, 2013
1 parent 5e3f3f5 commit 783ed11
Show file tree
Hide file tree
Showing 2 changed files with 1,369 additions and 27 deletions.
46 changes: 19 additions & 27 deletions inst/examples/BUGS/parametric-vs-nonparametric.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,10 @@
Plotting and knitr options, (can generally be ignored)

```{r plotting-options, cache=FALSE, message=FALSE, warning=FALSE, include=FALSE}
setwd("~/Documents/code/nonparametric-bayes/inst/examples/BUGS/")
#library(knitcitations)
library(ggplot2)
library(nonparametricbayes)
opts_chunk$set(tidy=FALSE, warning=FALSE, message=FALSE, cache=TRUE, comment=NA, fig.path="figure/parametric-"
fig.width=6, fig.height=4, cache.path="parametric-vs-nonparametric/", verbose=TRUE)
source("~/.knitr_defaults.R")
#opts_knit$set(upload.fun = socialR::flickr.url)
theme_set(theme_bw(base_size=12))
theme_update(panel.background = element_rect(fill = "transparent", colour = NA),
plot.background = element_rect(fill = "transparent", colour = NA))
cbPalette <- c("#000000", "#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#D55E00", "#CC79A7")
library(knitcitations)
library(nonparametricbayes)
```


Expand Down Expand Up @@ -158,7 +150,7 @@ All parametric Bayesian estimates use the following basic parameters for the JAG
```{r jags-setup}
y <- obs$x[-1]
N <- length(y);
jags.data <- list("N"=N,"y"=y)
jags.data <- list("N","y")
n.chains <- 6
n.iter <- 5e5
n.burnin <- floor(10000)
Expand Down Expand Up @@ -241,7 +233,7 @@ parameters in the transformed space used by the MCMC. We use logarithms
to maintain strictly positive values of parameters where appropriate.


```{r allen-mcmc, dependson=c("allen-model", "allen-pars", "jags-setup")}
```{r allen-mcmc, dependson=c("allen-model", "allen-pars", "jags-setup"), results="hide"}
jags.params=c("K","logr0","logtheta","stdQ", "stdR") # be sensible about the order here
# Can give a list of starting values or a function that can create random values
Expand Down Expand Up @@ -366,7 +358,7 @@ parameters in the transformed space used by the MCMC. We use logarithms
to maintain strictly positive values of parameters where appropriate.


```{r ricker-mcmc, dependson="ricker-model"}
```{r ricker-mcmc, dependson="ricker-model", results="hide"}
# Uniform priors on standard deviation terms
jags.params=c("K","logr0", "stdQ", "stdR")
jags.inits <- function(){
Expand All @@ -386,7 +378,7 @@ ricker_jags <- do.call(jags.parallel,
recompile(ricker_jags)
ricker_jags <- do.call(autojags,
list(object=ricker_jags, n.update=n.update, n.iter=n.iter,
n.thin = n.thin, progress.bar="none"))
n.thin = n.thin))
```


Expand Down Expand Up @@ -449,9 +441,8 @@ paste(sprintf(
stdR_prior_p[1], stdR_prior_p[2]),
"
iQ <- 1 / (stdQ * stdQ);
iR <- 1 / (stdR * stdR);
iQ <- 1 / (stdQ * stdQ)
iR <- 1 / (stdR * stdR)
r0 <- exp(logr0)
theta <- exp(logtheta)
K <- exp(logK)
Expand Down Expand Up @@ -482,25 +473,26 @@ par_priors <- list( deviance = function(x) 0 * x, logK = logK_prior,
```


```{r myers-mcmc, dependson="myers-model"}
```{r myers-mcmc, dependson="myers-model", results="hide"}
jags.params=c("logr0", "logtheta", "logK", "stdQ", "stdR")
jags.inits <- function(){
list("logr0" = log(rlnorm(1,0,.5)),
"logK" = log(10 * rlnorm(1,0,.2)),
"logtheta" = log( 2 * rlnorm(1,0,.2)),
"stdQ"= 0.2 * rlnorm(1,0,.1),
"stdR"= 1e-5 * rlnorm(1,0,.1),
"x"=y,
list("logr0" = rnorm(1, 1, .5),
"logK" = 10 * rnorm(1, 1, .2),
"logtheta" = 2 * rnorm(1, 1, .2),
"stdQ" = 0.2 * rlnorm(1, 0, .1),
"stdR" = 1e-5 * rlnorm(1, 0, .1),
"x" = y,
.RNG.name="base::Wichmann-Hill", .RNG.seed=123)
}
set.seed(12345)
myers_jags <- do.call(jags.parallel,
list(data=jags.data, inits=jags.inits, jags.params,
n.chains=n.chains, n.iter=n.iter, n.thin=n.thin,
n.burnin=n.burnin, model.file="myers.bugs")
n.burnin=n.burnin, model.file="myers.bugs"))
recompile(myers_jags)
myers_jags <- do.call(autojags,
list(object=myers_jags, n.update=n.update, n.iter=n.iter,
n.thin = n.thin, progress.bar="none"))
n.thin = n.thin))
```

Convergence diagnostics for parametric bayes
Expand Down
Loading

0 comments on commit 783ed11

Please sign in to comment.