# Concern with user-defined prior distributions

**URL:** <https://discourse.mc-stan.org/t/concern-with-user-defined-prior-distributions/36467>\
**Category:** General\
**Created:** [September 3, 2024, 3:54am UTC](https://discourse.mc-stan.org/t/concern-with-user-defined-prior-distributions/36467 "2024-09-03T03:54:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrickb](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Patrickb](https://discourse.mc-stan.org/u/Patrickb)\
**Post date:** [September 3, 2024, 3:54am UTC](https://discourse.mc-stan.org/t/concern-with-user-defined-prior-distributions/36467/1 "2024-09-03T03:54:38Z")

</div>

Dear Stan users,

I am in the early stages of writing a model for analyzing data with a user-defined prior distribution.  
As a first step, I want to make sure that I can write a Stan program that can sample from my prior distribution f  
where f(t) is proportional to t^2 on the domain (0, d), where d will be specified through the data list.

My stan code is as follows. For the record, note that I run with d=1.3 and inits=list(t=1).

functions  
{  
real lowertriangle\_lpdf(real x)  
{  
return 2\*log(x);  
}  
}  
data  
{  
real d;  
}  
parameters  
{  
real\<lower=0, upper=d\> t;  
}  
model  
{  
t ~ lowertriangle(); // my custom prior distribution, described in functions block above  
}

When I run it, I get a sample from t which seems correct; however, when I plot t vs the built-in variable lp\_\_,  
I get a skewed parabola, going up with t at the beginning but going deep down for the larger values its domain,  
which is far from the expected t vs 2\*log(t) plot.

Is is a bug? Or am I missing something in the way Stan is working here?  
Thanks in advance for any help.

Patrick

---

<div class="post-metadata">

**Author:** ![jsocolar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jsocolar/32/2486_2.png) [@jsocolar](https://discourse.mc-stan.org/u/jsocolar)\
**Post date:** [September 3, 2024, 11:10am UTC](https://discourse.mc-stan.org/t/concern-with-user-defined-prior-distributions/36467/2 "2024-09-03T11:10:58Z")

</div>

`lp__` is defined over an unconstrained parameter, from which your bounded variable `t` is constructed via a [constraining transform](https://mc-stan.org/docs/reference-manual/transforms.html). This nonlinear transform picks up a [Jacobian adjustment](https://jsocolar.github.io/jacobians/), which is applied automatically and under the hood, and is thus included in `lp__`.

---

<div class="post-metadata">

**Author:** ![Patrickb](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Patrickb](https://discourse.mc-stan.org/u/Patrickb)\
**Post date:** [September 3, 2024, 3:43pm UTC](https://discourse.mc-stan.org/t/concern-with-user-defined-prior-distributions/36467/3 "2024-09-03T15:43:12Z")

</div>

Dear Jacob,

Applying the back-transform to lp\_\_, I indeed get the expected 2\*log(t) for the log-probability of my variable t. That will be useful in the future development of my algorithm when I add data as I will need the (back-transformed) log-probability values.

Thank you very much for your informative answer (and for the links to useful & well-presented webpages!).
