Menu

read.monitor not working correctly?

runjags
2015-06-10
2015-09-16
  • Kristin Broms

    Kristin Broms - 2015-06-10

    Hi,

    First off, thanks for the package. If I can get it working, it'll be really nice to be able to run jags in the background and eventually use it for cross-validation. But currently, the output from results.jags() is not consistent (or correct) when combined with the method='bgparallel'...

    I am using R (version 3.2.0) within RStudio (version 0.99.441), and runjags version 2.0.1.

    Here is the gist of what I am doing (fitting a multi-species occupancy model) and the results I am getting:

    out.parallel <- run.jags("MSOM.bgparallel.R", inits=inits,
                                monitor=params, data=data,
                                n.chains=3, burnin=1000, adapt=1000, sample=2000,
                                method='bgparallel', keep.jags.file=TRUE)
    
      SigmaDet <- results.jags(out.parallel, read.monitor=c('sigmaDetCoef') )
      denplot(SigmaDet)  
      summary(SigmaDet)
    #   > round(summary(SigmaDet), 2)
    #   Lower95 Median Upper95  Mean   SD  Mode MCerr MC%ofSD SSeff AC.100 psrf
    #   sigmaDetCoef[1]   -2.55  -1.57   -0.57 -1.57 0.51 -1.55  0.01     1.3  5540   0.01    1
    #   sigmaDetCoef[2]   -1.82  -1.09   -0.42 -1.10 0.36 -1.09  0.00     1.4  5430  -0.01    1
    #   sigmaDetCoef[3]    1.64   2.41    3.47  2.48 0.49  2.32  0.01     1.6  3740   0.01    1
    #   sigmaDetCoef[4]    1.11   1.65    2.37  1.69 0.35  1.59  0.01     1.5  4225   0.00    1
    #   sigmaDetCoef[5]    0.96   2.06    3.12  2.06 0.55  2.06  0.01     1.7  3367  -0.02    1
    #   sigmaDetCoef[6]    0.03   1.24    2.52  1.26 0.64  1.23  0.01     1.4  5001   0.01    1
    #   sigmaDetCoef[7]   -0.94   0.63    2.26  0.65 0.80  0.62  0.01     1.4  5406   0.00    1
    #   sigmaDetCoef[8]   -0.99   0.70    2.60  0.77 0.91  0.63  0.01     1.4  4841   0.00    1     
        tmp <- results.jags(out.parallel, read.monitor=c('sigmaDetCoef', 'muDetCoef') )
        denplot(tmp)  
        summary(tmp)
    #     > round(summary(tmp), 2)
    #     Lower95 Median Upper95  Mean   SD  Mode MCerr MC%ofSD SSeff AC.100 psrf
    #     muDetCoef[1]      -2.55  -1.57   -0.57 -1.57 0.51 -1.55  0.01     1.3  5540   0.01    1
    #     muDetCoef[2]      -1.82  -1.09   -0.42 -1.10 0.36 -1.09  0.00     1.4  5430  -0.01    1
    #     muDetCoef[3]       1.64   2.41    3.47  2.48 0.49  2.32  0.01     1.6  3740   0.01    1
    #     muDetCoef[4]       1.11   1.65    2.37  1.69 0.35  1.59  0.01     1.5  4225   0.00    1
    #     muDetCoef[5]       0.96   2.06    3.12  2.06 0.55  2.06  0.01     1.7  3367  -0.02    1
    #     muDetCoef[6]       0.03   1.24    2.52  1.26 0.64  1.23  0.01     1.4  5001   0.01    1
    #     muDetCoef[7]      -0.94   0.63    2.26  0.65 0.80  0.62  0.01     1.4  5406   0.00    1
    #     muDetCoef[8]      -0.99   0.70    2.60  0.77 0.91  0.63  0.01     1.4  4841   0.00    1
    #     sigmaDetCoef[1]   -1.17   0.19    1.49  0.18 0.67  0.18  0.01     1.4  5261   0.00    1
    #     sigmaDetCoef[2]   -1.19   0.13    1.51  0.15 0.69  0.09  0.01     1.5  4695   0.01    1
    #     sigmaDetCoef[3]    0.97   1.88    2.83  1.88 0.47  1.87  0.01     1.4  5034  -0.01    1
    #     sigmaDetCoef[4]   -1.93  -0.65    0.45 -0.68 0.61 -0.59  0.01     1.7  3632   0.00    1
    #     sigmaDetCoef[5]    1.44   2.30    3.40  2.38 0.53  2.22  0.01     2.7  1403   0.07    1
    #     sigmaDetCoef[6]    1.26   2.42    3.97  2.54 0.73  2.22  0.01     1.9  2796   0.00    1
    #     sigmaDetCoef[7]    2.00   3.55    5.41  3.66 0.91  3.33  0.02     2.1  2191   0.03    1
    #     sigmaDetCoef[8]    1.49   3.16    5.84  3.38 1.19  2.89  0.03     2.4  1718   0.03    1# 
    

    'sigmaDetCoef' has morphed into 'muDetCoef'! And neither makes sense- the sigmaDetCoef's come from dunif(0, 10) distributions...

    Let me know if I should post more information. I'm not entirely sure if it's a bug, or if I am using the functions incorrectly, or if it is a problem within the model.

    Thank you,
    Kristin

     
  • Matt Denwood

    Matt Denwood - 2015-06-11

    Hi Kristin

    Thanks for the message - it does indeed seem that there is a bug in the code that selects results using the read.monitor argument of results.jags. I will look into this ASAP.

    In the meantime the following code should work around the bug (although it does mean that all of your parameters will have to be read in by results.jags):

    allresults <- results.jags(out.parallel, summarise=FALSE)
    
    summary(allresults, vars='sigmaDetCoef')
    plot(allresults, vars='sigmaDetCoef')
    

    Does this work as expected?

    Thanks again.

    Matt

     
  • Matt Denwood

    Matt Denwood - 2015-09-16

    Hi Kristin

    This bug is fixed in version 2.0.2 which is now on CRAN. I have added several tests to make sure it works to my local build procedure, so hopefully you will now get the results you expected :)

    Thanks again for reporting the issue.

    Matt

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.