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

Make likelihood() work with <epichains_summary>, <epichains>, and <numeric> objects #213

Merged
merged 78 commits into from
May 29, 2024

Conversation

jamesmbaazam
Copy link
Member

@jamesmbaazam jamesmbaazam commented Mar 5, 2024

This PR closes #39.

  • 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, ...)

A feature

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

likelihood() works only with a numeric vector of chains.

  • What is the new behavior (if this is a feature change)?

An <epichains_tree> or <epichains_summary> object can be passed directly to likelihood() to estimate the likelihood of observing the chains.

  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Not applicable.

  • Other information:

- Do we want to override the other relevant arguments (offspring_dist, stat_max, etc) with the attributes of an <epichains_tree> when passed, or should the user still supply them?

  • Currently, if the data contains Inf and stat_max is Inf, it errors because R cannot generate an infinite sequence (See
    calc_sizes <- seq_len(stat_max - 1)
    ).

@sbfnk, how can we surmount this issue?

Would it make sense to calculate the likelihood using only the finite values and in the case where individual = TRUE , return NA for the Inf values?

@jamesmbaazam jamesmbaazam marked this pull request as draft March 5, 2024 16:26
@jamesmbaazam jamesmbaazam marked this pull request as ready for review March 7, 2024 18:12
@jamesmbaazam jamesmbaazam force-pushed the likelihood-with-epichains-class branch from af0b43f to 060f580 Compare March 8, 2024 11:56
@codecov-commenter
Copy link

codecov-commenter commented Mar 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.07%. Comparing base (a7faf3a) to head (8bb0e64).
Report is 119 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #213      +/-   ##
==========================================
+ Coverage   99.03%   99.07%   +0.03%     
==========================================
  Files           8        8              
  Lines         729      755      +26     
==========================================
+ Hits          722      748      +26     
  Misses          7        7              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jamesmbaazam jamesmbaazam changed the title Make likelihood() work with <epichains_summary> and <epichains_tree> objects Make likelihood() work with <epichains_summary> and <epichains> objects Mar 12, 2024
@jamesmbaazam jamesmbaazam force-pushed the likelihood-with-epichains-class branch from e9a8c62 to 8746680 Compare March 12, 2024 11:42
@jamesmbaazam jamesmbaazam requested review from Bisaloo and sbfnk and removed request for Bisaloo March 12, 2024 12:12
Copy link
Contributor

@sbfnk sbfnk 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! Just a minor comment.

man/likelihood.Rd Outdated Show resolved Hide resolved
man/likelihood.Rd Outdated Show resolved Hide resolved
@jamesmbaazam
Copy link
Member Author

jamesmbaazam commented Mar 20, 2024

@sbfnk Currently, if the data contains Inf (more likely when an <epichains_summary> is passed) and stat_max is Inf, it errors because R cannot generate an infinite sequence (See

epichains/R/likelihood.R

Lines 103 to 104 in 5e6fd49

if (any(stat_rep_vect == stat_max)) {
calc_sizes <- seq_len(stat_max - 1)
)

Would it make sense to calculate the likelihood using only the finite values and in the case where individual = TRUE, return NA where the entry is Inf?

@jamesmbaazam jamesmbaazam force-pushed the likelihood-with-epichains-class branch from 86afdf1 to 31c2f33 Compare March 20, 2024 18:03
@sbfnk
Copy link
Contributor

sbfnk commented Mar 21, 2024

@sbfnk Currently, if the data contains Inf (more likely when an <epichains_summary> is passed) and stat_max is Inf, it errors because R cannot generate an infinite sequence (See

epichains/R/likelihood.R

Lines 103 to 104 in 5e6fd49

if (any(stat_rep_vect == stat_max)) {
calc_sizes <- seq_len(stat_max - 1)

)
Would it make sense to calculate the likelihood using only the finite values and in the case where individual = TRUE, return NA where the entry is Inf?

I don't think it would be correct to exclude some of the outbreaks from the likelihood.

We can only have data containing Inf with a finite stat_max in the simulation, right? So it doesn't really make a huge amount of sense to then calculate the likelihood with stat_max as Inf. Perhaps this should be added to the summary as attribute anyway? The likelihood function could then read it out and set stat_max to the "correct" value.

@jamesmbaazam
Copy link
Member Author

jamesmbaazam commented Mar 21, 2024

@sbfnk Currently, if the data contains Inf (more likely when an <epichains_summary> is passed) and stat_max is Inf, it errors because R cannot generate an infinite sequence (See

epichains/R/likelihood.R

Lines 103 to 104 in 5e6fd49

if (any(stat_rep_vect == stat_max)) {
calc_sizes <- seq_len(stat_max - 1)

)
Would it make sense to calculate the likelihood using only the finite values and in the case where individual = TRUE, return NA where the entry is Inf?

I don't think it would be correct to exclude some of the outbreaks from the likelihood.

We can only have data containing Inf with a finite stat_max in the simulation, right? So it doesn't really make a huge amount of sense to then calculate the likelihood with stat_max as Inf.

Perhaps this should be added to the summary as attribute anyway?

This is already the case.

The likelihood function could then read it out and set stat_max to the "correct" value.

That makes sense. See change here 8a35bc7. Did you mean that?

@jamesmbaazam jamesmbaazam force-pushed the likelihood-with-epichains-class branch 2 times, most recently from 108f4e0 to 33d7727 Compare March 21, 2024 18:49
@jamesmbaazam jamesmbaazam requested a review from sbfnk March 22, 2024 14:46
@jamesmbaazam jamesmbaazam added the enhancement New feature or request label Mar 22, 2024
@jamesmbaazam jamesmbaazam force-pushed the likelihood-with-epichains-class branch from 33d7727 to 80115cd Compare March 22, 2024 15:01
R/likelihood.R Outdated Show resolved Hide resolved
@jamesmbaazam jamesmbaazam force-pushed the likelihood-with-epichains-class branch from 1e3bc94 to 9a1b28d Compare May 14, 2024 19:48
@jamesmbaazam jamesmbaazam reopened this May 14, 2024
@jamesmbaazam jamesmbaazam requested a review from sbfnk May 14, 2024 20:35
@jamesmbaazam jamesmbaazam force-pushed the likelihood-with-epichains-class branch 3 times, most recently from b3543c5 to 116d2dd Compare May 15, 2024 16:03
@jamesmbaazam jamesmbaazam mentioned this pull request May 16, 2024
25 tasks
R/likelihood.R Outdated Show resolved Hide resolved
@jamesmbaazam jamesmbaazam requested a review from sbfnk May 29, 2024 07:18
R/likelihood.R Outdated Show resolved Hide resolved
R/helpers.R Outdated Show resolved Hide resolved
@jamesmbaazam jamesmbaazam merged commit e9ed2bd into main May 29, 2024
8 checks passed
@jamesmbaazam jamesmbaazam deleted the likelihood-with-epichains-class branch May 29, 2024 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Allow likelihood() to deal with an epichains objects
4 participants