Skip to content

Commit

Permalink
Merge pull request #27 from Spatiotemporal-Exposures-and-Toxicology/u…
Browse files Browse the repository at this point in the history
…nit-test

Unit test
  • Loading branch information
kyle-messier authored Jan 30, 2024
2 parents 09b1a24 + b0c3f09 commit c91b9f1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/obj_hill.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @param resp response
#'
#' @return value
obj_hill <- function (par, log10_conc, resp) {
obj_hill <- function(par, log10_conc, resp) {

tp <- par[1] # top asymptote
log10_ga <- par[2] # log10(AC50)
Expand Down
50 changes: 50 additions & 0 deletions tests/testthat/test-obj_hill.R
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))
})

0 comments on commit c91b9f1

Please sign in to comment.