-
Notifications
You must be signed in to change notification settings - Fork 10
Djm/resids hotfix #294
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
Merged
Merged
Djm/resids hotfix #294
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1fc9813
handle the quantile grouping correctly
dajmcdon 3094da9
existing tests pass, remove non-standard file
dajmcdon 63cd991
add a basic test
dajmcdon aceeac4
add flatline test
dajmcdon 695aeb0
fix: refactor quantile calculation
dajmcdon fb04f20
bump version
dajmcdon 0165001
add to news
dajmcdon 0d133df
remove test for nonexistent functions
dajmcdon 3b8c889
style only
dsweber2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: epipredict | ||
Title: Basic epidemiology forecasting methods | ||
Version: 0.0.9 | ||
Version: 0.0.10 | ||
Authors@R: c( | ||
person("Daniel", "McDonald", , "[email protected]", role = c("aut", "cre")), | ||
person("Ryan", "Tibshirani", , "[email protected]", role = "aut"), | ||
|
@@ -72,4 +72,4 @@ Config/testthat/edition: 3 | |
Encoding: UTF-8 | ||
LazyData: true | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.3.0 | ||
RoxygenNote: 7.3.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,6 @@ test_that("constructor returns reasonable quantiles", { | |
expect_error(new_quantiles(c(1, 2, 3), c(.1, .2, 3))) | ||
}) | ||
|
||
test_that("tail functions give reasonable output", { | ||
expect_equal(norm_q_par(qnorm(c(.75, .5), 10, 5)), list(m = 10, s = 5)) | ||
expect_equal(norm_q_par(qnorm(c(.25, .5), 10, 5)), list(m = 10, s = 5)) | ||
expect_equal(norm_q_par(qnorm(c(.25, .5), 0, 1)), list(m = 0, s = 1)) | ||
expect_equal(exp_q_par(qlaplace(c(.75, .5), 10, 5)), list(m = 10, s = 5)) | ||
expect_equal(exp_q_par(qlaplace(c(.25, .5), 10, 5)), list(m = 10, s = 5)) | ||
expect_equal(exp_q_par(qlaplace(c(.25, .5), 0, 1)), list(m = 0, s = 1)) | ||
}) | ||
|
||
test_that("single dist_quantiles works, quantiles are accessible", { | ||
z <- new_quantiles(values = 1:5, quantile_levels = c(.2, .4, .5, .6, .8)) | ||
|
@@ -49,6 +41,34 @@ test_that("quantile extrapolator works", { | |
expect_length(parameters(qq[1])$q[[1]], 7L) | ||
}) | ||
|
||
test_that("small deviations of quantile requests work", { | ||
l <- c(.05, .1, .25, .75, .9, .95) | ||
v <- c(0.0890306, 0.1424997, 0.1971793, 0.2850978, 0.3832912, 0.4240479) | ||
badl <- l | ||
badl[1] <- badl[1] - 1e-14 | ||
distn <- dist_quantiles(list(v), list(l)) | ||
|
||
# was broken before, now works | ||
expect_equal(quantile(distn, l), quantile(distn, badl)) | ||
|
||
# The tail extrapolation was still poor. It needs to _always_ use | ||
# the smallest (largest) values or we could end up unsorted | ||
l <- 1:9 / 10 | ||
v <- 1:9 | ||
distn <- dist_quantiles(list(v), list(l)) | ||
expect_equal(quantile(distn, c(.25, .75)), list(c(2.5, 7.5))) | ||
expect_equal(quantile(distn, c(.1, .9)), list(c(1, 9))) | ||
qv <- data.frame(q = l, v = v) | ||
expect_equal( | ||
unlist(quantile(distn, c(.01, .05))), | ||
tail_extrapolate(c(.01, .05), head(qv, 2)) | ||
) | ||
Comment on lines
+62
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I quite get how this is testing the tail behavior; is it just checking that |
||
expect_equal( | ||
unlist(quantile(distn, c(.99, .95))), | ||
tail_extrapolate(c(.95, .99), tail(qv, 2)) | ||
) | ||
}) | ||
|
||
test_that("unary math works on quantiles", { | ||
dstn <- dist_quantiles(list(1:4, 8:11), list(c(.2, .4, .6, .8))) | ||
dstn2 <- dist_quantiles(list(log(1:4), log(8:11)), list(c(.2, .4, .6, .8))) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sanity check, this is 2.5 because that's halfway between 2 and 3, which are the
.2
and.3
quantile values?