Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix snapshot tests #776

Merged
merged 3 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: performance
Title: Assessment of Regression Models Performance
Version: 0.12.4.3
Version: 0.12.4.4
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
3 changes: 2 additions & 1 deletion R/check_itemscale.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ print.check_itemscale <- function(x, digits = 2, ...) {
digits = digits,
format = "text",
missing = "<NA>",
zap_small = TRUE
zap_small = TRUE,
...
))
}

Expand Down
83 changes: 83 additions & 0 deletions tests/testthat/_snaps/compare_performance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# compare_performance

Code
print(compare_performance(lm1, lm2, lm3))
Output
# Comparison of Model Performance Indices

Name | Model | AIC (weights) | AICc (weights) | BIC (weights) | R2
---------------------------------------------------------------------
lm1 | lm | 231.5 (<.001) | 231.7 (<.001) | 243.5 (<.001) | 0.619
lm2 | lm | 106.2 (0.566) | 106.6 (0.611) | 121.3 (0.964) | 0.837
lm3 | lm | 106.8 (0.434) | 107.6 (0.389) | 127.8 (0.036) | 0.840

Name | R2 (adj.) | RMSE | Sigma
--------------------------------
lm1 | 0.614 | 0.510 | 0.515
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

10 changes: 7 additions & 3 deletions tests/testthat/_snaps/pkg-ivreg.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
Output
# Indices of model performance

AIC | BIC | R2 | R2 (adj.) | RMSE | Sigma | Wu & Hausman | p (Wu_Hausman) | Weak instruments | p (weak_instruments)
-------------------------------------------------------------------------------------------------------------------------------
182.692 | 191.486 | 0.655 | 0.604 | 3.484 | 3.793 | 13.869 | < .001 | 19.958 | < .001
AIC | BIC | R2 | R2 (adj.) | RMSE | Sigma | Wu & Hausman
--------------------------------------------------------------------
182.692 | 191.486 | 0.655 | 0.604 | 3.484 | 3.793 | 13.869

AIC | p (Wu_Hausman) | Weak instruments | p (weak_instruments)
------------------------------------------------------------------
182.692 | < .001 | 19.958 | < .001

7 changes: 7 additions & 0 deletions tests/testthat/test-compare_performance.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ 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)),
c("Name", "Model", "AIC", "AIC_wt", "AICc", "AICc_wt", "BIC", "BIC_wt", "R2", "R2_adjusted", "RMSE", "Sigma")
Expand Down
Loading