diff --git a/R/utils_pca_efa.R b/R/utils_pca_efa.R index 6df0bc53b..c95fb1167 100644 --- a/R/utils_pca_efa.R +++ b/R/utils_pca_efa.R @@ -182,7 +182,7 @@ predict.parameters_efa <- function(object, } } else { # psych:::predict.fa(object, data) - out <- as.data.frame(stats::predict(attri$model, data = newdata)) + out <- as.data.frame(stats::predict(attri$model, newdata = newdata)) } } else if (inherits(attri$model, "spca")) { # https://github.com/erichson/spca/issues/7 @@ -194,7 +194,7 @@ predict.parameters_efa <- function(object, out <- as.matrix(newdata) %*% as.matrix(attri$model$loadings) out <- stats::setNames(as.data.frame(out), paste0("Component", seq_len(ncol(out)))) } else { - out <- as.data.frame(stats::predict(attri$model, newdata = newdata, ...)) + out <- as.data.frame(stats::predict(attri$model, newdata = attri$dataset, ...)) } if (!is.null(names)) { diff --git a/tests/testthat/test-pca.R b/tests/testthat/test-pca.R index 0e67750ac..014a3c102 100644 --- a/tests/testthat/test-pca.R +++ b/tests/testthat/test-pca.R @@ -29,16 +29,16 @@ test_that("principal_components", { test_that("principal_components, n", { data(iris) - x <- parameters::principal_components(iris[1:4], n = 2) + x <- principal_components(iris[1:4], n = 2) expect_named(x, c("Variable", "PC1", "PC2", "Complexity")) - x <- parameters::principal_components(iris[1:4], n = 1) + x <- principal_components(iris[1:4], n = 1) expect_named(x, c("Variable", "PC1", "Complexity")) }) test_that("principal_components", { - x <- parameters::principal_components(mtcars[, 1:7]) + x <- principal_components(mtcars[, 1:7]) expect_equal( x$PC1, @@ -55,27 +55,7 @@ test_that("principal_components", { ) expect_named(x, c("Variable", "PC1", "PC2", "Complexity")) -}) - -test_that("principal_components", { - x <- model_parameters(principal_components(mtcars[, 1:7], nfactors = 2)) - expect_equal( - x$RC1, - c( - -0.836114674884308, - 0.766808147590597, - 0.85441780762136, - 0.548502661888057, - -0.889046093964722, - 0.931879020871552, - -0.030485507571411 - ), - tolerance = 0.01 - ) - - expect_named(x, c("Variable", "RC1", "RC2", "Complexity", "Uniqueness")) - expect_identical(dim(suppressWarnings(predict(x))), c(32L, 2L)) - expect_identical(dim(suppressWarnings(predict(x, newdata = mtcars[1:3, 1:7]))), c(3L, 2L)) + expect_identical(dim(predict(x)), c(32L, 2L)) })