Hello,
I have two representation of the same regression
y = a * x + mu
y - a * x ~ lognormal(mu, sigma);
1) works but gives Warning
2) is stable but give a slightly wrong result
1)------------------------------------------------
data{
int N;
vector[N] y;
real mu;
real sigma;
vector<lower=0>[N] x;
}
parameters{
real<lower=0, upper=1> a;
}
transformed parameters{
vector[N] y_regressed_log;
for(n in 1:N) y_regressed_log[n] = log(y[n]) + log1m((a*x[n]) ./ y[n]);
}
model{
y_regressed_log ~ normal(mu, sigma);
for(n in 1:N) target += -log(y[n]) - log1m((a*x[n]) ./ y[n]);
}
The following numerical problems occured the indicated number of times after warmup on chain 4
count
Exception thrown at line 19: normal_log: Random variable[2] is nan, but must not be nan! 28
Exception thrown at line 19: normal_log: Random variable[1998] is nan, but must not be nan! 5
Exception thrown at line 19: normal_log: Random variable[21] is nan, but must not be nan! 4
2)-----------------------------------------------------
data{
int N;
vector[N] y;
real log_mu;
real log_sigma;
vector<lower=0>[N] log_x;
}
parameters{
real log_a;
}
transformed parameters{
vector[N] log_model;
for(n in 1:N){
vector[2] temp;
temp[1] = log_a + log_x[n];
temp[2] = log_mu;
log_model[n] = log_sum_exp(temp);
}
}
model{
y ~ lognormal(log_model, log_sigma);
}
-----------------------------------------------------------------------
Any ides?
Thanks a lot!