missing data solution

26 views
Skip to first unread message

Robin Russell

unread,
Oct 28, 2022, 3:09:32 PM10/28/22
to nimble-users
Hello if anyone is interested, one solution to my very poorly worded question is in Walsh et al. 2018 and involves the zero's trick from the WinBUGs manual.  The code is in jags but can be converted to nimble.


regards,

Robin

Perry de Valpine

unread,
Oct 28, 2022, 8:56:07 PM10/28/22
to Robin Russell, nimble-users
Thanks for following up, Robin.

In nimble there is an alternative to the zeros trick.  (The zeros trick is a way to get an arbitrary log probability included in the model by having a fake "data" value that is zero, and declaring it to follow a Poisson.  The log probability of a zero in a Poisson is -lambda.  So by calculating whatever log probability you want and assigning it to lambda, it ends up included in the model's probability calculations.)

In nimble, you can do that arguably a bit more readably and elegantly with a user-defined distribution.  The need arises when one wants to calculate a value, say y, and then have it follow a distribution.  It can be done like this:

y <- [some calculation]
fake_datum ~ d_my_dist(y, arg2, arg3)

When that code is in a model, the log probability contribution will come from calling:
d_my_dist(fake_datum, y, arg2, arg3, log=TRUE)

so you can then write d_my_dist to simply ignore fake_datum and use y, arg2, and arg3 for whatever log probability calculation you want.

HTH
Perry


--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/CAH-82KbFXrWfC32mJumiyxWhrt9POXLrhcNPJuFqsGwoy81MHQ%40mail.gmail.com.

Hossein Baghishani

unread,
Oct 29, 2022, 1:11:37 AM10/29/22
to Perry de Valpine, Robin Russell, nimble-users
Are there some examples in the nimble manual?

Chris Paciorek

unread,
Oct 31, 2022, 2:54:14 PM10/31/22
to Hossein Baghishani, Robin Russell, nimble-users, Perry de Valpine
As far as writing user-defined distributions, yes, in Chapter 12, as well as an example at r-nimble.org/examples

-Chris

Reply all
Reply to author
Forward
0 new messages