I have been trying to generate random values from horseshoe prior for a plotting purpose…
Yet they all seems a little bit off compared to the original plots in Carvalho et al. (2009)Handling Sparsity via the Horseshoe.
Some of the functions that I have used are
library(LaplacesDemon) where I provided the parameter values for local shrinkage and global shrinkage…
Could someone provide some insights why this is happening?
Any helps will be appreciated.
I believe that is because Carvalho et al. are showing a composite probability density across many draws of the local
lambda parameter. Each individual component of the horseshoe (i.e. for each term it is applied to) is a normal distribution. Only when you stack them up do you get the spike and slab appearance.
Here’s one way to generate that look.
library(dplyr, warn.conflicts = FALSE)
# plot over this range
xseq <- seq(-5, 5, length.out = 500)
# how many terms for the horseshoe
N <- 100
# generate N densities, drawing the lambda parameter from a half-cauchy
denslist <- purrr::map(abs(rcauchy(N, 0, 1)), ~dhs(xseq, lambda=.x, tau=0.5))
# add them all together and divide by the number of draws
dens <- Reduce(`+`, denslist)/N
data.frame(x=xseq, density=dens) %>%
ggplot(aes(x, density)) +