diff --git a/DESCRIPTION b/DESCRIPTION index b85849cdc..873abae3e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: parameters Title: Processing of Model Parameters -Version: 0.21.7.3 +Version: 0.21.7.4 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/tests/testthat/_snaps/pca.md b/tests/testthat/_snaps/pca.md new file mode 100644 index 000000000..17cd547a4 --- /dev/null +++ b/tests/testthat/_snaps/pca.md @@ -0,0 +1,32 @@ +# print model_parameters pca + + Code + print(principal_components(mtcars[, 1:4], n = "auto")) + Output + # Loadings from Principal Component Analysis (no rotation) + + Variable | PC1 | Complexity + ----------------------------- + mpg | -0.93 | 1.00 + cyl | 0.96 | 1.00 + disp | 0.95 | 1.00 + hp | 0.91 | 1.00 + + The unique principal component accounted for 87.55% of the total variance of the original data. + +--- + + Code + print(principal_components(mtcars[, 1:4], n = "auto"), labels = c( + "Miles/(US) gallon", "Number of cylinders", "Displacement (cu.in.)", + "Gross horsepower")) + Output + # Loadings from Principal Component Analysis (no rotation) + + Variable | Label | PC1 | Complexity + ----------------------------------------------------- + mpg | Miles/(US) gallon | -0.93 | 1.00 + cyl | Number of cylinders | 0.96 | 1.00 + disp | Displacement (cu.in.) | 0.95 | 1.00 + hp | Gross horsepower | 0.91 | 1.00 + diff --git a/tests/testthat/test-pca.R b/tests/testthat/test-pca.R index 014a3c102..9e1bd58e8 100644 --- a/tests/testthat/test-pca.R +++ b/tests/testthat/test-pca.R @@ -59,6 +59,23 @@ test_that("principal_components", { }) +# print ---- + +test_that("print model_parameters pca", { + data(mtcars) + expect_snapshot(print(principal_components(mtcars[, 1:4], n = "auto"))) + expect_snapshot(print( + principal_components(mtcars[, 1:4], n = "auto"), + labels = c( + "Miles/(US) gallon", + "Number of cylinders", + "Displacement (cu.in.)", + "Gross horsepower" + ) + )) +}) + + # predict ---------------------- # N.B tests will fail if `GPArotation` package is not installed