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

what input can I provide to dispersion in convert_summary_stats_to_params() #234

Open
avallecam opened this issue Feb 1, 2024 · 0 comments
Labels
question Further information is requested

Comments

@avallecam
Copy link
Member

Trying to solve this problem, is there a way I can prioritize convert_summary_stats_to_params() over extract_param()?

library(epiparameter)
library(tidyverse)

# How to get the mean and sd values 
# for this influenza distribution?

influenza_generation <- 
  epidist_db(disease = "influenza",
             epi_dist = "generation")
#> Returning 1 results that match the criteria (1 are parameterised). 
#> Use subset to filter by entry variables or single_epidist to return a single entry. 
#> To retrieve the short citation for each use the 'get_citation' function

influenza_generation_discrete <- 
  discretise(influenza_generation)

# problem
# the summary statistics do not have mean and sd
influenza_generation$summary_stats
#> $quantiles
#>   5  95 
#> 0.9 5.1 
#> 
#> $median
#> [1] 2.7
#> 
#> $median_ci_limits
#> [1] 2.0 3.5
#> 
#> $median_ci
#> [1] 95
influenza_generation$summary_stats$median
#> [1] 2.7
influenza_generation$summary_stats$quantiles
#>   5  95 
#> 0.9 5.1

# solution
# extract parameters from percentiles
influenza_extracted <- extract_param(
  type = "percentiles",
  values = c(influenza_generation$summary_stats$quantiles[1],
             influenza_generation$summary_stats$quantiles[2]),
  distribution = "lnorm",
  percentiles = c(0.05,0.95)
)
#> Stochastic numerical optimisation used. 
#> Rerun function multiple times to check global optimum is found

influenza_extracted
#>   meanlog     sdlog 
#> 0.7619400 0.5272806

# question: 
# what input is expected for dispersion?

# I tried quantiles, but is not in the set
convert_summary_stats_to_params(
  distribution = "lnorm",
  median = influenza_generation$summary_stats$median,
  quantiles = influenza_generation$summary_stats$quantiles
)
#> Error in chk_ss(x): Assertion on 'names(x)' failed: Must be a subset of {'mean','median','mode','var','sd','cv','skewness','ex_kurtosis','dispersion'}, but has additional elements {'quantiles'}.

# I tried interquartile range, but failed
convert_summary_stats_to_params(
  distribution = "lnorm",
  median = influenza_generation$summary_stats$median,
  dispersion = influenza_generation$summary_stats$quantiles
)
#> Error in (function (...) : Cannot calculate lognormal parameters from given input

Created on 2024-02-01 with reprex v2.0.2

@avallecam avallecam added the question Further information is requested label Feb 1, 2024
@avallecam avallecam changed the title what input can I provide to dispersion in convert_summary_stats_to_params() what input can I provide to dispersion in convert_summary_stats_to_params() Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant