File: test-n_factors.R

package info (click to toggle)
r-cran-parameters 0.24.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,852 kB
  • sloc: sh: 16; makefile: 2
file content (86 lines) | stat: -rw-r--r-- 2,579 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
test_that("n_factors, default", {
  skip_if_not_installed("nFactors")
  skip_if_not_installed("psych")
  set.seed(333)
  x <- n_factors(mtcars[, 1:4])
  expect_identical(ncol(x), 3L)
})

test_that("n_factors, EGAnet", {
  skip_on_cran()
  skip_if_not_installed("EGAnet")
  set.seed(333)
  x <- n_factors(mtcars, package = "EGAnet")
  expect_identical(ncol(x), 3L)
  expect_identical(
    print(capture.output(x)),
    c(
      "# Method Agreement Procedure:",
      "",
      "The choice of 3 dimensions is supported by 2 (100.00%) methods out of 2 (EGA (glasso), EGA (TMFG))."
    )
  )
})

test_that("n_factors, EGAnet does not fail", {
  skip_on_cran()
  skip_if_not_installed("EGAnet")
  set.seed(333)
  x <- n_factors(mtcars[, 1:4], package = "EGAnet")
  expect_identical(ncol(x), 3L)
  expect_identical(nrow(x), 1L)
  expect_identical(
    print(capture.output(x)),
    c(
      "# Method Agreement Procedure:",
      "",
      "The choice of 1 dimensions is supported by 1 (100.00%) methods out of 1 (EGA (glasso))."
    )
  )
})

test_that("n_factors, oblimin rotation", {
  skip_if_not_installed("nFactors")
  skip_if_not_installed("psych")
  skip_if_not_installed("GPArotation")
  set.seed(333)
  x <- n_factors(mtcars[, 1:4], type = "PCA", rotation = "oblimin")
  expect_identical(ncol(x), 3L)
  expect_identical(
    print(capture.output(x)),
    c(
      "# Method Agreement Procedure:",
      "",
      "The choice of 1 dimensions is supported by 11 (84.62%) methods out of 13 (Bartlett, Anderson, Lawley, Optimal coordinates, Acceleration factor, Parallel analysis, Kaiser criterion, Scree (SE), Scree (R2), VSS complexity 1, Velicer's MAP)." # nolint
    )
  )
})

test_that("n_factors, no rotation, psych only", {
  skip_if_not_installed("nFactors")
  skip_if_not_installed("psych")
  set.seed(333)
  x <- n_factors(mtcars[, 1:4], rotation = "none", package = "psych")
  expect_identical(ncol(x), 3L)
  expect_identical(
    print(capture.output(x)),
    c(
      "# Method Agreement Procedure:",
      "",
      "The choice of 1 dimensions is supported by 3 (60.00%) methods out of 5 (Velicer's MAP, BIC, BIC (adjusted))."
    )
  )
})

test_that("n_factors, variance explained", {
  skip_on_cran()
  skip_if_not_installed("nFactors")
  skip_if_not_installed("psych")
  set.seed(333)
  x <- n_factors(mtcars[, 1:4], type = "PCA")
  expect_equal(
    attributes(x)$Variance_Explained$Variance_Cumulative,
    c(0.84126, 0.85088, 0.85859, 0.85859),
    tolerance = 1e-4
  )
})