-
Notifications
You must be signed in to change notification settings - Fork 2
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
Debug curve plot #323
Debug curve plot #323
Changes from all commits
d04c7be
0ff8f0d
8c6aa1a
720857c
6a5d834
da10ca9
8b8af51
605f07b
93b0f8b
5bd7e46
2b540a6
902be9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
# uses r > 1 scale for shape | ||
ab0 <- function( | ||
t, | ||
curve_params) { | ||
ab0 <- function(t, curve_params) { | ||
y0 <- curve_params[["y0"]] | ||
y1 <- curve_params[["y1"]] | ||
t1 <- curve_params[["t1"]] | ||
alpha <- curve_params[["alpha"]] | ||
shape <- curve_params[["r"]] | ||
r <- curve_params[["r"]] | ||
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. shortening varname to make lines below fit in less than 80 characters |
||
|
||
beta <- bt(y0, y1, t1) | ||
|
||
yt <- 0 | ||
|
||
yt_phase_1 <- y0 * exp(beta * t) | ||
yt_phase_2 <- (y1^(1 - shape) - (1 - shape) * alpha * (t - t1))^(1 / (1 - shape)) | ||
if (r == 1) { | ||
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 r == 1, the usual expression for this function reduces to |
||
yt_phase_2 <- y1 * exp(-alpha * (t - t1)) | ||
# see wolfram alpha result: https://bit.ly/3ZB69Yn | ||
# this is a version the product-limit characterization of the | ||
# exponential function | ||
} else { | ||
yt_phase_2 <- | ||
(y1^(1 - r) - (1 - r) * alpha * (t - t1))^(1 / (1 - r)) | ||
} | ||
|
||
yt <- dplyr::if_else(t <= t1, yt_phase_1, yt_phase_2) | ||
return(yt) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# `ab0()` produces consistent results | ||
|
||
9298.67465260527 | ||
|
||
--- | ||
|
||
9990.00499833375 | ||
|
||
--- | ||
|
||
9298.67465260527 | ||
|
||
--- | ||
|
||
909.090909090912 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
test_that("`ab0()` produces consistent results", { | ||
params1 <- | ||
data.frame( | ||
y0 = 10, | ||
y1 = 10^4, | ||
t1 = 9.5, | ||
alpha = 0.01, | ||
r = 1, | ||
antigen_iso = "test" | ||
) |> | ||
as_curve_params() | ||
|
||
calc1 <- | ||
ab0(curve_params = params1, t = 9.4) | ||
|
||
expect_snapshot_value(calc1, style = "deparse") | ||
|
||
calc2 <- | ||
ab0(curve_params = params1, t = 9.6) | ||
|
||
expect_snapshot_value(calc2, style = "deparse") | ||
|
||
params2 <- | ||
data.frame( | ||
y0 = 10, | ||
y1 = 10^4, | ||
t1 = 9.5, | ||
alpha = 0.01, | ||
r = 2, | ||
antigen_iso = "test" | ||
) |> | ||
as_curve_params() | ||
|
||
calc3 <- | ||
ab0(curve_params = params2, t = 9.4) | ||
|
||
expect_snapshot_value(calc3, style = "deparse") | ||
|
||
calc4 <- | ||
ab0(curve_params = params2, t = 9.6) | ||
|
||
expect_snapshot_value(calc4, style = "deparse") | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
test_that("`plot_curve_params_one_ab()` produces consistent results", { | ||
params <- | ||
data.frame( | ||
y0 = 10, | ||
y1 = 10 ^ 4, | ||
t1 = 9.5, | ||
alpha = 0.01, | ||
r = 1, | ||
antigen_iso = "test" | ||
) |> | ||
as_curve_params() | ||
|
||
|
||
fig1 <- | ||
params |> | ||
plot_curve_params_one_ab(n_points = 10 ^ 5, | ||
xlim = c(0, 25), | ||
log_y = FALSE) | ||
|
||
fig1 |> | ||
vdiffr::expect_doppelganger(title = "curve_r1") | ||
|
||
}) |
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.
lint