[R] Rejection sampling to draw from distributions

From: Anup Nandialath <anup_nandialath_at_yahoo.com>
Date: Fri, 14 Mar 2008 14:43:07 -0700 (PDT)


Dear friends,

Please find below the code that I have employed for a rejection sampler to draw from asymmetric laplace distributions. I was wondering if this code can be written more efficiently? Are there more efficient ways of drawing random numbers from asymmetric laplace distributions??

Thanks in advance for your help and have a great weekend.

Regards

Anup



ral <- function(n,p,s=3)
{

rout <- matrix(0,n)
for(i in 1:n)
{

  repeat
    {
      root <- rnorm(1)
      ratio <- dal(val=root, p=p)/(s*dnorm(root))
      alpha <- runif(1, min=0, max=1)
      if(alpha<ratio)
        {break}
      }

   rout[i,] <- root
}
return(rout)}        

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
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. Received on Fri 14 Mar 2008 - 21:45:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 15 Mar 2008 - 03:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive