Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Nov 1, 2024
1 parent d687920 commit 061e934
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
95 changes: 95 additions & 0 deletions tests/testthat/_snaps/windows/export_table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# export_table, table_width

Code
print(out, table_width = 50)
Output
# Comparison of Model Performance Indices
Name | Model | Chi2(24) | p (Chi2)
-------------------------------------
model1 | lavaan | 85.306 | < .001
model2 | lavaan | 85.306 | < .001
Name | Baseline(36) | p (Baseline) | GFI
--------------------------------------------
model1 | 918.852 | < .001 | 0.943
model2 | 918.852 | < .001 | 0.943
Name | AGFI | NFI | NNFI | CFI | RMSEA
----------------------------------------------
model1 | 0.894 | 0.907 | 0.896 | 0.931 | 0.092
model2 | 0.894 | 0.907 | 0.896 | 0.931 | 0.092
Name | RMSEA CI | p (RMSEA) | RMR | SRMR
-------------------------------------------------
model1 | [0.07, 0.11] | < .001 | 0.082 | 0.065
model2 | [0.07, 0.11] | < .001 | 0.082 | 0.065
Name | RFI | PNFI | IFI | RNI
--------------------------------------
model1 | 0.861 | 0.605 | 0.931 | 0.931
model2 | 0.861 | 0.605 | 0.931 | 0.931
Name | Loglikelihood | AIC (weights)
---------------------------------------
model1 | -3737.745 | 7517.5 (0.500)
model2 | -3737.745 | 7517.5 (0.500)
Name | BIC (weights) | BIC_adjusted
--------------------------------------
model1 | 7595.3 (0.500) | 7528.739
model2 | 7595.3 (0.500) | 7528.739

---

Code
print(tab, table_width = 80)
Output
Parameter | lm1 | lm2
------------------------------------------------------------------------------
(Intercept) | 5.01 (4.86, 5.15) | 3.68 ( 3.47, 3.89)
Species [versicolor] | 0.93 (0.73, 1.13) | -1.60 (-1.98, -1.22)
Species [virginica] | 1.58 (1.38, 1.79) | -2.12 (-2.66, -1.58)
Petal Length | | 0.90 ( 0.78, 1.03)
Species [versicolor] × Petal Length | |
Species [virginica] × Petal Length | |
Petal Width | |
------------------------------------------------------------------------------
Observations | 150 | 150
Parameter | lm3
----------------------------------------------------------
(Intercept) | 4.21 ( 3.41, 5.02)
Species [versicolor] | -1.81 (-2.99, -0.62)
Species [virginica] | -3.15 (-4.41, -1.90)
Petal Length | 0.54 ( 0.00, 1.09)
Species [versicolor] × Petal Length | 0.29 (-0.30, 0.87)
Species [virginica] × Petal Length | 0.45 (-0.12, 1.03)
Petal Width |
----------------------------------------------------------
Observations | 150
Parameter | lm4
----------------------------------------------------------
(Intercept) | 4.21 ( 3.41, 5.02)
Species [versicolor] | -1.80 (-2.99, -0.62)
Species [virginica] | -3.19 (-4.50, -1.88)
Petal Length | 0.54 (-0.02, 1.09)
Species [versicolor] × Petal Length | 0.28 (-0.30, 0.87)
Species [virginica] × Petal Length | 0.45 (-0.12, 1.03)
Petal Width | 0.03 (-0.28, 0.34)
----------------------------------------------------------
Observations | 150
Parameter | lm5 | lm6
---------------------------------------------------------------------------------
(Intercept) | 4.21 ( 3.41, 5.02) | 4.21 ( 3.41, 5.02)
Species [versicolor] | -1.80 (-2.99, -0.62) | -1.80 (-2.99, -0.62)
Species [virginica] | -3.19 (-4.50, -1.88) | -3.19 (-4.50, -1.88)
Petal Length | 0.54 (-0.02, 1.09) | 0.54 (-0.02, 1.09)
Species [versicolor] × Petal Length | 0.28 (-0.30, 0.87) | 0.28 (-0.30, 0.87)
Species [virginica] × Petal Length | 0.45 (-0.12, 1.03) | 0.45 (-0.12, 1.03)
Petal Width | 0.03 (-0.28, 0.34) | 0.03 (-0.28, 0.34)
---------------------------------------------------------------------------------
Observations | 150 | 150

27 changes: 27 additions & 0 deletions tests/testthat/test-export_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,30 @@ test_that("export_table", {
ignore_attr = TRUE
)
})


test_that("export_table, table_width", {
skip_on_cran()
skip_if_not_installed("lavaan")
skip_if_not_installed("performance")
skip_if_not_installed("parameters")

data(HolzingerSwineford1939, package = "lavaan")
structure <- " visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 "
model1 <- lavaan::cfa(structure, data = HolzingerSwineford1939)
model2 <- lavaan::cfa(structure, data = HolzingerSwineford1939)

out <- performance::compare_performance(model1, model2)
expect_snapshot(print(out, table_width = 50), variant = "windows")

data(iris)
lm1 <- lm(Sepal.Length ~ Species, data = iris)
lm2 <- lm(Sepal.Length ~ Species + Petal.Length, data = iris)
lm3 <- lm(Sepal.Length ~ Species * Petal.Length, data = iris)
lm6 <- lm5 <- lm4 <- lm(Sepal.Length ~ Species * Petal.Length + Petal.Width, data = iris)

tab <- parameters::compare_parameters(lm1, lm2, lm3, lm4, lm5, lm6)
expect_snapshot(print(tab, table_width = 80), variant = "windows")
})

0 comments on commit 061e934

Please sign in to comment.