suyusung / R2jags

R2jags: Using R to Run 'JAGS'
8 stars 3 forks source link

Is pD ever computed in the same way as BUGS, using R2jags? #19

Open giabaio opened 5 months ago

giabaio commented 5 months ago

Hi there, This may be a silly question -- but I know in the R2jags code, the print method has a line

msgDICRule <- ifelse(x$DICbyR, "(using the rule, pD = var(deviance)/2)", "(using the rule, pD = Dbar-Dhat)")

which seems to indicate that, sometimes, x$DICbyR may be FALSE and therefore pD would be computed in the same way as BUGS would. All the times I've used JAGS/R2jags, though, I don't think this has ever happened and R2jags/JAGS, I think, always compute pD as var(deviance)/2.

I know you can estimate the value that BUGS would calculate using rjags::dic.samples(), but I wanted to make sure that the ifelse statement was actually activated, at least in theory?

Thanks! Gianluca

giabaio commented 5 months ago

Related to this, would you consider a PR to modify the naming of the pD object to avoid confusion? I have a fork of your package and have made some changes (which I don't think break anything, as far as I've tested) to rename the resulting value (pV instead of pD), which then propagates to the print method too. In fact, I have added an option to compute pD using rjags::dic.samples(), which may be helpful too... Happy to send a PR if it helps.

suyusung commented 5 months ago

I merged your fix. Can you provide short description on these: Argument names in code not in docs: pD n.iter.pd n.adapt?

giabaio commented 5 months ago

Thank you! That's very helpful. I think I have added the description of these in the .Rd file under /man, haven't I?

Il check more specifically later though. Thank you!


Gianluca Baio Professor of Statistics and Health Economics | Head of Department

Department of Statistical Science | University College London 1-19 Torrington Place, London, WC1E 6BT, UK Twitter: @stats_uclhttps://twitter.com/stats_UCL | Instagram: @stats_UCLhttps://instagram.com/ucl.stats/

Telephone: +44(0)20 7679 1248 (internal: 41248) Website: http://www.homepages.ucl.ac.uk/~ucakgba Blog: https://gianluca.statistica.it/blog/ Book a meeting with me: https://book.morgen.so/gianlucabaio/book-me


From: Yu-Sung Su @.> Sent: Sunday, June 23, 2024 2:17:55 PM To: suyusung/R2jags @.> Cc: Baio, Gianluca @.>; Author @.> Subject: Re: [suyusung/R2jags] Is pD ever computed in the same way as BUGS, using R2jags? (Issue #19)

⚠ Caution: External sender

I merged your fix. Can you provide short description on these: Argument names in code not in docs: pD n.iter.pd n.adapt?

— Reply to this email directly, view it on GitHubhttps://github.com/suyusung/R2jags/issues/19#issuecomment-2184985794, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACCRVSKFSU2QJUVZFCRZ5H3ZI3DIHAVCNFSM6AAAAABI6P7NUKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBUHE4DKNZZGQ. You are receiving this because you authored the thread.Message ID: @.***>

giabaio commented 5 months ago

Yes, I have checked and the new options are described in the man file jags.Rd.

G

giabaio commented 5 months ago

Thanks for merging the PR --- this is very helpful! I may fiddle with the package a bit more, as I'm using it extensively to complement a book --- hope OK?

suyusung commented 5 months ago

Sure. Your contribution can lively update this package.

suyusung commented 5 months ago

I have made some changes to ensure the package to pass the R CMD check. Please let me know when you are done with the patch. I will upload the new package on to the CRAN.

giabaio commented 5 months ago

Perfect. So:

  1. There's a small change --- I set the adapt step to be silent (so force progress.bar="none" and quiet=TRUE). I also have a few tidyverse functions for post-processing, like traceplots, acfplots, posterior plots etc. They are currently under my non-CRAN package bmhe --- they do NOT need to be ported into R2jags and they would also rely on tidyverse, which is a negative, as it would add a dependency. If you want them though, I am happy to add the code.
  2. I am toying with the ideal of allowing the user to set a global set of options (like options(r2j.progress.bar="text") or options(r2j.quiet=FALSE)) and then let the main functions read the preferred behaviour from there. Nothing would change with respect to what happens now, in terms of default, but the advantage is that you would be able to modify the default globally, if you need to. So, for instance, if I use R2jags inside a quarto project to compile R code into a document, I could shut all the messages and text output (which I don't want to appear in the resulting document), while not having to specify in the call to jags the options progress.bar="none", quiet=TRUE all the time... This is minor, too, I guess --- I find it helpful in my own specific project (for which I have a separate branch of my fork to R2jags). Again, if you think that's worth it, I can look into this.

I think bottom line, I can either very quickly implement 1. so you can submit to CRAN and avoid the potential bug (which didn't impact the results all the time, in my experience, but occasionally it would very badly) or if you want all, give me a couple days and then I'll send another PR...

Let me know what you think!

suyusung commented 5 months ago

I think I would prefer option 2 for now.

giabaio commented 5 months ago

[like] Baio, Gianluca reacted to your message:


From: Yu-Sung Su @.> Sent: Wednesday, June 26, 2024 12:07:15 AM To: suyusung/R2jags @.> Cc: Baio, Gianluca @.>; Author @.> Subject: Re: [suyusung/R2jags] Is pD ever computed in the same way as BUGS, using R2jags? (Issue #19)

⚠ Caution: External sender

I think I would prefer option 2 for now.

— Reply to this email directly, view it on GitHubhttps://github.com/suyusung/R2jags/issues/19#issuecomment-2190235099, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACCRVSIGX43N3RENTKC4U43ZJIA3HAVCNFSM6AAAAABI6P7NUKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJQGIZTKMBZHE. You are receiving this because you authored the thread.Message ID: @.***>

giabaio commented 5 months ago

So just to make sure, are you happy with the current patched version, or would you like the options argument too?