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

Referencing likelihood/bru_obs parameters in joint models #256

Open
aaron-oz opened this issue Dec 5, 2024 · 4 comments
Open

Referencing likelihood/bru_obs parameters in joint models #256

aaron-oz opened this issue Dec 5, 2024 · 4 comments

Comments

@aaron-oz
Copy link

aaron-oz commented Dec 5, 2024

I'm fitting a joint model with two spatially varying ZIP likelihoods. From the tutorials and documentation (as far as I can tell), it's not obvious how best to correctly reference the two zero-probability parameter for zero-inflated poisson_1 parameters during prediction, or for that matter how to generally reference hyperparameters.

The summary of the bru.fit looks like this:

...
Model hyperparameters:
                                                            mean    sd ...
zero-probability parameter for zero-inflated poisson_1     0.839 0.001 ...      
zero-probability parameter for zero-inflated poisson_1[2]  0.988 0.001 ...
...

Working from the ZIP/ZAP vignette, I tried to reference these parameters in the predict formula like this:

total.scaling.prob <- (1 - zero_probability_parameter_for_zero_inflated_poisson_1[1])
total.lambda <- ...
total.expect <- total.scaling.prob * total.lambda
feat.scaling.prob <- (1 - zero_probability_parameter_for_zero_inflated_poisson_1[2])
feat.lambda <- ...
feat.expect <- feat.scaling.prob * feat.lambda

list(
total.scaling.prob = total.scaling.prob,
total.expect=total.expect,
feat.scaling.prob = feat.scaling.prob,
feat.expect=feat.expect
)

This works for the first one (total in my example), but this returns NA/NaNs for the terms relying on the second zero-prob hyperparameter. For example, printing my predict object returns:

$total.scaling.prob
       mean           sd    q0.025      q0.5    q0.975    median sd.mc_std_err
1 0.1608452 0.0007659288 0.1599901 0.1607657 0.1619182 0.1607657  0.0003228154

$feat.scaling.prob
  mean sd q0.025 q0.5 q0.975 median sd.mc_std_err mean.mc_std_err
1  NaN NA     NA   NA     NA     NA           NaN              NA

I have a few general questions from this:

  1. Does the ordering of these hyperparameters always align with the order of the bru_obs passed into bru()? I can tell that it the ordering aligns in this example based on the values of the zero-prob parameters. That is, I ran bru(comps, bru_obs_total, bru_obs_feat) and zero-probability parameter for zero-inflated poisson_1is frombru_obs_totalandzero-probability parameter for zero-inflated poisson_1[2]is frombru_obs_feat`.

  2. How can I reference these (or other hyperparameters) in predict or generate formulas?

  3. Is there documentation anywhere that explains what objects are available for named reference in the predict/generate formulas?

Let me know if it would be helpful for me to put together a reproducible example. Also let me know if there is a more appropriate venue to pose questions like this. I'm not sure it's necessarily an issue or a bug.

Many thanks for working on this great package (and neat extension to INLA).

@finnlindgren
Copy link
Collaborator

The names in the inla summary output for the parameters are "sanitized" using bru_standardise_names(), https://inlabru-org.github.io/inlabru/reference/bru_standardise_names.html
(Make sure to use the latest inlabru from CRAN to get a bug fix for that function)

Perhaps the easiest way to get the full list of standardised names is to run generate(fit, n.samples=1) and inspect the output; it will list all the component names, and the hyperparameter names.

While the ordering of parameters in inla is mostly predictable, I would recommend not relying on it.

In the long term plans for inlabru is to make the hyperparameters accessible by standard names "within" each component, just as name_latent makes the hidden latent variables for component name available to the predictor expression, whereas name by itself is the "effect of name". So in the future, hopefully name_prec would work, as well as tag_some_likelihood_parameter, whereas "tag" is a name given to each observation model like()/bru_obs().

@finnlindgren
Copy link
Collaborator

The Details section of https://inlabru-org.github.io/inlabru/reference/predict.bru.html has some information about what's available to the predictor expressions.

@finnlindgren
Copy link
Collaborator

The likelihood specific hyperparameters should be in the same order as given to bru(). When the models are of different typ that doesn't matter if one references them by name, but in your example one has to rely on the ordering, at least in the names themselves; the [2] is attached to the second observation model when there are two of the same sort. Unfortunately the naming of the inla output is dependent on internal inla implementation details for some models. So making a more standardised translation in the inlabru output is a likely future solution.

@aaron-oz
Copy link
Author

aaron-oz commented Dec 6, 2024

Thank you for your prompt help, Finn. That's all useful information and reviewing generate(fit, n.samples=1) helped me find the appropriate name for the second ZIP prob: zero_probability_parameter_for_zero_inflated_poisson_1_2_.

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