我正在使用principal()
包中的psych
函数在R中复制SPSS主成分分析结果(根据https://stats.stackexchange.com/questions/612/is-pca-followed-by-a-rotation-e-g-varimax-still-pca中的建议)
我正在使用以下代码:
com<-principal(ws, nfactors = 1, residuals = FALSE,rotate="varimax",n.obs=NA, covar=TRUE,
scores=TRUE,missing=TRUE,impute="mean",oblique.scores=TRUE,
method="correlation")
但我收到以下错误:
Error in solve.default(model, r) :
Lapack routine dgesv: system is exactly singular: U[104,104] = 0
In addition: Warning message:
In cor.smooth(r) : Matrix was not positive definite, smoothing was done
非常感谢任何建议。我在下面附上了我的数据样本(dput(ws)
)。非常感谢!
structure(list(hv001 = c(906, 3101, 4001, 6801, 1502, 3508, 4301,
2205, 508, 901, 906, 2304, 4913, 3803, 5704, 2902, 4701, 2303,
3602, 5905, 4805, 1405, 6301, 4007, 904, 302, 7003, 1602, 7107,
4801, 1803, 3403, 6904, 3002, 509, 6904, 1407, 5803, 5802, 4504,
405, 502, 7207, 2706, 2703, 4007, 3403, 703, 2304, 4806, 403,
502, 5607, 902, 2707, 2709, 6402, 6902, 1902, 7501, 2202, 2201,
7205, 4901, 2204, 3504, 5608, 3202, 3505, 2202, 5608, 2306, 7402,
7109, 7303, 5904, 3602, 6102, 101, 7302, 906, 3506, 6003, 6302,
909, 4801, 4806, 3104, 5708, 6802, 404, 4903, 5609, 2101, 3502,
4002, 1602, 7206, 6903, 7103), hv002 = c(26, 372, 147, 215, 23,
48, 130, 17, 48, 214, 93, 15, 122, 27, 172, 5, 53, 100, 177,
341, 279, 42, 47, 10, 15, 47, 90, 106, 218, 110, 95, 86, 69,
77, 47, 49, 43, 55, 324, 88, 120, 177, 112, 462, 347, 3, 69,
36, 16, 561, 109, 322, 28, 47, 123, 8, 174, 66, 101, 55, 212,
201, 57, 231, 53, 128, 211, 136, 102, 246, 154, 5, 59, 231, 263,
108, 137, 35, 98, 165, 27, 205, 8, 70, 147, 189, 417, 71, 23,
56, 139, 302, 106, 83, 24, 12, 56, 95, 4, 198), hv005 = c(346129,
1051441, 458555, 513316, 2337718, 2526226, 1956333, 420415, 2337718,
106202, 346129, 420415, 1181939, 1956333, 852471, 420415, 1956333,
420415, 1956333, 811088, 1181939, 1042611, 513316, 1956333, 346129,
1042611, 595684, 2337718, 249256, 1181939, 2526226, 671551, 595684,
1566584, 2337718, 595684, 1042611, 852471, 264004, 1956333, 2337718,
537817, 1238001, 1051441, 1051441, 1956333, 671551, 1042611,
420415, 1181939, 2337718, 537817, 852471, 106202, 1051441, 1051441,
513316, 595684, 2526226, 513316, 162660, 162660, 1238001, 333940,
420415, 671551, 852471, 2526226, 2526226, 162660, 852471, 420415,
214934, 1238001, 595684, 811088, 1956333, 811088, 346129, 595684,
346129, 2526226, 811088, 513316, 346129, 1181939, 1181939, 1566584,
852471, 513316, 2337718, 333940, 852471, 1566584, 671551, 458555,
2337718, 1238001, 595684, 249256), hv025 = c(2, 1, 1, 2, 2, 2,
2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2,
2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 2, 2, 1, 1, 2, 1, 2, 1, 2, 2, 2,
1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 1, 2, 2, 1, 1, 2, 2, 2, 1), hv009 = c(7, 3, 4, 5, 4, 3, 4,
2, 5, 2, 8, 3, 4, 4, 2, 3, 7, 4, 3, 5, 9, 5, 6, 1, 3, 5, 7, 5,
6, 2, 4, 4, 4, 3, 5, 5, 3, 5, 3, 4, 4, 5, 3, 5, 4, 4, 5, 9, 3,
3, 4, 3, 4, 3, 5, 4, 9, 8, 6, 1, 5, 4, 6, 1, 8, 3, 3, 5, 2, 6,
5, 2, 3, 1, 7, 3, 7, 3, 7, 7, 3, 4, 5, 5, 3, 3, 4, 5, 8, 2, 3,
5, 2, 7, 2, 2, 7, 10, 6, 5), hv012 = c(7, 3, 4, 5, 4, 3, 4, 2,
5, 2, 8, 3, 4, 4, 2, 3, 3, 4, 3, 5, 9, 5, 6, 1, 3, 5, 7, 5, 6,
2, 4, 4, 4, 3, 5, 5, 3, 5, 3, 4, 4, 5, 3, 5, 4, 4, 5, 9, 3, 3,
4, 3, 4, 3, 5, 2, 9, 8, 6, 1, 5, 4, 6, 1, 8, 3, 3, 5, 2, 6, 5,
2, 3, 1, 7, 3, 7, 3, 7, 7, 3, 4, 5, 5, 3, 3, 4, 5, 6, 2, 3, 5,
2, 7, 2, 2, 7, 10, 6, 4), hv013 = c(7, 3, 4, 4, 4, 3, 4, 2, 5,
2, 8, 3, 4, 4, 2, 3, 7, 4, 3, 5, 9, 5, 4, 1, 3, 3, 7, 5, 6, 2,
0, 4, 3, 3, 5, 5, 3, 5, 3, 4, 4, 3, 3, 5, 4, 4, 5, 9, 3, 3, 4,
3, 4, 3, 5, 4, 9, 8, 6, 1, 4, 4, 6, 1, 8, 3, 3, 5, 2, 6, 5, 2,
3, 1, 5, 3, 7, 3, 7, 7, 3, 4, 5, 5, 3, 2, 4, 5, 8, 2, 3, 3, 1,
7, 2, 2, 7, 10, 6, 5), hv201 = c(44, 12, 12, 43, 21, 41, 13,
43, 21, 12, 44, 12, 13, 31, 21, 13, 12, 12, 11, 31, 21, 21, 12,
13, 13, 43, 41, 21, 21, 12, 21, 21, 13, 12, 12, 13, 21, 12, 21,
13, 21, 21, 21, 31, 11, 13, 21, 12, 12, 21, 21, 21, 21, 44, 13,
21, 44, 13, 21, 13, 12, 12, 21, 11, 12, 13, 13, 21, 13, 12, 43,
13, 12, 21, 13, 13, 13, 13, 12, 43, 44, 13, 42, 13, 13, 11, 21,
13, 21, 43, 12, 11, 32, 12, 11, 13, 21, 21, 44, 21), hv204 = c(15,
996, 996, 20, 996, 5, 15, 30, 996, 996, 30, 996, 5, 25, 5, 20,
996, 996, 996, 10, 996, 10, 996, 20, 60, 60, 30, 996, 996, 996,
30, 10, 15, 996, 996, 10, 996, 996, 996, 996, 996, 996, 5, 996,
996, 10, 996, 996, 996, 10, 996, 996, 996, 20, 10, 15, 20, 5,
10, 10, 996, 996, 996, 996, 996, 996, 5, 996, 5, 996, 90, 5,
996, 996, 5, 996, 15, 20, 996, 15, 30, 9, 30, 5, 10, 996, 996,
20, 996, 15, 996, 996, 10, 996, 996, 5, 996, 996, 5, 996), hv205 = c(23,
12, 12, 22, 31, 22, 31, 31, 12, 31, 31, 12, 23, 23, 31, 12, 13,
13, 23, 12, 13, 31, 22, 13, 31, 23, 31, 13, 31, 11, 31, 12, 31,
23, 12, 31, 31, 23, 31, 12, 31, 12, 31, 12, 12, 12, 13, 23, 41,
12, 12, 12, 13, 23, 12, 14, 31, 22, 31, 22, 12, 12, 31, 12, 13,
12, 31, 12, 12, 12, 31, 22, 13, 31, 31, 31, 22, 13, 13, 31, 23,
12, 31, 31, 13, 12, 12, 31, 13, 31, 12, 12, 31, 23, 12, 12, 31,
12, 22, 12)), .Names = c("hv001", "hv002", "hv005", "hv025",
"hv009", "hv012", "hv013", "hv201", "hv204", "hv205"), row.names = c(10678L,
3179L, 4323L, 8790L, 835L, 3936L, 4789L, 1696L, 6299L, 10495L,
10703L, 1909L, 5863L, 4156L, 7311L, 2912L, 5073L, 1857L, 3991L,
7840L, 5254L, 690L, 8477L, 4520L, 10597L, 3056L, 9158L, 889L,
9572L, 5096L, 1178L, 3598L, 9040L, 2989L, 6336L, 9030L, 768L,
7583L, 7539L, 5005L, 4713L, 6064L, 10013L, 2486L, 2392L, 4531L,
3596L, 9322L, 1910L, 5317L, 4631L, 6080L, 7070L, 10542L, 2501L,
2594L, 8582L, 8957L, 1223L, 10372L, 1587L, 1547L, 9960L, 5458L,
1667L, 3749L, 7100L, 3355L, 3783L, 1591L, 7087L, 1991L, 10264L,
9655L, 10147L, 7781L, 3982L, 8396L, 120L, 10106L, 10679L, 3841L,
8033L, 8519L, 10789L, 5111L, 5313L, 3309L, 7464L, 8835L, 4668L,
5526L, 7117L, 1537L, 3698L, 4355L, 916L, 10006L, 8995L, 9434L
), class = "data.frame")
答案 0 :(得分:0)
如果您保留method
默认值(即&#34;回归&#34;),您应该能够获得PCA结果。但是,我怀疑你是否会得到与SPSS相同的结果(我已经看到SPSS和R之间的差异与&#34; varimax&#34;旋转结果)。
答案 1 :(得分:0)
我仔细检查了代码。似乎分数不能作为参数传递给函数,因此请将分数的值更改为FALSE 。 请尝试以下代码....
res = principal(ws, nfactors = 1, residuals = F, rotate = "varimax", n.obs = NA, covar = T, scores = F, missing = T, impute = "mean", oblique.scores = T, method = "correlation")
我认为这将有助于继续你的工作。