[R] rgamma function produces NaN values

PIKAL Petr petr@p|k@| @end|ng |rom prechez@@cz
Thu Mar 5 11:30:10 CET 2020


Hi

what is gibbs_lasso? I did not find any function of this name.

Usually reproducible example greatly enhance your chances to get reasonable
answer.

If any n, a0, SIGMAgamma, b0 is NA rgamma gives you NA.

Cheers
Petr
> -----Original Message-----
> From: R-help <r-help-bounces using r-project.org> On Behalf Of Sanna Soomro
> Sent: Wednesday, March 4, 2020 4:22 PM
> To: r-help using r-project.org
> Subject: [R] rgamma function produces NaN values
> 
> 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
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


More information about the R-help mailing list