[R] Dicrete Laplace distribution

Moshe Olshansky m_olshansky at yahoo.com
Fri Mar 12 03:33:15 CET 2010


Dear Nicolette,

You can always use the bruit force solution which works for every discrete distribution with finite number of states: let p0,p1,...,pK be the probabilities of 0,1,...,K (such that they sum up to 1).
Let P <- c(p0,p1,...,pK) and P1 <- c(cumsum(P),1)
Now let x = runif() (uniform in (0,1)) and k <- which(P1 >= x)[1] has the desired distribution.

Regards,
Moshe.

--- On Fri, 12/3/10, Raquel Nicolette <nicolette at ua.pt> wrote:

> From: Raquel Nicolette <nicolette at ua.pt>
> Subject: [R] Dicrete Laplace distribution
> To: r-help at r-project.org
> Received: Friday, 12 March, 2010, 2:47 AM
>  
> 
> Hello,
> 
>  
> 
>  <http://tolstoy.newcastle.edu.au/R/help/04/07/0312.html#0313qlink1> Could
> anybody tell me how to generate discrete Laplacian
> distribution? 
> 
>  
> 
> I need to sample  uma discretised Laplacian density
> like this:
> 
>  
> 
>   J(  g -> g´)  ~ exp (-lambda | g´ - g
> |)  g in {0,…, gmax} 
> 
>  
> 
> Thanks,
> 
>  
> 
> Nicolette
> 
> 
>     [[alternative HTML version deleted]]
> 
> 
> -----Inline Attachment Follows-----
> 
> ______________________________________________
> 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.
>



More information about the R-help mailing list