loc <- 1; b <- 2
y <- rlaplace(n = 100, loc = loc, scale = b)
mean(y) # sample mean
loc # population mean
var(y) # sample variance
2 * b^2 # population variance
if (FALSE) loc <- 0; b <- 1.5; x <- seq(-5, 5, by = 0.01)
plot(x, dlaplace(x, loc, b), type = "l", col = "blue",
main = "Blue is density, orange is the CDF", ylim = c(0,1),
sub = "Purple are 5,10,...,95 percentiles", las = 1, ylab = "")
abline(h = 0, col = "blue", lty = 2)
lines(qlaplace(seq(0.05,0.95,by = 0.05), loc, b),
dlaplace(qlaplace(seq(0.05, 0.95, by = 0.05), loc, b), loc, b),
col = "purple", lty = 3, type = "h")
lines(x, plaplace(x, loc, b), type = "l", col = "orange")
abline(h = 0, lty = 2)
plaplace(qlaplace(seq(0.05, 0.95, by = 0.05), loc, b), loc, b)
Run the code above in your browser using DataLab