Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Nov 3, 2024
1 parent b78a354 commit 0b68889
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/testthat/_snaps/compare_performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,67 @@
lm2 | 0.833 | 0.333 | 0.338
lm3 | 0.835 | 0.330 | 0.336

---

Code
print(compare_performance(lm1, lm2, lm3), table_width = Inf)
Output
# Comparison of Model Performance Indices
Name | Model | AIC (weights) | AICc (weights) | BIC (weights) | R2 | R2 (adj.) | RMSE | Sigma
-------------------------------------------------------------------------------------------------
lm1 | lm | 231.5 (<.001) | 231.7 (<.001) | 243.5 (<.001) | 0.619 | 0.614 | 0.510 | 0.515
lm2 | lm | 106.2 (0.566) | 106.6 (0.611) | 121.3 (0.964) | 0.837 | 0.833 | 0.333 | 0.338
lm3 | lm | 106.8 (0.434) | 107.6 (0.389) | 127.8 (0.036) | 0.840 | 0.835 | 0.330 | 0.336

---

Code
print(compare_performance(lm1, lm2, lm3), layout = "vertical")
Output
# Comparison of Model Performance Indices
Metric | lm1 | lm2 | lm3
--------------------------------------------------------------
Model | lm | lm | lm
AIC (weights) | 231.5 (<.001) | 106.2 (0.566) | 106.8 (0.434)
AICc (weights) | 231.7 (<.001) | 106.6 (0.611) | 107.6 (0.389)
BIC (weights) | 243.5 (<.001) | 121.3 (0.964) | 127.8 (0.036)
R2 | 0.619 | 0.837 | 0.840
R2 (adj.) | 0.614 | 0.833 | 0.835
RMSE | 0.510 | 0.333 | 0.330
Sigma | 0.515 | 0.338 | 0.336

---

Code
print(compare_performance(lm1, lm2, lm3, lm4), layout = "vertical",
table_width = 50)
Message
When comparing models, please note that probably not all models were fit
from same data.
Output
# Comparison of Model Performance Indices
Metric | lm1 | lm2
----------------------------------------------
Model | lm | lm
AIC (weights) | 231.5 (<.001) | 106.2 (0.408)
AICc (weights) | 231.7 (<.001) | 106.6 (0.454)
BIC (weights) | 243.5 (<.001) | 121.3 (0.933)
R2 | 0.619 | 0.837
R2 (adj.) | 0.614 | 0.833
RMSE | 0.510 | 0.333
Sigma | 0.515 | 0.338
Metric | lm3 | lm4
----------------------------------------------
Model | lm | lm
AIC (weights) | 106.8 (0.313) | 107.0 (0.279)
AICc (weights) | 107.6 (0.289) | 107.8 (0.257)
BIC (weights) | 127.8 (0.035) | 128.0 (0.032)
R2 | 0.840 | 0.840
R2 (adj.) | 0.835 | 0.834
RMSE | 0.330 | 0.331
Sigma | 0.336 | 0.337

5 changes: 5 additions & 0 deletions tests/testthat/test-compare_performance.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ test_that("compare_performance", {
)
)

# table split
expect_snapshot(print(compare_performance(lm1, lm2, lm3)))
expect_snapshot(print(compare_performance(lm1, lm2, lm3), table_width = Inf))
# vertical layout
expect_snapshot(print(compare_performance(lm1, lm2, lm3), layout = "vertical"))
expect_snapshot(print(compare_performance(lm1, lm2, lm3, lm4), layout = "vertical", table_width = 50))

expect_silent(expect_identical(
colnames(compare_performance(lm1, lm2, lm3, lm4, verbose = FALSE)),
Expand Down

0 comments on commit 0b68889

Please sign in to comment.