tests/testthat/test-varimax.R

################################################################################

context("VARIMAX")

################################################################################

test_that("varimax2() works", {

  replicate(10, {

    for (scale in c(TRUE, FALSE)) {
      for (ord in c(TRUE, FALSE)) {
        X <- matrix(rnorm(1000 * 5), ncol = 5)
        X_rot <- varimax2(X, normalize = scale, reorder = ord)
        rot   <- varimax2(X, normalize = scale, reorder = ord, rotmat = TRUE)
        expect_equal(X_rot, X %*% rot)
        if (ord) {
          X_rot2 <- varimax(X, normalize = scale)$loadings[]
          expect_equal(sum(cor(X_rot2, X_rot) > 0.9999), 5)
        } else {
          expect_equal(X_rot, varimax(X, normalize = scale)$loadings[])
          expect_equal(rot,   varimax(X, normalize = scale)$rotmat)
        }
      }
    }
  })

})

################################################################################

Try the bigutilsr package in your browser

Any scripts or data that you put into this service are public.

bigutilsr documentation built on Aug. 8, 2025, 7:24 p.m.