# Can (Should) I center the observations of an exponential distribution?

Let’s think of a simple exponential model (which works well and fast)

data {
int <lower = 0> N;     // number of observations
int <lower = 0> K;     // number of parameters
row_vector[K] X[N];
real y[N];
}

parameters {
vector[K] beta;
}

model {
beta ~ normal(0, 1);
for(t in 1:N)
y[t] ~ exponential(exp(X[t]*beta));
}


My model is actually more complicated and the chains don’t mix. I am trying to reparameterize the model using the fact that if X \sim Exp(\lambda) then X \times \lambda \sim Exp(1)

data {
int <lower = 0> N;     // number of observations
int <lower = 0> K;     // number of parameters
row_vector[K] X[N];
real y[N];
}

parameters {
vector[K] beta;
}

transformed parameters{
real y_std [N];
for(t in 1:N)
y_std[t] = y[t]* exp(X[t]*beta);
}

model {
beta ~ normal(0, 1);
for(t in 1:N)
y_std[t] ~ exponential(1);
}


But this second model is not right (does not recover the parameters in synthetic data). Does anyone know why? Thanks!

Edit: see code in response below

1 Like

I think the reparametrization introduces a change of variables and you’ll need the Jacobian adjustment.

4 Likes

Thanks, that was it. The following model code produces posterior parameters distributions that match the first code (and the truth). It is is 50% slower for this simple example.

model {
real y_std [N];
for(t in 1:N)
y_std[t] = y[t]* exp(X[t]*beta);
beta ~ normal(0, 1);
for(t in 1:N){
y_std[t] ~ exponential(1);
target += X[t]*beta;
}
}


So that was it. Thanks.

4 Likes

Happy to help! You should mark your own answer as the solution. It has the code. I merely gave a hint.

2 Likes

Thanks. I did now.