In order to familiarize with Stan and Bayesian Inference,I’m trying to fit a **Normal distribution** in a **Triangle distribution** and infer **a** e **b** parameters (just a toy project):

Triangle(y | a,b)=2/(b-a)*(1-ABS(y-(a+b)(b-a)))

`STAN CODE`

functions {

real triangle_lpdf(real x,real a,real b)

{

return log(2/(b-a)) + log1m(fabs(x-(a+b)/(b-a)));

pairs }

}

data {

int N;

real x[N];

}

parameters {

real a;

real b;

}

model {

a ~ normal(-2,0.5);

b ~ normal(2,0.5);

for(n in 1:N)

//target += log(2/(b-a)) + log1m(fabs(x[n]-(a+b)/(b-a)));

target += triangle_lpdf(x[n] | a,b);

}

`R CODE`

data=list(x=rnorm(100,0,0.3),N=100)

fit=stan(file=“TestTriangle.stan”,data=data,chains = 1)

`RESULT`

mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat

a 0.0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 28 1.04

b 0.0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 14 1.08

lp__ 7807.7 6.25 19.67 7766.87 7814.33 7814.33 7814.33 7814.33 10 1.12

while I would expect something like:

-1<a<0

0<b<1

I understated this is more a didactic question nevertheless I’d like some advise on why my assumptions are not correct.

Thank You