简体   繁体   中英

Principal component analysis using “Principal”

I am using principal() function from psych package to replicate SPSS principal component analysis results in R. (as recommended in: https://stats.stackexchange.com/questions/612/is-pca-followed-by-a-rotation-eg-varimax-still-pca )

I'm using the code below:

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")

But I'm getting the following error:

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

Any advice would be much appreciated. I'm attaching a sample of my data (by dput(ws) ) below. Thank you so much!

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")

If you leave the method default (which is "regression") you should be able to get the PCA results. However, I doubt if you will get the same results as SPSS (I have seen discrepancy between SPSS and R with "varimax" rotation results).

I went through the code. It seems that scores cannot be passed as an argument to the function so please change the value of the score to FALSE . Try the code below....

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")

I think it will help to continue your work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM