# Lp__ and target +=

Is that corret the value of “lp__” should always equal to the right hand side of “target +=”?

The problem is that I tried to reproduce the value of “lp__” in R but failed. I used “target+=” in Stan programming and I think there should not be a problem of Jacobian because I have already done the transformation in my coding. So I am wondering which part is wrong.

Thanks a lot for helping!

Btw, I didn’t paste my code here because it is too long…

`lp__` will be equal to the sum of all `target +=` calls if you don’t have any parameter constraints. If you have any constraints (e.g., `<lower=0>`), then Stan will automatically add the necessary Jacobian corrections

2 Likes

Thanks a lot for your help!

I used <lower = 0> in the “transformed parameters” block but not “parameters” block. Does that also lead to adding Jacobian corrections?

No, constraints in transformed parameters do not lead to corrections. However, in order to consistently satisfy that constraint without any constrained parameters in the `parameters` block, you must have applied a nonlinear transform. Assuming that your transform is nonlinear, then if your transformed parameter is anywhere used on the left-hand side of a sampling statement (or as the first argument in a lpdf/lpmf on the right-hand side of a `target +=` statement), then you might need to apply your a Jacobian adjustment in order to get the inference that you intend.

Note that sampling statements with a `~` are really `target += ` statements in disguise, so these will also influence `lp__`. Note also that some parameter types, including covariance matrices, are inherently constrained types that induce a Jacobian adjustment even without an explicitly declared parameter constraint. See the reference manual here for more on the constraint transforms and their Jacobians:

2 Likes

To add to @jsocolar’s excellent answer, we could give you a more concrete explanation if you posted your model and the R code being used to recreate `lp`

1 Like

Hi all. Thanks so much for helping! Just figured out why there is a big difference. I incorrectly deleted one line of code in my stan file…