-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Spatiotemporal-Exposures-and-Toxicology/u…
…nit-test Unit test
- Loading branch information
Showing
2 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Testing the obj-hill functions | ||
test_that("2 and 3 parameter models give accurate likelihood", { | ||
|
||
## hill function for simulation | ||
hill_fun <- function(x, alpha, beta, theta){ | ||
alpha / (1 + 10^(beta * (theta - x))) | ||
} | ||
|
||
## Creating regular parameters | ||
tp <- 1 | ||
log10_ga <- 1 | ||
gw <- 2 | ||
err <- 1 | ||
|
||
## 2-parameter model | ||
|
||
#simulate dose-response | ||
params2 <- c(tp, log10_ga, err) | ||
log10_conc <- seq(0.1,10,length.out = 50) | ||
resp <- hill_fun(log10_conc, tp, log10_ga, gw) | ||
|
||
# 2 parameter hill model expectation | ||
val <- obj_hill(params2, log10_conc, resp) | ||
expect_equal(val, -100.201, tolerance = 0.001) | ||
|
||
## 3-parameter model | ||
|
||
# 3 parameter hill model expectation | ||
params3 <- c(tp, log10_ga, gw, err) | ||
val <- obj_hill(params3, log10_conc, resp) | ||
expect_equal(val, -99.23463, tolerance = 0.001) | ||
|
||
|
||
#### Edge Tests | ||
|
||
# Really tiny parameter values | ||
|
||
#simulate dose-response | ||
params_tiny <- c(1e-10, 1e-10, 1e-10, 1e-10) | ||
|
||
expect_no_warning(obj_hill(params_tiny, log10_conc, resp)) | ||
|
||
|
||
# Really large parameter values | ||
|
||
#simulate dose-response | ||
params_large <- c(1e10, 1e10, 1e10, 1e10) | ||
|
||
expect_no_warning(obj_hill(params_tiny, log10_conc, resp)) | ||
}) |