Skip to content

Commit

Permalink
copy files instead of submodules, because it confuses julia package m…
Browse files Browse the repository at this point in the history
…anager
  • Loading branch information
sunxd3 committed Oct 21, 2024
1 parent c6a31fa commit ff49d61
Show file tree
Hide file tree
Showing 360 changed files with 17,643 additions and 2 deletions.
2 changes: 1 addition & 1 deletion benchmark/run_benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ end
## Stan

const STAN_BUGS_EXAMPLES_FOLDER = joinpath(
dirname(@__FILE__), "stan-example-models/bugs_examples/"
dirname(@__FILE__), "stan/bugs_examples/"
)

const MODEL_VOL1_STAN = OrderedDict(
Expand Down
1 change: 0 additions & 1 deletion benchmark/stan-example-models
Submodule stan-example-models deleted from 4902ad
22 changes: 22 additions & 0 deletions benchmark/stan/bugs_examples/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
This folder contains WinBUGS examples in Stan. The descriptions can be found at:
http://www.mrc-bsu.cam.ac.uk/wp-content/uploads/WinBUGS_Vol1.pdf
http://www.mrc-bsu.cam.ac.uk/wp-content/uploads/WinBUGS_Vol2.pdf
http://www.mrc-bsu.cam.ac.uk/wp-content/uploads/WinBUGS_Vol3.pdf

OpenBUGS examples:
http://www.openbugs.net/w/Examples
http://mathstat.helsinki.fi/openbugs/ExamplesFrames.html

JAGS models and data for all these examples are in:

http://sourceforge.net/projects/mcmc-jags/files/Examples/2.x/

JAGS' author has a R package for BUGS examples:
https://r-forge.r-project.org/projects/bugs-examples/
To install the package, install.packages("BUGSExamples", repos="http://R-Forge.R-project.org")

----

Above is the original README.txt file.

This folder is copied from: https://github.com/stan-dev/example-models/tree/master/bugs_examples.
14 changes: 14 additions & 0 deletions benchmark/stan/bugs_examples/vol1/blocker/blocker.data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"rt" <-
c(3, 7, 5, 102, 28, 4, 98, 60, 25, 138, 64, 45, 9, 57, 25, 33,
28, 8, 6, 32, 27, 22)
"nt" <-
c(38, 114, 69, 1533, 355, 59, 945, 632, 278, 1916, 873, 263,
291, 858, 154, 207, 251, 151, 174, 209, 391, 680)
"rc" <-
c(3, 14, 11, 127, 27, 6, 152, 48, 37, 188, 52, 47, 16, 45, 31,
38, 12, 6, 3, 40, 43, 39)
"nc" <-
c(39, 116, 93, 1520, 365, 52, 939, 471, 282, 1921, 583, 266,
293, 883, 147, 213, 122, 154, 134, 218, 364, 674)
"N" <-
22
7 changes: 7 additions & 0 deletions benchmark/stan/bugs_examples/vol1/blocker/blocker.data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"nc": [39, 116, 93, 1520, 365, 52, 939, 471, 282, 1921, 583, 266, 293, 883, 147, 213, 122, 154, 134, 218, 364, 674],
"rc": [3, 14, 11, 127, 27, 6, 152, 48, 37, 188, 52, 47, 16, 45, 31, 38, 12, 6, 3, 40, 43, 39],
"N": 22,
"nt": [38, 114, 69, 1533, 355, 59, 945, 632, 278, 1916, 873, 263, 291, 858, 154, 207, 251, 151, 174, 209, 391, 680],
"rt": [3, 7, 5, 102, 28, 4, 98, 60, 25, 138, 64, 45, 9, 57, 25, 33, 28, 8, 6, 32, 27, 22]
}
6 changes: 6 additions & 0 deletions benchmark/stan/bugs_examples/vol1/blocker/blocker.init.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
d <- 0
delta <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
sigmasq_delta <- 1
mu <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
delta <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
delta_new <- 0
7 changes: 7 additions & 0 deletions benchmark/stan/bugs_examples/vol1/blocker/blocker.init.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"mu": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"delta": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"d": 0,
"delta_new": 0,
"sigmasq_delta": 1
}
29 changes: 29 additions & 0 deletions benchmark/stan/bugs_examples/vol1/blocker/blocker.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//DOC See \url{http://www.openbugs.net/Examples/Blockers.html}.
data {
int<lower=0> N;
array[N] int<lower=0> nt;
array[N] int<lower=0> rt;
array[N] int<lower=0> nc;
array[N] int<lower=0> rc;
}
parameters {
real d;
real<lower=0> sigmasq_delta;
vector[N] mu;
vector[N] delta;
real delta_new;
}
transformed parameters {
real<lower=0> sigma_delta;
sigma_delta = sqrt(sigmasq_delta);
}
model {
rt ~ binomial_logit(nt, mu + delta);
rc ~ binomial_logit(nc, mu);
delta ~ student_t(4, d, sigma_delta);
mu ~ normal(0, sqrt(1E5));
d ~ normal(0, 1E3);
sigmasq_delta ~ inv_gamma(1E-3, 1E-3);
// FIXME: sample in generated quantities in later version
delta_new ~ student_t(4, d, sigma_delta);
}
15 changes: 15 additions & 0 deletions benchmark/stan/bugs_examples/vol1/blocker/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
STAN_HOME = ../../../../..
PGM = blocker#
CXX = g++
BOOSTPATH = $(shell find $(STAN_HOME)/lib -path '*lib/boost_*' -regex '.*lib\/boost_[^/]*')
EIGENPATH = $(shell find $(STAN_HOME)/lib -path '*lib/eigen_*' -regex '.*lib\/eigen_[^/]*')
CPPFLAGS = -I $(BOOSTPATH) -I$(EIGENPATH) -I $(STAN_HOME)/src
LIBFLAGS = -L$(STAN_HOME)/bin -lstan

$(PGM) :
$(STAN_HOME)/bin/stanc --name=$(PGM) $(PGM).stan
$(CXX) -O3 -DNDEBUG $(CPPFLAGS) $(PGM).cpp -o $(PGM) $(LIBFLAGS)
./$(PGM) data=$(PGM).data.R sample

clean :
rm -rf $(PGM).cpp samples.csv $(PGM)
36 changes: 36 additions & 0 deletions benchmark/stan/bugs_examples/vol1/blocker/post.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## take a look at the samples and compare with results computed
## in other program.


library(coda)

N <- 22;

post <- read.csv(file = "samples.csv", header = TRUE, comment.char = '#');
colnames(post) <- c("d", "sigmasq_delta",
paste("mu", 1:N, sep = ''),
paste("delta", 1:N, sep = ''));

sigma_delta <- sqrt(post[, "sigmasq_delta"]);
delta.new <- post[, "d"] + rt(nrow(post), df = 4) * sigma_delta;

poi <- cbind(post[, "d"], delta.new, sigma_delta);
pars <- c("d", "delta.new", "sigma");
colnames(poi) <- pars;
summary(as.mcmc(poi))

library(BUGSExamples)


# theta0 <- theta[1] - theta[2] * mean(X)
ex <- list(name = "Blockers", parameters = pars,
nSample = 10000, nBurnin = 1000, nThin = 1,
nChain = 3);

jagspost <- runExample(ex, engine = 'JAGS')
summary(jagspost$coda)





