-
Notifications
You must be signed in to change notification settings - Fork 8
Test growth_rate #197
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
Test growth_rate #197
Changes from all commits
6306558
6b9ae45
4ce0fcd
741ecd2
58cafd8
8b82d9d
6850a9a
46690de
fda2e1a
2556d55
eab1d78
7141537
1c26f37
b65ab18
c973778
bc04213
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,56 @@ | ||||||
library(dplyr) | ||||||
|
||||||
X <- c(1:10,NA,10:20,NA) | ||||||
Y <- c(2^(1:9),NA,NA,2^(10:21)) | ||||||
|
||||||
methods <- c("rel_change","linear_reg","smooth_spline","trend_filter") | ||||||
|
||||||
gr <- function(method = "rel_change", h = 3, na_rm = TRUE, ...) { | ||||||
growth_rate(x=X,y=Y,method=method,na_rm = na_rm, h = h,...) | ||||||
} | ||||||
|
||||||
test_that("Test error throwing",{ | ||||||
# Error cases | ||||||
expect_error(growth_rate(x=1:3,y=1:4), | ||||||
"`x` and `y` must have the same length.") | ||||||
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. suggestion [non-blocking]: Probably beyond scope here, but it would be nice if the errors and warnings in |
||||||
expect_error(growth_rate(x=1:20,y=1:20,x0=21), | ||||||
"`x0` must be a subset of `x`.") | ||||||
nmdefries marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
# Fails only when method = `"trend_filter"` | ||||||
expect_error(gr(method = "trend_filter",cv=FALSE,df=1.5), | ||||||
"If `cv = FALSE`, then `df` must be an integer.") | ||||||
}) | ||||||
|
||||||
test_that("Test throwing of warning of duplicates",{ | ||||||
# The warning that is prompted is as follows: | ||||||
# "`x` contains duplicate values. (If being run on a column in an `epi_df`, | ||||||
# did you group by relevant key variables?)" | ||||||
# Note that putting it in the regexp of expect_warning doesn't seem to work | ||||||
jhu_csse_daily_subset %>% | ||||||
mutate(cases_gr = growth_rate(x = time_value, y = cases, dup_rm=TRUE)) %>% | ||||||
expect_warning() %>% | ||||||
expect_error() | ||||||
Comment on lines
+30
to
+31
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. issue: It's hard to tell what this is doing. If we want to check for both a warning and an error, run this twice with each |
||||||
}) | ||||||
|
||||||
test_that("Simple example of growth rate that produces desired results",{ | ||||||
expect_equal(growth_rate(x=1:20,y=2^(1:20),h=1), c(rep(1,19),NaN)) | ||||||
}) | ||||||
|
||||||
test_that("log_scale works",{ | ||||||
expect_equal(growth_rate(x=1:20,y=exp(1:20),h=5, | ||||||
method="linear_reg",log_scale = TRUE), | ||||||
rep(1,20)) | ||||||
}) | ||||||
|
||||||
test_that("Running different methods with NA removal won't fail",{ | ||||||
for (m in methods) expect_false(NA %in% gr(method = m,x0=1:5)) | ||||||
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. question:
Suggested change
? |
||||||
}) | ||||||
|
||||||
test_that("na_rm works and is necessary when there are NA's",{ | ||||||
expect_false(NA %in% gr()) | ||||||
expect_equal(length(gr()),20) | ||||||
expect_equal(gr(na_rm = FALSE), | ||||||
# 1+NA gives an NA classified as a numeric | ||||||
rep(1+NA,23)) | ||||||
expect_equal(gr(h=1), c(rep(1,19),NaN)) | ||||||
expect_error(gr(method = "smooth_spline")) | ||||||
}) | ||||||
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. Could you please add another test for the actual values coming out? E.g., construct a simple example where the growth rate should be obvious, and test that we calculate that obvious value. At least for some of the Also, please test that each of the 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. If you can't construct an example where you think you know what the output should be, maybe throw in some 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.
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. @kenmawer I think the point here is to test that the correct calculations are occurring when arguments are correctly specified, not just that errors happen when the inputs are wrong. 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. I already added a few tests for calculations. I would suspect that for some of the other methods, it would be too complicated to be able to verify the outputted numbers. It also depends on what you mean by "correct calculations," whether it's merely getting the right number of cells or getting those exact numbers. 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. Since it's likely too complicated to verify the output numbers [for the complex settings like using trend filtering], that's why I suggested 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. Looks like of the requested
only the method outputs are left -- is that correct? |
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.
question: Is this a bug fix? The new version of this line doesn't mean the same thing as the old version.
suggestion: I'm assuming the new version is desired behavior (keeping only pairs of obs in x and y when both values are available), but the comment "# Remove NAs if we need to" is very ambiguous. Recommend making the goal more explicit.