1
$\begingroup$

Can someone check whether I correctly simulate the Horseshoe pdf?

lambda = rcauchy(1000, location = 0, scale = 1)

horseshoe = rnorm(1000, 0,lambda)

hist(horseshoe, breaks = 'FD')

enter image description here

$\endgroup$
7
  • 1
    $\begingroup$ 1. Can you write out the formulae related to the Horseshoe distribution? That way, the question is self-contained. 2. The Horseshoe dist'n uses a half-Cauchy; your formulation allows for $\lambda < 0$. Substitute lambda = abs(rcauchy(...)) to fix this. $\endgroup$
    – jbowman
    Commented Apr 8, 2022 at 17:36
  • $\begingroup$ @jbowman if I knew the correct standard formulation of the Horseshoe distribution simulating from it wouldn't be a problem. But I have seen different versions so I am not sure what's the correct way of specifying it. I have tried the abs() method before but that resulted in a truncated (only +) Horseshoe dist whereas I guess it should be symmetrical around zero because it's being used a Ridge prior. $\endgroup$
    – Amin Shn
    Commented Apr 8, 2022 at 17:49
  • $\begingroup$ abs(rcauchy( can't result in a truncated distribution, as it only affects the standard deviation of the subsequent Normal distribution, which is still symmetric around 0. $\endgroup$
    – jbowman
    Commented Apr 8, 2022 at 18:33
  • $\begingroup$ @jbowman You're right, I had to say truncated(ish) distribution when you plot it, or heavily skewed towards positive values. Try it for yourself and you'll see what I mean, it doesn't look symmetrical like the above plot at all. $\endgroup$
    – Amin Shn
    Commented Apr 8, 2022 at 18:42
  • 4
    $\begingroup$ You have made the mean of the Normal equal to $\lambda$, not the scale parameter. The Horseshoe distribution is a Cauchy - Normal scale mixture. Sorry, I should have caught that in my 1st comment... $\endgroup$
    – jbowman
    Commented Apr 8, 2022 at 22:23

1 Answer 1

4
$\begingroup$

The horseshoe distribution is a zero-mean Cauchy-Normal scale mixture of normals (as @jbowman points out). It has one parameter, scale $\tau$; the bigger $\tau$ is, the heavier the tails are (the higher the probability of observing large positive or negative values). 1

Your simulation assumes $\tau = 1$. You also have to fold the Cauchy (by taking the absolute value) as it doesn't make sense to sample from a Normal with negative standard deviation. That's why your code throws warnings and you end up with a sample that's about half NaN's.

The horseshoe distribution has two equivalent specifications: $$ \lambda \sim \text{Half-Cauchy}(0, 1) \\ X \sim \text{Normal}(0, \lambda \cdot \tau) $$ and $$ \lambda \sim \text{Half-Cauchy}(0, \tau) \\ X \sim \text{Normal}(0, \lambda) $$

It's straightforward to use either to generate a random sample. In the plot I also overlay the histogram with the probability density function.

1 C. M. Carvalho, N. G. Polson, and J. G. Scott (2010). The horseshoe estimator for sparse signals. Biometrika, 97(2):465–480

tau <- 2 # scale parameter of horseshoe distribution
n <- 1000 # number of samples to draw

lambda <- abs(rcauchy(n))
x <- rnorm(n, sd = lambda * tau)
# Or
lambda <- abs(rcauchy(n, scale = tau))
x <- rnorm(n, sd = lambda)

horseshoe-distribution

For completeness, this is the R code to reproduce the plot.

set.seed(1234)

# Probability density function of the horseshoe distribution with scale tau.
dhorseshoe <- function(x, tau = 1) {
  theta2 <- x^2 / (2 * tau^2)
  expint::expint_E1(theta2, scale = TRUE) / sqrt(2 * pi^3 * tau^2)
}

tau <- 2 # scale parameter of horseshoe distribution
n <- 1000 # number of samples to draw

lambda <- abs(rcauchy(n))
x <- rnorm(n, sd = lambda * tau)
# Or
lambda <- abs(rcauchy(n, scale = tau))
x <- rnorm(n, sd = lambda)

hist(
  # The horseshoe distribution has heavy tails and is centered at 0.
  # Let's "zoom in" on values between -100 and 100.
  x[abs(x) < 100],
  breaks = 200, probability = TRUE, col = NULL,
  xlim = c(-100, 100), xlab = NULL, ylim = c(0, 0.4), ylab = NULL,
  main = paste("Horseshoe distribution with scale", tau)
)
curve(dhorseshoe(x, tau = tau), n = 1001, add = TRUE, col = "red")
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.