Concern with user-defined prior distributions

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

lp__ is defined over an unconstrained parameter, from which your bounded variable t is constructed via a constraining transform. This nonlinear transform picks up a Jacobian adjustment, which is applied automatically and under the hood, and is thus included in lp__.

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!).