Skip to content

Commit 5886baf

Browse files
committed
added bugs_example/vol1/litter files
1 parent cff0424 commit 5886baf

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
G <- 2
2+
N <- 16
3+
r <-
4+
structure(c(13, 12, 12, 11, 9, 10, 9, 9, 8, 10, 8, 9, 12, 9, 11, 8, 9, 8, 9, 4, 8, 7, 11, 4, 4, 5, 5, 3, 7, 3, 7, 0),
5+
.Dim = c(2, 16))
6+
n <-
7+
structure(c(13, 12, 12, 11, 9, 10, 9, 9, 8, 11, 8, 10, 13, 10, 12, 9, 10, 9, 10, 5, 9, 9, 13, 7, 5, 10, 7, 6, 10, 10,
8+
10, 7),
9+
.Dim = c(2, 16))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
data {
2+
int<lower=0> G;
3+
int<lower=0> N;
4+
int<lower=0> r[G,N];
5+
int<lower=0> n[G,N];
6+
}
7+
parameters {
8+
matrix<lower=0,upper=1>[G,N] p;
9+
vector<lower=0,upper=1>[G] mu;
10+
vector<lower=0.1>[G] a_plus_b;
11+
}
12+
transformed parameters {
13+
vector[G] a;
14+
vector[G] b;
15+
a <- mu .* a_plus_b;
16+
b <- (1 - mu) .* a_plus_b;
17+
}
18+
model {
19+
a_plus_b ~ pareto(0.1,1.5);
20+
for (g in 1:G) {
21+
for (i in 1:N) {
22+
p[g,i] ~ beta(a[g],b[g]);
23+
r[g,i] ~ binomial(n[g,i],p[g,i]);
24+
}
25+
}
26+
}
27+
generated quantities {
28+
vector<lower=0>[G] theta;
29+
for (g in 1:G)
30+
theta[g] <- 1 / (a[g] + b[g]);
31+
}

bugs_examples/vol1/litter/makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
STAN_HOME = ../../../../..
2+
PGM = litter#
3+
CXX = g++
4+
BOOSTPATH = $(shell find $(STAN_HOME)/lib -path '*lib/boost_*' -regex '.*lib\/boost_[^/]*')
5+
EIGENPATH = $(shell find $(STAN_HOME)/lib -path '*lib/eigen_*' -regex '.*lib\/eigen_[^/]*')
6+
CPPFLAGS = -I $(BOOSTPATH) -I$(EIGENPATH) -I $(STAN_HOME)/src
7+
LIBFLAGS = -L$(STAN_HOME)/bin -lstan
8+
9+
$(PGM) :
10+
$(STAN_HOME)/bin/stanc --name=$(PGM) $(PGM).stan
11+
$(CXX) -O3 -DNDEBUG $(CPPFLAGS) $(PGM).cpp -o $(PGM) $(LIBFLAGS)
12+
./$(PGM) data=$(PGM).data.R sample
13+
14+
clean :
15+
rm -rf $(PGM).cpp samples.csv $(PGM)

bugs_examples/vol1/litter/post.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## take a look at the samples and compare with results computed
2+
## in other program.
3+
4+
5+
library(coda)
6+
7+
post <- read.csv(file = "samples.csv", header = TRUE, comment.char = '#');
8+
9+
summary(as.mcmc(poi))
10+
11+
library(BUGSExamples)
12+
13+
14+
# theta0 <- theta[1] - theta[2] * mean(X)
15+
ex <- list(name = "Litter", parameters = pars,
16+
nSample = 10000, nBurnin = 1000, nThin = 1,
17+
nChain = 3);
18+
19+
jagspost <- runExample(ex, engine = 'JAGS')
20+
summary(jagspost$coda)
21+
22+
23+
24+
25+

0 commit comments

Comments
 (0)