JAGS 4.3.0 is released

The source tarball for JAGS 4.3.0 is now available from Sourceforge. Binary distributions will be available later. See the updated manual for details of the features in the new version. This version is fully compatible with the current version of rjags on CRAN.

29 thoughts on “JAGS 4.3.0 is released

  1. Pingback: JAGS 4.3.0 is released | A bunch of data

  2. Pingback: JAGS 4.3.0 is released – Mubashir Qasim

  3. Hello. What’s the best way to uninstall/remove a previous version of JAGS on macOS? I’d like to install the latter version of JAGS but according to some sources it’s better to remove the previous version of JAGS. Thank you!

  4. Hi Dr Plummer, thanks very much for your work on JAGS, I have just got started using it and it is very helpful. One question though in your 4.3 user manual I can’t seem to find any section that gives a list of distributions that are supported, their functions, and the parameters they require, e.g. dnorm(0, 1e-4) I assume the second parameter is the precision or the square root of the precision but can’t seem to find which it is.

    • The normal distribution is covered in section 9.2.1 of the JAGS user manual which covers continuous univariate distributions in the bugs module. It might be easier to find if I add an index at the back. I’ll look into that for the next version.

  5. Dear Martyn, Thank you so much for all your work with JAGS! I noticed that up to JAGS 4.2 in conjugate beta prior – binomial likelihood problems the “ConjugateBeta” sampler was used. I just noticed that JAGS 4.3 uses “BinomSlicer”. I wonder what motivated the change. Thank you!

    • That’s just a silly mistake. When I added BinomSlicer sampling method, I accidentally gave it higher precedence than the conjugate sampler. I will fix this.

  6. Hi. I’m not sure if JAGS-4.3.0.exe found on sourceforge is meant to be used also for R 3.3.0 or later on Windows. Can you please clarify? Thank you.

  7. Hi Martyn
    Thanks for all you’ve contributed to the world through JAGS. What a tremendous public-service!

    I’m writing because a relatively simple model that I’ve been running for years will not converge in JAGS 4.3. I’m particularly surprised because the troublesome parameters are slopes in a Poisson regression model, so they’re not particularly complex.

    We can re-create the differences between the two JAGS versions on multiple computers (all running Windows). The same issue occurs whether running jags through the packages jagsUI or rjags.

    This has happened multiple times too. The model that was run is pasted below. The data are counts of birds along survey routes that are conducted annually. You can access the data and the models through the R package bbsBayes (see https://github.com/BrandonEdwards/bbsBayes). In that package this model is called “slope”. This package is used to generate annual indices of abundance for species of North American birds. bbsBayes is a wrapper package for the JAGS data preparation and MCMC modelling used by the United States Geological Survey and Canadian Wildlife Service for their annual reports. It uses the jagsUI package to run the JAGS models.

    So, what might be causing this difference? Is it the samplers?

    Jags 4.3 version of the models run through rjags: FAILS TO CONVERGE. Here’s the list of samplers:
    #list.factories(“sampler”)
    factory status
    1 glm::Holmes-Held TRUE
    2 glm::Generic TRUE
    3 glm::ScaledWishart TRUE
    4 glm::ScaledGamma TRUE
    5 bugs::BinomSlice TRUE
    6 bugs::RW1 TRUE
    7 bugs::Censored TRUE
    8 bugs::Sum TRUE
    9 bugs::DSum TRUE
    10 bugs::Conjugate TRUE
    11 bugs::Dirichlet TRUE
    12 bugs::MNormal TRUE
    13 base::Finite TRUE
    14 base::Slice TRUE

    And the jags 4.2 version of the exact same model and code: CONVERGES WELL. Here’s the list of samplers after running the model.

    jags 4.2 result of

    list.factories(“sampler”)

    factory status

    1 glm::Albert-Chib TRUE

    2 glm::Albert-Chib-Gibbs TRUE

    3 glm::Auxiliary-Mixture TRUE

    4 glm::Linear TRUE

    5 glm::LinearGibbs TRUE

    6 glm::IWLS TRUE

    7 bugs::Censored TRUE

    8 bugs::Sum TRUE

    9 bugs::DSum TRUE

    10 bugs::Conjugate TRUE

    11 bugs::Dirichlet TRUE

    12 bugs::MNormal TRUE

    13 base::Finite TRUE

    14 base::Slice TRUE

    Here’s the model. It includes many derived parameters that aren’t important here, but the key parameters that are failing to converge in JAGS 4.3 are “beta[]” (random-effect slopes) and “BETA” (fixed-effect, hyperparmeter for the mean of the beta[]s). The data are counts (count[]) of birds along annual survey-routes,

    model
    {
    #### counts and overdispersion effects ###### Link-Sauer model with nested observer-route effect
    for( k in 1 : ncounts )
    {

    likelihood

                                Elambdas[k] <- beta[strat[k]] * (year[k] - fixedyear) + eta*firstyr[k] + obs[strat[k],obser[k]] + strata[strat[k]] + yeareffect[year[k],strat[k]]
    
                                Elambda[k] ~ dnorm(Elambdas[k], taunoise)
                                log(lambda[k]) <- Elambda[k]
    
                                count[k] ~ dpois(lambda[k])
                                #----------------------------------#
                                fcount[k] ~ dpois(lambda[k])
                                err[k] <- pow(count[k]-lambda[k],2)/lambda[k]
                                ferr[k] <- pow(fcount[k]-lambda[k],2)/lambda[k]
                                fzero[k] <- equals(fcount[k],0)
                                loglik[k] <- logdensity.pois(count[k], lambda[k])
                                #----------------------------------#
                }
    
                nfzero <- sum(fzero[1:ncounts])
                gof <- sum(err[1:ncounts])
                fgof <- sum(ferr[1:ncounts])
                diffgof <- gof-fgof
                posdiff <- step(diffgof)
    
                taunoise ~ dgamma(0.001,0.001)
                sdnoise <- 1 / pow(taunoise, 0.5)
                sdobs <- 1 / pow(tauobs, 0.5)
                tauobs ~ dgamma(0.001,0.001)
                eta ~ dnorm( 0.0,1.0E-6)
                STRATA ~ dnorm( 0.0,0.01)
                taustrata ~ dgamma(0.001,0.0001) #<- 1/pow(sdbeta,2)#
                sdstrata <- 1/pow(taubeta,0.5)#~ dunif(0.001,10)
    
                #---------------------------------------------------------#
    
                #----------------------------------#
                #### stratum effects  ######
                for( s in 1 : nstrata )
                {
                                #### observer effects  ######
    
                                for( i in 1 : nobservers[s] )
                                {
                                                obs[s,i] ~ dnorm( 0.0,tauobs)
                                }
    
                                #### end observer effects  ######
    
                                beta[s] ~ dnorm(BETA,taubeta)
                                strata[s] ~ dnorm(STRATA,taustrata)
                                sdyear[s] <- 1/pow(tauyear[s],0.5)
                                tauyear[s] ~ dgamma(0.001,0.001) #
    
                                #### stratum specific year effects  ######
                                for( y in ymin : ymax )
                                {
                                                yeareffect[y,s] ~ dnorm( 0.0, tauyear[s])
                                }
    
                                expstrata[s] <- exp(strata[s])
                                overdisp[s] <- 1 + 1/(expstrata[s]*taunoise)
                                #-------------------------------------------------#
    
                }# end s strata loop
    
    
    
                #### hierarchical trend effects  ######
    
    
                BETA ~ dnorm(0,0.01)
    
                taubeta ~ dgamma(1,0.0001) #
                ### informative taubeta, parameterized so that:
                ### mean of taubeta = ~10000
                ### the mean of sdbeta =~ 0.02
                ### there is <5% prob of sdbeta > 0.04 (i.e., there is a small, but non-zero probability that the SD of the stratum beta
                ### terms is large enough to to encompass trends that vary from -8%/year to 8%/year with a continental trend = 0)
                ### this informative prior should only be useful when there are few strata
    
                sdbeta <- 1/pow(taubeta,0.5)#
    
                #### summary statistics  ######
                sdn <- exp(0.5*sdnoise*sdnoise)
    
                for( i in 1 : nstrata )
                {
                                for( t in ymin : ymax )
                                {
                                                for(o in 1 : nobservers[i])
                                                {
                                                                no[i,t,o] <- exp(strata[i] + beta[i]*(t-fixedyear) + yeareffect[t,i] + obs[i,o])
                                                }
    
                                                mn[i,t] <- mean(no[i,t,1 : nobservers[i]])
                                                n[i,t] <- nonzeroweight[i]*(mn[i,t]*sdn)
                                }
                }
    
                #-------------------------------------------------#
    

    }

    Thank you so much for any help you can provide.

    • That doesn’t sound good. It would help a lot if you could send me an R script that would allow me to run the model and collect samples after loading the package and downloading the data.

      • Thank You Martyn:
        Here’s a short script that will allow you to run the model using the sample data that come with the package installation. If you run it with JAGS 4.2 and 4.3, you’ll see the different convergence.

        Run this script once using JAGS 4.3.0 and once using

        JAGS 4.2.0 and compare the differences in the R hat values

        Install latest bbsBayes release, attach package:

        install.packages(“devtools”)
        library(devtools)
        devtools::install_github(“BrandonEdwards/bbsBayes”, ref = “v1.1.0”)
        library(bbsBayes)

        Stratify the sample data that comes with the package

        strat_data <- stratify(by = “bbs_cws”, sample_data = T)

        Prepare stratified data for JAGS using slope model

        jags_data <- prepare_jags_data(strat_data = strat_data,
        species_to_run = “Wood Thrush”,
        model = “slope”)

        Run JAGS Model

        This will take a while. If you have the capability to run

        parallel chains on your computer, change the last argument to

        ‘parallel = TRUE’

        to use 3 cores with 1 chain per core.

        mod <- run_model(jags_data = jags_data,
        parameters_to_save = c(“BETA”, “beta”),
        parallel = FALSE)

        View data frame of r hat values for BETA and beta parameters

        rhat <- r_hat(mod,
        parameter_list = c(“BETA”, “beta”))

      • Hi Martyn

        Have you had a chance to investigate this? Can I help in any other way?

        Thanks again

        Adam

      • Yes I did. The sampler factories in the glm module can give up under certain circumstances, which are triggered by your example. So you are not getting the advantages of the advanced sampling methods for glms. I had tried to fix this in the development version but the compiler grinds to a halt instead, which I spent some time fixing.

        This appears to be an unintended consequence of you using a centred parameterization for the random effects. You could try using a non-centered parameterization to see if that works.

        It’s difficult to make progress debugging this example because it is so huge.

      • Ok. Thanks Martyn. I’ll try an alternate parameterization of the random effects.

    • Hi Again Martyn
      I’ve created a non-centered version of the model. But now the model fails to initialize in 4.3.
      I’ve placed a simplified version of the model, a subset of the data, and a test example script, in a GitHub repository: https://github.com/AdamCSmithCWS/JAGS-version-compare
      In the script, it’s only the initialization step that I’ve tested, since that seems to be the source of the problem. It will also hopefully be a bit easier to re-create because the dataset is much reduced (a full model-run of ~20000 iterations only required ~30 minutes in JAGS 4.2).

      • You can ignore this issue. The most recent update to rjags (4-10, posted Nov 6, 2019) seems to have solved it.
        Thanks for your help.

  8. Hi Martyn,
    I have a model that was written in OpenBugs, where one of the parameters is declared as follows:
    K~dlnorm(11.52,1)I(100000,6000000)

    When running in Jags, I get a compile error on this line with the message: BUGS I(,) notation is only allowed if all parameters are fixed.

    The model works fine in OpenBugs. However, I would like to move the model over to Jags. I am wondering if Jags would declare this parameter differently.
    With thanks,
    Divya

Leave a comment