comparepost: Line plots of selected parameters from multiple models.

Description Usage Arguments Author(s) Examples

Description

Line plots of selected parameters from multiple models.

Usage

1
comparepost(postlist, years1 = NA, years2 = NA, pnames = NULL)

Arguments

postlist

A single, or list of, R2jags output objects or mcmc.list objects. The legend will be created from the names of the list objects.

years1

An optional vector of years to use for plotting labels, possibly useful for random effects

years2

An optional vector of years to use for plotting labels, possibly useful for random effects

pnames

A character list of which parameters to plot

Author(s)

Matt Tyers

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# ------------ two competing R2jags models ----------- #

## Not run: 
library(R2jags)
N <- 1000
x <- 1:N
yreff <- rnorm(10,0,10)
yr <- rep(1:20, each=50)
epsilon <- rnorm(N, 0, 1)
y <- x + yreff[yr] + epsilon

cat('model {
 for (i in 1:N){
   y[i] ~ dnorm(mu[i], tau)
   mu[i] <- b0 + b1*x[i] + a.yr[yr[i]]
}
b0 ~ dnorm(0, .0001)
b1 ~ dnorm(0, .0001)
tau <- pow(sigma, -2)
sigma ~ dunif(0, 100)
for(j in 1:Nyr) {
  a.yr[j] ~ dnorm(0, tau.a)
}
tau.a <- pow(sigma.a, -2)
sigma.a ~ dunif(0, 100)
}', file="test.jags")

test.data <- list(x=x,y=y,N=N,yr=yr,Nyr=max(yr))
test.jags.out1 <- jags(model.file="test.jags", data=test.data, 
     parameters.to.save=c("b0","b1","a.yr","sigma","sigma.a"), n.chains=3, n.iter=10000)

cat('model {
 for (i in 1:N){
   y[i] ~ dnorm(mu[i], tau)
   mu[i] <- b0 + b1*x[i] + a.yr[yr[i]]
}
b0 ~ dnorm(0, .0001)
b1 ~ dnorm(0, .0001)
tau <- pow(sigma, -2)
sigma ~ dunif(0, 100)
for(j in 1:Nyr) {
  a.yr[j] ~ dnorm(0, 0.0001)
}
}', file="test.jags")

test.data <- list(x=x,y=y,N=N,yr=yr,Nyr=max(yr))
test.jags.out2 <- jags(model.file="test.jags", data=test.data, 
     parameters.to.save=c("b0","b1","a.yr","sigma"), n.chains=3, n.iter=10000)

# ------------- calling comparepost() ------------ #
par(mfrow=c(3,2))
comparepost(postlist=list(hierarchical=test.jags.out1,non_hier=test.jags.out2),years1=1998:2017)

### or just one posterior...
comparepost(test.jags.out1,years1=1998:2017)

## End(Not run)

mbtyers/jagsplot documentation built on May 22, 2019, 12:58 p.m.