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

Upgrade time-varying models using chunks and specifying prior parameters #171

Merged
merged 14 commits into from
Apr 23, 2024

Conversation

ntorresd
Copy link
Member

@ntorresd ntorresd commented Apr 15, 2024

  • Please check if the PR fulfills these requirements
  • I have read the CONTRIBUTING guidelines
  • A new item has been added to NEWS.md
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Checks have been run locally and pass
  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    This PR:

  • What is the current behavior? (You can also link to an open issue here)

Currently, one value of the force-of-infection is estimated for every year in the time spanned by the serosurvey.

data(chagas2012)
serodata <- prepare_serodata(chagas2012)
seromodel <- fit_seromodel(serodata, foi_model = "tv_normal")

image

  • What is the new behavior (if this is a feature change)?
    Now chunks can be specified either by size:
seromodel <- fit_seromodel(serodata, foi_model = "tv_normal", chunk_size = 10)

image

or explicitly specifying the chunk structure:

chunks <- rep(c(1, 2, 3, 4, 5), c(10, 10, 15, 15, max(serodata$age_mean_f)-50))
seromodel <- fit_seromodel(serodata, foi_model = "tv_normal", chunks = chunks)

image

  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
    Yes, two breaking changes are introduced in this PR:
  1. The use of chunks is a breaking change allowing users to specify prior knowledge about the force-of-infection by assigning constant values of the force-of-infection to specific time intervals. The default behavior is chunk_size=1, which recovers previous results.
  2. Now the user can specify the initial location and scale parameters of the distributions used in the stan files by means of foi_location and foi_scale parameters in fit_seromodel. The interpretation of these parameters may vary depending on the specified model. To recover previous results, users should use:
# tv_normal model
fit_seromodel(
   serodata = serodata,
   foi_model = "tv_normal",
   foi_location = 0,
   foi_scale = 1,
   ...
)

# tv_normal_log model
fit_seromodel(
   serodata = serodata,
   foi_model = "tv_normal",
   foi_location = -6,
   foi_scale = 4,
   ...
)
  • Other information:

- Define stan function `prob_infected` in a separate script
- Change models to estimate de foi by chunks rather than by year
- Allow flexible specification of distribution parameters by means of
`foi_location` and `foi_scale`
- Now tests for time-varying models use simulated data and chunks
- The model accuracy is tested by comparing the foi used to simulate
the data and the estimated foi
- Files with benchmarks used with previous strategy are removed
@ntorresd ntorresd marked this pull request as ready for review April 16, 2024 01:37
@ntorresd ntorresd requested a review from ben18785 April 16, 2024 01:37
@ntorresd ntorresd requested review from ekamau and removed request for ben18785 April 16, 2024 16:42
Copy link
Collaborator

@ekamau ekamau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, except for the minor aesthetic in one of the stan files

int<lower=0> n_obs;
int n_pos[n_obs];
int n_total[n_obs];
int <lower=1>age_max;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for uniformity remove the space between int and <lower=1>
i.e., int<lower=1> age_max;

@ntorresd ntorresd merged commit ef45b15 into main Apr 23, 2024
8 checks passed
@ntorresd ntorresd deleted the upgrade-tv-models branch April 23, 2024 16:19
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

Successfully merging this pull request may close these issues.

2 participants