51 changes: 51 additions & 0 deletions benchmark/stan/bugs_examples/vol1/bones/bones.data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
nChild <-
13
nInd <-
34
gamma <-
structure(c(0.7425, 10.267, 10.5215, 9.3877, 0.2593, -0.5998,
10.5891, 6.6701, 8.8921, 12.4275, 12.4788, 13.7778, 5.8374, 6.9485,
13.7184, 14.3476, 4.8066, 9.1037, 10.7483, 0.3887, 3.2573, 11.6273,
15.8842, 14.8926, 15.5487, 15.4091, 3.9216, 15.475, 0.4927, 1.3059,
1.5012, 0.8021, 5.0022, 4.0168, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1.0153, 7.0421, 14.4242,
17.4685, 16.7409, 16.872, 17.0061, 5.2099, 16.9406, 1.3556, 1.8793,
1.8902, 2.3873, 6.3704, 5.1537, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 17.4944, 2.3016, 2.497, 2.3689, 3.9525, 8.2832, 7.1053,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3.2535, 3.2306,
2.9495, 5.3198, 10.4988, 10.3038), .Dim = c(34, 4))
delta <-
c(2.9541, 0.6603, 0.7965, 1.0495, 5.7874, 3.8376, 0.6324, 0.8272,
0.6968, 0.8747, 0.8136, 0.8246, 0.6711, 0.978, 1.1528, 1.6923,
1.0331, 0.5381, 1.0688, 8.1123, 0.9974, 1.2656, 1.1802, 1.368,
1.5435, 1.5006, 1.6766, 1.4297, 3.385, 3.3085, 3.4007, 2.0906,
1.0954, 1.5329)
ncat <-
c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3,
3, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 5, 5)
grade <-
structure(c(1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, -1,
2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
1, 1, 1, 1, 1, 1, 2, 2, 2, -1, 2, 2, 1, 1, 1, 1, 1, 2, 1, 2,
2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1,
1, 1, 1, -1, -1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, -1, -1, 1,
1, -1, 2, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 2, 2, 1, 1, 1,
-1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2,
2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, -1, 2, 2, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, -1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 2, 1, 1, 1, 1, 1, -1, -1, 2, 1, -1, 1, 2, 2, 1, 1, 1, 1, 1,
1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
1, 1, 1, 1, 2, 2, 3, 2, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, -1, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 2, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1,
1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 4, 2, 3, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 3, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 1, 1, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2,
2, 3, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 2, 3, 3, 3, 4,
5, 5, 5, 5, 1, 1, 1, 1, 3, 3, 3, 4, 4, 5, 5, 5, 5), .Dim = c(13,
34))
51 changes: 51 additions & 0 deletions benchmark/stan/bugs_examples/vol1/bones/bones.data.R.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
nChild <-
13
nInd <-
34
gamma <-
structure(c(0.7425, 10.267, 10.5215, 9.3877, 0.2593, -0.5998,
10.5891, 6.6701, 8.8921, 12.4275, 12.4788, 13.7778, 5.8374, 6.9485,
13.7184, 14.3476, 4.8066, 9.1037, 10.7483, 0.3887, 3.2573, 11.6273,
15.8842, 14.8926, 15.5487, 15.4091, 3.9216, 15.475, 0.4927, 1.3059,
1.5012, 0.8021, 5.0022, 4.0168, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1.0153, 7.0421, 14.4242,
17.4685, 16.7409, 16.872, 17.0061, 5.2099, 16.9406, 1.3556, 1.8793,
1.8902, 2.3873, 6.3704, 5.1537, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, 17.4944, 2.3016, 2.497, 2.3689, 3.9525, 8.2832, 7.1053,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 3.2535, 3.2306,
2.9495, 5.3198, 10.4988, 10.3038), .Dim = c(34, 4))
delta <-
c(2.9541, 0.6603, 0.7965, 1.0495, 5.7874, 3.8376, 0.6324, 0.8272,
0.6968, 0.8747, 0.8136, 0.8246, 0.6711, 0.978, 1.1528, 1.6923,
1.0331, 0.5381, 1.0688, 8.1123, 0.9974, 1.2656, 1.1802, 1.368,
1.5435, 1.5006, 1.6766, 1.4297, 3.385, 3.3085, 3.4007, 2.0906,
1.0954, 1.5329)
ncat <-
c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3,
3, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 5, 5)
grade <-
structure(c(1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, NA,
2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
1, 1, 1, 1, 1, 1, 2, 2, 2, NA, 2, 2, 1, 1, 1, 1, 1, 2, 1, 2,
2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1,
1, 1, 1, NA, NA, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, NA, NA, 1,
1, NA, 2, NA, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, NA, 2, 2, 1, 1, 1,
NA, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2,
2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, NA, 2, 2, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, NA, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 2, 1, 1, 1, 1, 1, NA, NA, 2, 1, NA, 1, 2, 2, 1, 1, 1, 1, 1,
1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
1, 1, 1, 1, 2, 2, 3, 2, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, NA, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, NA, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, NA, NA, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 2, NA, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1,
1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 4, 2, 3, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 3, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 1, 1, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2,
2, 3, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 2, 3, 3, 3, 4,
5, 5, 5, 5, 1, 1, 1, 1, 3, 3, 3, 4, 4, 5, 5, 5, 5), .Dim = c(13,
34))
57 changes: 57 additions & 0 deletions benchmark/stan/bugs_examples/vol1/bones/bones.data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"ncat": [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 5, 5],
"nChild": 13,
"nInd": 34,
"grade": [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1],
[2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 2, 1, 1],
[2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 4, 3, 3, 3, 1, 1],
[2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 4, 5, 4, 3, 1, 1],
[2, 1, 1, 1, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 3, 2, 1, 1, 1, 1, 1, 3, 1, 5, 5, 5, 4, 2, 3],
[2, 1, 1, 1, 2, 2, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 2, -1, 1, 3, 2, 1, 1, 1, 1, 1, 3, 1, 5, 5, 5, 5, 3, 3],
[2, 1, 1, 1, 2, 2, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 2, -1, 1, 3, 3, 1, 1, 1, 1, 1, 3, 1, 5, 5, 5, 5, 3, 3],
[2, 1, 2, 2, 2, 2, 2, 2, 1, -1, -1, 1, 2, 2, 1, 1, 2, 2, 1, 3, 2, 1, 1, 1, 1, 1, 3, 1, 5, 5, 5, 5, 3, 4],
[2, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 1, 1, 1, 3, 1, 5, 5, 5, 5, 4, 4],
[2, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 2, -1, 2, 3, 3, 1, 1, 1, 1, 1, 3, 1, 5, 5, 5, 5, 5, 5],
[2, 1, -1, 2, 2, 2, -1, 2, 2, 1, -1, -1, 2, 2, -1, -1, 2, 1, 2, 3, 3, -1, 1, -1, 1, 1, 3, 1, 5, 5, 5, 5, 5, 5],
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 1, -1, 2, 1, 3, 2, 5, 5, 5, 5, 5, 5],
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, -1, 2, -1, 2, 3, 4, 5, 5, 5, 5, 5, 5]
],
"delta": [2.9541, 0.6603, 0.7965, 1.0495, 5.7874, 3.8376, 0.6324, 0.8272, 0.6968, 0.8747, 0.8136, 0.8246, 0.6711, 0.978, 1.1528, 1.6923, 1.0331, 0.5381, 1.0688, 8.1123, 0.9974, 1.2656, 1.1802, 1.368, 1.5435, 1.5006, 1.6766, 1.4297, 3.385, 3.3085, 3.4007, 2.0906, 1.0954, 1.5329],
"gamma": [
[0.7425, -1, -1, -1],
[10.267, -1, -1, -1],
[10.5215, -1, -1, -1],
[9.3877, -1, -1, -1],
[0.2593, -1, -1, -1],
[-0.5998, -1, -1, -1],
[10.5891, -1, -1, -1],
[6.6701, -1, -1, -1],
[8.8921, -1, -1, -1],
[12.4275, -1, -1, -1],
[12.4788, -1, -1, -1],
[13.7778, -1, -1, -1],
[5.8374, -1, -1, -1],
[6.9485, -1, -1, -1],
[13.7184, -1, -1, -1],
[14.3476, -1, -1, -1],
[4.8066, -1, -1, -1],
[9.1037, -1, -1, -1],
[10.7483, -1, -1, -1],
[0.3887, 1.0153, -1, -1],
[3.2573, 7.0421, -1, -1],
[11.6273, 14.4242, -1, -1],
[15.8842, 17.4685, -1, -1],
[14.8926, 16.7409, -1, -1],
[15.5487, 16.872, -1, -1],
[15.4091, 17.0061, -1, -1],
[3.9216, 5.2099, -1, -1],
[15.475, 16.9406, 17.4944, -1],
[0.4927, 1.3556, 2.3016, 3.2535],
[1.3059, 1.8793, 2.497, 3.2306],
[1.5012, 1.8902, 2.3689, 2.9495],
[0.8021, 2.3873, 3.9525, 5.3198],
[5.0022, 6.3704, 8.2832, 10.4988],
[4.0168, 5.1537, 7.1053, 10.3038]
]
}
57 changes: 57 additions & 0 deletions benchmark/stan/bugs_examples/vol1/bones/bones.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Bones: latent trait model for multiple ordered
* categorical responses
* http://www.openbugs.net/Examples/Bones.html
*
*
* Note:
* 1. Since it is just the response that is
* modelled as categorical distribution,
* we should be able to run the model now except handling
* the missing. However, the data structure is a bit
* difficult to deal with (Allowing some redundancy
* in the transformed parameters (Q here), the model
* is fine in Stan.
* 2. The missing data is recoded as `-1`, which is
* not modeled for `gamma` as in the OpenBUGS example
* and not modeled for `grade`.
*/

data {
int<lower=0> nChild;
int<lower=0> nInd;
array[nInd, 4] real gamma; // -1 if missing
array[nInd] real delta;
array[nInd] int<lower=0> ncat;
array[nChild, nInd] int grade; // -1 if missing
}
parameters {
array[nChild] real theta;
}
model {
array[nChild, nInd, 5] real p;
array[nChild, nInd, 4] real Q;
theta ~ normal(0.0, 36);
for (i in 1 : nChild) {
// Probability of observing grade k given theta
for (j in 1 : nInd) {
// Cumulative probability of > grade k given theta
for (k in 1 : (ncat[j] - 1)) {
Q[i, j, k] = inv_logit(delta[j] * (theta[i] - gamma[j, k]));
}
p[i, j, 1] = 1 - Q[i, j, 1];
for (k in 2 : (ncat[j] - 1)) {
p[i, j, k] = Q[i, j, k - 1] - Q[i, j, k];
}
p[i, j, ncat[j]] = Q[i, j, ncat[j] - 1];

// incement log probability directly because grade[i, j]
// has categorical distribution with varying dimension.
// for missing grade[i, j] = -1, there is no log prob
// contribution
if (grade[i, j] != -1) {
target += log(p[i, j, grade[i, j]]);
}
}
}
}
15 changes: 15 additions & 0 deletions benchmark/stan/bugs_examples/vol1/bones/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
STAN_HOME = ../../../../..
PGM = bones#
CXX = clang++
BOOSTPATH = $(shell find $(STAN_HOME)/lib -path '*lib/boost_*' -regex '.*lib\/boost_[^/]*')
EIGENPATH = $(shell find $(STAN_HOME)/lib -path '*lib/eigen_*' -regex '.*lib\/eigen_[^/]*')
CPPFLAGS = -I $(BOOSTPATH) -I$(EIGENPATH) -I $(STAN_HOME)/src
LIBFLAGS = -L$(STAN_HOME)/bin -lstan

$(PGM) :
$(STAN_HOME)/bin/stanc --name=$(PGM) $(PGM).stan
$(CXX) -O3 -Wall $(CPPFLAGS) $(PGM).cpp -o $(PGM) $(LIBFLAGS)
./$(PGM) data=$(PGM).data.R sample

clean :
rm -rf $(PGM).cpp samples.csv $(PGM)
Loading

2 comments on commit ff49d61

@sunxd3
Copy link
Member Author

@sunxd3 sunxd3 commented on ff49d61 Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/116566

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.2 -m "<description of version>" ff49d61c1c0a25cea7833fcc5fd61b0e258ea630
git push origin v0.6.2

Please sign in to comment.