Skip to content

Instantly share code, notes, and snippets.

@leoniedu
Created April 9, 2010 02:10

Revisions

  1. leoniedu revised this gist Apr 9, 2010. 1 changed file with 27 additions and 2 deletions.
    29 changes: 27 additions & 2 deletions test_rjags.R
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ## bug?

    write('model {
    for (i in 1:n.rows) {
    y[i] ~ dnorm(y.hat[i], tau.y)
    @@ -15,6 +15,31 @@ y[1] <- NA
    x <- rnorm(10)
    n.rows <- 10
    sdp <- 100
    print(y[1])
    ## NA
    m <- jags.model("model.bug")
    ms <- jags.samples(m, n.iter=1000)
    y[1]
    print(y[1])
    ## -1.797693e+308 instead of NA
    ## R version 2.10.1 (2009-12-14)
    ## x86_64-apple-darwin9.8.0


    ## sessionInfo()
    ## R version 2.10.1 (2009-12-14)
    ## x86_64-apple-darwin9.8.0

    ## locale:
    ## [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

    ## attached base packages:
    ## [1] splines stats graphics grDevices utils datasets methods
    ## [8] base

    ## other attached packages:
    ## [1] survival_2.35-8 Zelig_3.4-8 boot_1.2-41 MASS_7.3-5
    ## [5] R2jags_0.02-02 rjags_1.0.3-13 R2WinBUGS_2.1-16 coda_0.13-4
    ## [9] lattice_0.18-3

    ## loaded via a namespace (and not attached):
    ## [1] grid_2.10.1
  2. leoniedu created this gist Apr 9, 2010.
    20 changes: 20 additions & 0 deletions test_rjags.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    ## bug?
    write('model {
    for (i in 1:n.rows) {
    y[i] ~ dnorm(y.hat[i], tau.y)
    y.hat[i] <- b.0 + b.1 * x[i]
    }
    b.0 ~ dnorm (0, 1/(sdp^2))
    b.1 ~ dnorm (0, 1/(sdp^2))
    tau.y ~ dgamma(.0001, .0001)
    sigma.y <- pow(tau.y, -(1/2))
    }', file="model.bug")
    library(rjags)
    y <- rnorm(10)
    y[1] <- NA
    x <- rnorm(10)
    n.rows <- 10
    sdp <- 100
    m <- jags.model("model.bug")
    ms <- jags.samples(m, n.iter=1000)
    y[1]