Link functions in stochastic declarations

126 views
Skip to first unread message

Matthijs Hollanders

unread,
Mar 24, 2022, 5:15:36 PM3/24/22
to nimble-users
Hi,

I am able to specify priors with a log-link function as follows:

log(phi) ~ dexp(1(

However, when I try to do it for exp, exp(phi) ~ dexp(1), I get the following error:

Error in processLinks() : Error, unknown link function: exp

In section 5.2.6 of the manual, it says exp is the inverse of the link function log. Can we only declare stochastic nodes with the link function, and not with the inverse?

Sincerely,

Matt

Perry de Valpine

unread,
Mar 24, 2022, 5:38:12 PM3/24/22
to Matthijs Hollanders, nimble-users
Hi Matt,

The short answer is no.  There is a fixed set of supported link functions.  They are defined in the source code as:

linkInverses <- list('logit' = quote(expit()),
                     'log' = quote(exp()),
                     'probit' = quote(phi()),
                     'cloglog' = quote(icloglog()) )

There is no mechanism to add link functions while using the package.  If you wanted to expand available links, you could add to this list in the source code in the format shown, rebuild the package, and I think it will work.  But putting links on the left-hand side of a model declaration is really just a kind of syntactic sugar for creating (in your example) a stochastic node and a deterministic node that uses the link function, so you might as well simply add the additional line of model code.

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/312f0e00-38d2-4ab3-bc51-b0689e67a978n%40googlegroups.com.

David Pleydell

unread,
Mar 25, 2022, 7:48:18 AM3/25/22
to nimble-users
Hi Matt

Another approach is to use the change of variables technique to create a distribution for phi (given that you know the distribution of exp(phi)).  I often do this when performing MCMC so that I can sample on unbounded scales. In your case phi is unbounded, whereas exp(phi) is bounded at zero. So each time your MCMC (assuming that is what you are doing) proposes a -ve sample for exp(phi) it will be rejected. This is not efficient. Far better (in my opinion) to sample on an unbounded scale. 

Attached is some code that shows how you can do this in your example.  

Best regards
David
dLogExp.R

Matthijs Hollanders

unread,
Mar 27, 2022, 2:47:05 AM3/27/22
to nimble-users
Thank you both for the info and the R script!

David Pleydell

unread,
Mar 31, 2022, 4:29:44 AM3/31/22
to nimble-users
Your welcome Matt!

Actually, your question prompted me to put together an R package to provide a set of transformed (to the real line) distributions.  Links to the package are provided here

Best regards
David

Reply all
Reply to author
Forward
0 new messages