Search code examples
jagsrjags

Does JAGS have a log function for bases other than e?


I am trying to calculate a log with base 2 in JAGS, but can't find a way to implement this. In the documentation I can't find a way to do this, and I am hoping I am missing something, or that someone knows a workaround.

Thanks in advance for any help, Benny


Solution

  • Log base 2 (or the binary logarithm) can be calculated with this trick here (link to wikipedia). As an example in R using the natural log:

    log_2_result <- log(15, base = 2)
    
    log_2_trick <- log(15) / log(2)
    
    identical(log_2_result, log_2_trick)
    [1] TRUE
    
    

    JAGS has the log function, so you could use a similar approach to above (for log_2_trick). An important thing to note, however, is that because log is a link function in JAGS you can only input a scalar into it.