| 1 |
skip_on_cran() |
| 2 |
|
| 3 |
skip_if_not_installed("modeltests") |
| 4 |
library(modeltests) |
| 5 |
|
| 6 |
skip_if_not_installed("lavaan") |
| 7 |
suppressPackageStartupMessages(library(lavaan)) |
| 8 |
|
| 9 |
fit <- sem("mpg ~ wt", data = mtcars) |
| 10 |
form <- paste("F =~", paste0("x", 1:9, collapse = " + ")) |
| 11 |
fit2 <- cfa(form, data = HolzingerSwineford1939) |
| 12 |
|
| 13 |
test_that("lavaan tidier arguments", { |
| 14 |
check_arguments(tidy.lavaan) |
| 15 |
check_arguments(glance.lavaan) |
| 16 |
}) |
| 17 |
|
| 18 |
test_that("tidy.lavaan", { |
| 19 |
td <- tidy(fit, conf.int = TRUE) |
| 20 |
td2 <- tidy(fit2, conf.int = TRUE) |
| 21 |
tdc <- tidy(fit2, conf.int = TRUE, conf.level = .999) |
| 22 |
tdr <- tidy(fit2, rsquare = TRUE) |
| 23 |
|
| 24 |
check_tidy_output(td) |
| 25 |
check_tidy_output(td2) |
| 26 |
check_tidy_output(tdc) |
| 27 |
check_tidy_output(tdr) |
| 28 |
|
| 29 |
check_dims(td, 3, 11) |
| 30 |
# std.nox not available without fixed exogenous predictors (#1217) |
| 31 |
check_dims(td2, 19, 10) |
| 32 |
|
| 33 |
expect_equal(td$term, c("mpg ~ wt", "mpg ~~ mpg", "wt ~~ wt")) |
| 34 |
|
| 35 |
op_counts <- dplyr::count(td2, op)$n |
| 36 |
expect_true((all(9:10 %in% op_counts))) |
| 37 |
|
| 38 |
# check conf level |
| 39 |
expect_true(all(td2$conf.high <= tdc$conf.high)) |
| 40 |
|
| 41 |
# passing arguments via ... |
| 42 |
check_dims(filter(tdr, op == "r2"), expected_rows = 9) |
| 43 |
}) |
| 44 |
|
| 45 |
|
| 46 |
test_that("glance.lavaan", { |
| 47 |
gl <- glance(fit) |
| 48 |
check_glance_outputs(gl) |
| 49 |
|
| 50 |
gl2 <- glance(fit2) |
| 51 |
check_glance_outputs(gl2) |
| 52 |
}) |