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

set tolerance instead of max to delay_opts() for uncertain distributions #857

Open
avallecam opened this issue Nov 20, 2024 · 1 comment

Comments

@avallecam
Copy link

Summary:
delay_opts() uses tolerance instead of max for certain distributions, but not uncertain.

Description:
Previously reported for certain distributions in #665 and fixed in #716

Reproducible Steps:

library("EpiNow2")
#> 
#> Attaching package: 'EpiNow2'
#> The following object is masked from 'package:stats':
#> 
#>     Gamma

certain <- EpiNow2::LogNormal(
  mean = 4,
  sd = 1
)

uncertain <- EpiNow2::LogNormal(
  mean = EpiNow2::Normal(mean = 4,sd = 0.5),
  sd = EpiNow2::Normal(mean = 1, sd = 0.5)
)
#> Warning: ! Uncertain lognormal distribution specified in terms of parameters that are
#>   not the "natural" parameters of the distribution meanlog and sdlog.
#> ℹ Converting using a crude and very approximate method that is likely to
#>   produce biased results.
#> ℹ If possible it is preferable to specify the distribution directly in terms of
#>   the natural parameters.

EpiNow2::delay_opts(certain)
#> ℹ Unconstrained distributon passed as a delay.
#> ℹ Constraining with default CDF cutoff 0.001.
#> ℹ To silence this message, specify delay distributions with `max` or
#>   `tolerance`.
#> - lognormal distribution (cdf_cutoff: 0.001):
#>   meanlog:
#>     1.4
#>   sdlog:
#>     0.25

EpiNow2::delay_opts(uncertain)
#> Error in `check_stan_delay()`:
#> ℹ All distribution passed to the model need to have a finite maximum,
#>   which can be achieved either by setting `max` or non-zero `cdf_cutoff`.

packageVersion("EpiNow2")
#> [1] '1.6.1'

Created on 2024-11-20 with reprex v2.1.1


@sbfnk
Copy link
Contributor

sbfnk commented Nov 20, 2024

This behaviour is as expected - we can't constrain uncertain distributions with a CDF cutoff.

The underlying reason is that this in that case we can't work out how long the constrained and discretised PMF is in advance (as it will depend on the parameter values as they're being sampled by stan) which creates all sorts of issues.

The issue could and should be addressed with better documentation / messaging.

@sbfnk sbfnk added this to the CRAN v1.7 release milestone Dec 10, 2024
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