# Lighthouse problem without using Cauchy Distribution

Hello, I am trying to solve the lighthouse problem without using the cauchy distribution. I want to see if I can write a stan program in the same way I would generate the data.

``````data {
int<lower=0> N;
real beta;
real x[N];
}
parameters {
real theta;
real alpha;
}
model {
alpha ~ uniform(-100,100);
theta ~ uniform(-pi()/2,pi()/2);
x ~ alpha + beta*tan(theta); // should be same as x ~ cauchy(alpha,beta);
}
``````

This program should be equivalent but I run into a parsing error `PARSER EXPECTED: <distribution and parameters>` on the last line.

Is it possible to write the model in this sort of style?

First, if you are going to use uniform priors on `theta` and `alpha`, then you need to declare lower and upper bounds on them in the parameters block, like

``````parameters {
real<lower=-0.5 * pi(), upper = 0.5 * pi()> theta;
real<lower=-100, upper = 100> alpha;
}
``````

at which point you do not need to explicitly specify uniform priors on them in the model block.

But the syntax error comes from the fact that

``````x ~ alpha + beta*tan(theta);
``````

is not valid syntax in the Stan language. I am not really sure what you meant, but if it is equivalent to `x ~ cauchy(alpha, beta);` then you do not need to declare a `theta` parameter.

You can derive the cauchy distribution from the relation `x = alpha + beta*tan(theta)` using standard transformation rules when you assume theta is uniformly distributed from `-pi/2` to `pi/2`. What I want to know is if Stan can do the transformation on its own or do I always need to explicitly state what the distribution is. If Stan can do the transformation on its own it makes writing models easier.

The only transformations Stan does on its own is from the unconstrained parameter space to the parameter space you declare in the parameters block, which can be constrained by lower and / or upper bounds as well as special vectors and matrices.

I realize that one can utilize the quantile function of the Cauchy distribution. But `x ~ alpha + beta * tan(theta);` is not valid syntax. If you use a tilde, then the right-hand side has to be a call to a probability distribution. So, `x ~ cauchy(alpha, beta);` would be legal but would not involve `theta`.

For details on how to implement the `tan` parameterization of the Cauchy see https://betanalpha.github.io/assets/case_studies/fitting_the_cauchy.html.

Instead of the `tan` parameterization you could try a scale mixture of Gaussian density functions. From the reference Michael gives above, you’d have something like

``````y ~ normal(mu, inv_sqrt(tau));
tau ~ gamma(1 / 2, sigma2 / 2);
// ... priors on mu and sigma2
``````