[R] rgamma function produces NaN values

Sanna Soomro @@@oomro97 @end|ng |rom gm@||@com
Wed Mar 4 16:21:32 CET 2020


Hi,

In my code, I want to sample from the posterior distribution to get
estimates for each parameter via the Bayesian approach. My model has
spatial coefficient and lasso penalty.

When I run this line

gibbs_lasso(y = Y, x= X, W=W.rook, tau = 0.5, M=2)

It works, however, when I changed M from 2 to 5, I get the following error:

Error in rgig(1, 0.5, (SIGMA[m, ]/theta2) * ((y[ik] - crossprod(x[ik,  :
  invalid parameters for GIG distribution: lambda=0.5, chi=nan, psi=nan
In addition: Warning message:
In rgamma(1, shape = 1.5 * n + a0, rate = SIGMAgamma + b0) : NAs produced

It makes sense that rgig cannot accept NaN values of sigma parameter in its
computation. But why does rgamma produces NaN value for sigma? The gamma
distribution require both shape and scale parameters to be positive and my
R computations for both should always be positive then sigma can be sampled
easily. So, what went wrong in my code?

Best regards
Sanna


More information about the R-help mailing list