Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Jacobian transformations for priors #95

Closed
seananderson opened this issue May 24, 2022 · 2 comments
Closed

Add Jacobian transformations for priors #95

seananderson opened this issue May 24, 2022 · 2 comments

Comments

@seananderson
Copy link
Member

This will require an argument flag in sdmTMB() since they should only be applied if going to tmbstan, not for marginal maximum likelihood.

Regarding the PC prior, from @joenomiddlename:

Regarding the PC prior sampling in Stan. I think the Jacobian is given in the Appendix (A.6 Theorem 2.6) of the preprint of the main text https://arxiv.org/pdf/1503.00256.pdf. The authors give the prior pdf in terms of the range / SD and the kappa / tau parametrizations. Then, I believe the (range) prior should only be used it once if the range is shared.

It appears the paper breaks down the priors into the two parts, the range and the sd (lambda1 and lambda 2). The first part is marginal, the latter conditional

See screenshots below. And, it looks like I already set it up with the range and SD conditional on range priors separately inside the function, so it's just a matter of somehow only applying the range part once if the range is shared (I'll start a separate issue):

  Type range_ll = log(dhalf) + log(lam1) + log(pow(range, -1. - dhalf)) -
                  lam1 * pow(range, -dhalf);
  Type sigma_ll = log(lam2) - lam2 * sigma;
  Type penalty = range_ll + sigma_ll;

(in src/utils.h)

The transformation relevant to the Jacobian is just from the part inside the absolute value bars below. The log absolute derivative of the transform, so log(abs(D(transformation))). Then remember whether to add or subtract.

Screenshot of Skim (2022-04-21, 11-02-54 PM)

Screenshot of Skim (2022-04-21, 11-04-05 PM)

Note that conditioning is equivalent to conditioning

@ericward-noaa
Copy link
Collaborator

Just making notes to myself. The Jacobian adjustments are just at the end of the lines on the marginals. They are:

P(sigma) = sqrt(8*nu) / (rho^2)

P(sigma | rho) = C * kappa^nu

And C is defined on P 18 of the PDF linked above,
image

@ericward-noaa
Copy link
Collaborator

ericward-noaa commented May 31, 2022

I think this is working and am going to port it over into the cpp file. Tests in inst/jacobian-pcprior-tests.r Some comparisons:

Spatial variance, sigma_O (real value = 0.2)

type mean_sigmaO median_sigmaO
Prior no adjustment 0.189 0.189
Prior with adjustment 0.190 0.190

Range (real value = 0.1)

type mean_range median_range
Prior no adjustment 0.106 0.106
Prior with adjustment 0.101 0.101

Sigma_obs (real value = 0.04)

type mean_sigma median_sigma
Prior no adjustment 0.04 0.04
Prior with adjustment 0.04 0.04

B0 (real value = 2)

type mean_B0 median_B0
Prior no adjustment 1.987 1.987
Prior with adjustment 1.982 1.982

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants