-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
159 additions
and
9 deletions.
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
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,68 @@ | ||
test_that("model is gam if specified", { | ||
dat <- data.frame(day = 1:100, value = rnorm(100)) | ||
res <- model_out(dat, xcol = "day", method = "gam") | ||
|
||
m <- mgcv::gam(value ~ s(day, bs = "cs"), | ||
data = dat, method = "REML") | ||
xdf <- tibble::tibble(day = 1:100) | ||
expected <- stats::predict(m, xdf) | ||
|
||
expect_true(all(res$y == expected)) | ||
}) | ||
|
||
test_that("model is loess if specified", { | ||
dat <- data.frame(day = 1:2000, value = rnorm(2000)) | ||
res <- model_out(dat, xcol = "day", method = "loess") | ||
|
||
m <- stats::loess(value ~ day, data = dat, span = 0.75) | ||
xdf <- tibble::tibble(day = 1:2000) | ||
expected <- stats::predict(m, xdf) | ||
|
||
expect_true(all(res$y == expected)) | ||
}) | ||
|
||
test_that("model is loess if not specified and n <= 1000", { | ||
dat <- data.frame(day = 1:1000, value = rnorm(1000)) | ||
res <- model_out(dat, xcol = "day") | ||
|
||
m <- stats::loess(value ~ day, data = dat, span = 0.75) | ||
xdf <- tibble::tibble(day = 1:1000) | ||
expected <- stats::predict(m, xdf) | ||
|
||
expect_true(all(res$y == expected)) | ||
}) | ||
|
||
test_that("model is gam if not specified and n > 1000", { | ||
dat <- data.frame(day = 1:1001, value = rnorm(1001)) | ||
res <- model_out(dat, xcol = "day") | ||
|
||
m <- mgcv::gam(value ~ s(day, bs = "cs"), | ||
data = dat, method = "REML") | ||
xdf <- tibble::tibble(day = 1:1001) | ||
expected <- stats::predict(m, xdf) | ||
|
||
expect_true(all(res$y == expected)) | ||
}) | ||
|
||
test_that("model uses gam options", { | ||
dat <- data.frame(day = 1:1001, value = rnorm(1001)) | ||
res <- model_out(dat, xcol = "day", k = 5) | ||
|
||
m <- mgcv::gam(value ~ s(day, bs = "cs", k = 5), | ||
data = dat, method = "REML") | ||
xdf <- tibble::tibble(day = 1:1001) | ||
expected <- stats::predict(m, xdf) | ||
|
||
expect_true(all(res$y == expected)) | ||
}) | ||
|
||
test_that("model uses loess options", { | ||
dat <- data.frame(day = 1:100, value = rnorm(100)) | ||
res <- model_out(dat, xcol = "day", span = 0.5) | ||
|
||
m <- stats::loess(value ~ day, data = dat, span = 0.5) | ||
xdf <- tibble::tibble(day = 1:100) | ||
expected <- stats::predict(m, xdf) | ||
|
||
expect_true(all(res$y == expected)) | ||
}) |
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