| 1 |
skip_on_cran() |
| 2 |
|
| 3 |
skip_if_not_installed("modeltests") |
| 4 |
library(modeltests) |
| 5 |
|
| 6 |
skip_if_not_installed("quantreg") |
| 7 |
suppressPackageStartupMessages(library(quantreg)) |
| 8 |
|
| 9 |
data(stackloss) |
| 10 |
|
| 11 |
df <- as_tibble(stack.x) |> |
| 12 |
mutate(stack.loss = stack.loss) |
| 13 |
|
| 14 |
dflarge_n <- df |> slice(rep(row_number(), 500)) |
| 15 |
|
| 16 |
fit <- rq(stack.loss ~ ., data = df, tau = .5) |
| 17 |
fit2 <- rq(stack.loss ~ 1, data = df, tau = .5) |
| 18 |
fitlarge_n <- rq(stack.loss ~ ., data = dflarge_n, tau = .5) |
| 19 |
|
| 20 |
test_that("quantreg::rq tidier arguments", { |
| 21 |
check_arguments(tidy.rq) |
| 22 |
check_arguments(glance.rq) |
| 23 |
check_arguments(augment.rq) |
| 24 |
}) |
| 25 |
|
| 26 |
test_that("tidy.rq", { |
| 27 |
td <- tidy(fit) |
| 28 |
td2 <- tidy(fit2) |
| 29 |
tdlarge_n <- tidy(fitlarge_n) |
| 30 |
td_iid <- tidy(fit, conf.int = TRUE, se.type = "iid") |
| 31 |
|
| 32 |
check_tidy_output(td) |
| 33 |
check_tidy_output(td2) |
| 34 |
check_tidy_output(tdlarge_n) |
| 35 |
check_tidy_output(td_iid) |
| 36 |
|
| 37 |
check_dims(td, 4, 5) |
| 38 |
check_dims(td2, 1, 5) |
| 39 |
check_dims(tdlarge_n, 4, 6) |
| 40 |
check_dims(td_iid, 4, 8) |
| 41 |
}) |
| 42 |
|
| 43 |
test_that("glance.rq", { |
| 44 |
gl <- glance(fit) |
| 45 |
gl2 <- glance(fit2) |
| 46 |
check_glance_outputs(gl, gl2) |
| 47 |
}) |
| 48 |
|
| 49 |
test_that("augment.rq", { |
| 50 |
au <- augment(fit, interval = "confidence") |
| 51 |
check_tibble(au, method = "augment", strict = FALSE) |
| 52 |
check_dims(au, 21, 9) |
| 53 |
|
| 54 |
check_augment_function( |
| 55 |
aug = augment.rq, |
| 56 |
model = fit, |
| 57 |
data = df, |
| 58 |
newdata = df, |
| 59 |
strict = FALSE |
| 60 |
) |
| 61 |
|
| 62 |
check_augment_function( |
| 63 |
aug = augment.rq, |
| 64 |
model = fit2, |
| 65 |
data = df, |
| 66 |
newdata = df, |
| 67 |
strict = FALSE |
| 68 |
) |
| 69 |
}) |