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

Setting distributional parameters to constant bug #227

Closed
athowes opened this issue Aug 5, 2024 · 6 comments · Fixed by #282
Closed

Setting distributional parameters to constant bug #227

athowes opened this issue Aug 5, 2024 · 6 comments · Fixed by #282
Labels
bug Something isn't working medium Nice to have for next release

Comments

@athowes
Copy link
Collaborator

athowes commented Aug 5, 2024

We have two bugs I've seen when trying to set distirbutional parameters to be constant:

set.seed(1)

obs_time <- 25
sample_size <- 500

meanlog <- 1.8
sdlog <- 0.5

# The mean of the lognormal distribution is: exp(meanlog + 0.5 * sdlog^2)

sim_obs <- simulate_gillespie() |>
  simulate_secondary(
    dist = rlnorm,
    meanlog = meanlog,
    sdlog = sdlog
  ) |>
  observe_process() |>
  filter_obs_by_obs_time(obs_time = obs_time)

sim_obs <- sim_obs[sample(seq_len(.N), sample_size, replace = FALSE)]
prep_obs <- as_latent_individual(sim_obs)

Bug 1

epidist(data = prep_obs, formula = brms::bf(mu ~ 1, sigma = 1), seed = 1)

results in:

Error: The following priors do not correspond to any model parameter: 
Intercept_sigma ~ normal(0, 0.5)
Function 'default_prior' might be helpful to you.

Reason: in epidist_prior we hard code that the model has to have certain priors.

Bug 2

Even if we didn't have this prior problem, then we have the following bug:

epidist(data = prep_obs, formula = brms::bf(mu ~ 1, shape = 1), family = stats::Gamma(link = "log"))
Compiling Stan program...
Semantic error in '/var/folders/4r/hkp4v9fn3wx044_hk8qnsjxw0000gn/T/RtmpSfhylK/model-3c965f0b3c81.stan', line 61, column 14 to column 72:
   -------------------------------------------------
    59:      mu += Intercept;
    60:      mu = exp(mu);
    61:      target += latent_gamma_lpdf(Y | mu, shape, pwindow, swindow, vreal1);
                       ^
    62:    }
    63:    // priors including constants
   -------------------------------------------------

Ill-typed arguments supplied to function 'latent_gamma_lpdf':
(vector, vector, real, vector, vector, array[] real)
Available signatures:
(vector, vector, vector, vector, vector, array[] real) => real
  The third argument must be vector but got real

Reason: our custom likelihood expects a vector for all distributional parameters. If instead its a real then it throws an error.

@seabbs
Copy link
Contributor

seabbs commented Aug 5, 2024

what happens if you do this instead by setting the prior to be constant? I am not convinced this is the most important functionality to support so would push it unless you have a strong view that its functionality we need?

@athowes
Copy link
Collaborator Author

athowes commented Aug 5, 2024

Currently we do not support users passing in priors. Perhaps #71 (allowing users to pass in priors) is therefore more important to do. And then we wouldn't need to support this in the formula.

@seabbs
Copy link
Contributor

seabbs commented Aug 6, 2024

I think #71 would support a broader range of use cases? Obviously it would be nice if this worked though

@athowes
Copy link
Collaborator Author

athowes commented Aug 6, 2024

Yes #71 would support a broader range of use cases and I agree is more of a priority.

(Sorry, I wrote 71 but really it's #196 now)

@athowes athowes added the medium Nice to have for next release label Aug 8, 2024
@athowes athowes mentioned this issue Aug 8, 2024
2 tasks
@athowes
Copy link
Collaborator Author

athowes commented Aug 29, 2024

I think this will be closed via #255 but I need to check, then I'll close this. Maybe add a test.

@athowes
Copy link
Collaborator Author

athowes commented Sep 5, 2024

Nope, get error:

Error in `f()`:No available prior to replace in old_prior found for:
<lower=0> sigma ~ lognormal(-0.7, 0.4)
Run `rlang::last_trace()` to see where the error occurred.

To fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working medium Nice to have for next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants