rlaplacian

How to plot laplacian noise distribution?


I am currently working on Differential Privacy and want to visualize my noise distribution of the data set. I am using Laplacian distribution as my noise addition mechanism.

I have already calculated beta (scale parameter) and the true output of the data set (mean) and wonder which of the Laplace functions I should be using (dlaplace(), plaplace(), qlaplace(), rlaplace() from the rmutil package) for a noise distribution. I also don't understand why I can't just generate a noise distribution with a Laplace parameter and mean, without specifying the data (y,q,p,n) in the functions mentioned above.

My thought of getting the Laplace distribution and visualising it is shown as below:

df <- ?laplace(?,m=33.6, s=7.32)
plot(df)

? represents the areas that I am unsure about, m is the mean and s is the scale parameter.


Solution

  • If you want to plot the density:

    curve(dlaplace(x, m=33.6, s=7.32), from = 0, to = 66)
    

    Laplace density

    ggplot2 equivalent:

    ggplot() + 
       geom_function(fun = function(x) rmutil::dlaplace(x, m = 33.6, s = 7.32)) + 
       expand_limits(x=c(0,66))
    

    If you want random deviates:

    hist(rlaplace(10000, m = 33.6, s = 7.32), col = "gray", breaks = 100)
    

    (the first argument, 10000, is the number of random deviates desired; use geom_histogram() in ggplot)

    Laplace histogram