I have to identify genes showing sex specific expression in 2 tissues: "pancreas" and "lung".
To do it first of all i need to do a PCA to ascertain whether there is separation between tissues of different sexes (in particular there are 3 individuals of sex 1 and 3 of sex2 for each tissue)
I suppose that i should classify the genes in counts for sex by using the sex column in the Design list and after I should perform a PCA where different colors are assigned to sex 1 and sex 2 genes.
The problem is that even if I know what I should do to perform the PCA (if what i tought is right) I don't know how to write the codes required to do it: how can i create a new dataframe made by only the genes in count that correspond to lung and pancreas rows in Design?
I thought to do in this way in order to color the genes with different colors depending by sex (information shown in Design), if there's a simplier way is well accepted any suggestion.
dput(Design[1:10,]):
Design = structure(list(Individual = c("GTEX-Y5V6", "GTEX-1KXAM", "GTEX-18A67",
"GTEX-14BMU", "GTEX-13PVR", "GTEX-1211K", "GTEX-1KXAM", "GTEX-18A67",
"GTEX-14BMU", "GTEX-1211K"), sex = c(1L, 1L, 1L, 2L, 2L, 2L,
1L, 1L, 2L, 2L), age = c("60-69", "60-69", "50-59", "20-29",
"60-69", "60-69", "60-69", "50-59", "20-29", "60-69"), RNA.quality..max10. = c(7.1,
8.1, 7.2, 7.2, 7.3, 7, 7.2, 7.3, 7.4, 8.2), organ = c("Thyroid",
"Thyroid", "Thyroid", "Thyroid", "Thyroid", "Thyroid", "Stomach",
"Stomach", "Stomach", "Stomach"), tissue = c("Thyroid", "Thyroid",
"Thyroid", "Thyroid", "Thyroid", "Thyroid", "Stomach", "Stomach",
"Stomach", "Stomach")), row.names = c("GTEX-Y5V6-0526-SM-4VBRV",
"GTEX-1KXAM-1726-SM-D3LAE", "GTEX-18A67-0826-SM-7KFTI", "GTEX-14BMU-0226-SM-5S2QA",
"GTEX-13PVR-0626-SM-5S2RC", "GTEX-1211K-0726-SM-5FQUW", "GTEX-1KXAM-0926-SM-CXZKA",
"GTEX-18A67-2626-SM-718AD", "GTEX-14BMU-1126-SM-5RQJ8", "GTEX-1211K-1426-SM-5FQTF"
), class = "data.frame")
dput(counts[1:10,]):
structure(list(`GTEX-Y5V6-0526-SM-4VBRV` = c(0L, 1L, 2L, 1L,
0L, 0L, 0L, 0L, 0L, 214L), `GTEX-1KXAM-1726-SM-D3LAE` = c(0L,
0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 205L), `GTEX-18A67-0826-SM-7KFTI` = c(0L,
0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 164L), `GTEX-14BMU-0226-SM-5S2QA` = c(0L,
0L, 0L, 12L, 0L, 0L, 0L, 0L, 0L, 108L), `GTEX-13PVR-0626-SM-5S2RC` = c(0L,
0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 100L), `GTEX-1211K-0726-SM-5FQUW` = c(0L,
0L, 0L, 2L, 0L, 0L, 1L, 0L, 0L, 174L), `GTEX-1KXAM-0926-SM-CXZKA` = c(2L,
1L, 2L, 2L, 0L, 0L, 0L, 0L, 0L, 99L), `GTEX-18A67-2626-SM-718AD` = c(7L,
3L, 7L, 2L, 0L, 1L, 5L, 0L, 0L, 116L), `GTEX-14BMU-1126-SM-5RQJ8` = c(0L,
0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 44L), `GTEX-1211K-1426-SM-5FQTF` = c(4L,
0L, 5L, 2L, 0L, 0L, 0L, 0L, 0L, 143L), `GTEX-11TT1-0726-SM-5GU5A` = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 57L), `GTEX-1HCUA-1626-SM-A9SMG` = c(0L,
0L, 0L, 22L, 0L, 0L, 0L, 0L, 0L, 53L), `GTEX-1KXAM-0226-SM-EV7AP` = c(0L,
0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 75L), `GTEX-18A67-1726-SM-7KFT9` = c(0L,
0L, 2L, 1L, 0L, 0L, 0L, 0L, 0L, 73L), `GTEX-14BMU-0726-SM-73KXS` = c(0L,
0L, 0L, 40L, 0L, 0L, 0L, 0L, 0L, 74L), `GTEX-13PVR-0726-SM-5S2PX` = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 54L), `GTEX-1211K-1126-SM-5EGGB` = c(0L,
1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 25L), `GTEX-11TT1-0326-SM-5LUAY` = c(0L,
0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 54L), `GTEX-1KXAM-2426-SM-DIPFC` = c(1L,
0L, 2L, 1L, 0L, 0L, 2L, 0L, 0L, 29L), `GTEX-18A67-0326-SM-7LG5X` = c(0L,
0L, 5L, 4L, 0L, 0L, 2L, 0L, 1L, 91L), `GTEX-14BMU-2026-SM-5S2W6` = c(0L,
0L, 2L, 5L, 0L, 0L, 0L, 0L, 0L, 30L), `GTEX-13PVR-2526-SM-5RQIT` = c(0L,
0L, 2L, 1L, 0L, 0L, 0L, 0L, 0L, 14L), `GTEX-1211K-2126-SM-59HJZ` = c(1L,
0L, 2L, 0L, 0L, 0L, 1L, 0L, 0L, 51L), `GTEX-Y3I4-2326-SM-4TT81` = c(0L,
0L, 3L, 0L, 0L, 0L, 1L, 0L, 0L, 38L), `GTEX-1KXAM-0426-SM-DHXKG` = c(0L,
0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 105L), `GTEX-18A67-1126-SM-7KFSB` = c(1L,
0L, 0L, 4L, 0L, 0L, 1L, 0L, 0L, 76L), `GTEX-14BMU-0526-SM-73KW4` = c(0L,
0L, 0L, 11L, 0L, 0L, 0L, 0L, 0L, 53L), `GTEX-1211K-0826-SM-5FQUP` = c(1L,
0L, 0L, 2L, 0L, 0L, 1L, 0L, 0L, 104L), `GTEX-11TT1-1626-SM-5EQL7` = c(0L,
0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 113L), `GTEX-ZYFG-0226-SM-5GIDT` = c(1L,
0L, 2L, 2L, 0L, 0L, 2L, 0L, 0L, 54L), `GTEX-1KXAM-0826-SM-CXZK9` = c(0L,
0L, 0L, 5L, 0L, 0L, 2L, 0L, 0L, 97L), `GTEX-18A67-2426-SM-7LT95` = c(1L,
0L, 2L, 0L, 0L, 1L, 3L, 0L, 0L, 69L), `GTEX-14BMU-0926-SM-5S2QB` = c(0L,
0L, 0L, 3L, 0L, 0L, 0L, 0L, 0L, 29L), `GTEX-13PVR-1826-SM-5Q5CC` = c(1L,
0L, 0L, 3L, 0L, 1L, 2L, 0L, 0L, 32L), `GTEX-1211K-0926-SM-5FQTL` = c(0L,
0L, 0L, 3L, 0L, 0L, 1L, 0L, 0L, 99L), `GTEX-11TT1-0526-SM-5P9JO` = c(0L,
1L, 2L, 4L, 0L, 0L, 2L, 0L, 0L, 52L), `GTEX-1KXAM-0726-SM-E9U5I` = c(0L,
0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 45L), `GTEX-18A67-2526-SM-7LG5Z` = c(1L,
0L, 2L, 0L, 0L, 0L, 1L, 0L, 0L, 91L), `GTEX-14BMU-1026-SM-5RQJ5` = c(1L,
0L, 1L, 8L, 0L, 0L, 0L, 0L, 0L, 47L), `GTEX-13PVR-2026-SM-73KXT` = c(0L,
0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 27L), `GTEX-1211K-1326-SM-5FQV2` = c(0L,
0L, 3L, 0L, 0L, 0L, 1L, 1L, 0L, 57L), `GTEX-11TT1-0626-SM-5GU4X` = c(1L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 90L), `GTEX-ZYFG-1826-SM-5GZWX` = c(0L,
0L, 3L, 2L, 0L, 0L, 2L, 0L, 0L, 91L), `GTEX-1KXAM-1926-SM-D3LAG` = c(0L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 103L), `GTEX-18A67-2226-SM-7LT9Z` = c(0L,
0L, 2L, 2L, 0L, 0L, 1L, 0L, 1L, 157L), `GTEX-13PVR-1726-SM-5Q5EC` = c(1L,
0L, 2L, 0L, 0L, 0L, 1L, 0L, 0L, 34L), `GTEX-1211K-1826-SM-5EGJ2` = c(0L,
0L, 1L, 3L, 0L, 0L, 0L, 0L, 0L, 49L), `GTEX-11TT1-0926-SM-5GU5M` = c(0L,
2L, 0L, 3L, 1L, 0L, 0L, 0L, 1L, 49L), `GTEX-1KXAM-1026-SM-CY8IA` = c(0L,
0L, 1L, 3L, 0L, 0L, 0L, 0L, 0L, 93L), `GTEX-14BMU-1626-SM-5TDE7` = c(0L,
1L, 3L, 13L, 0L, 0L, 1L, 0L, 0L, 84L), `GTEX-13PVR-2226-SM-7DHKP` = c(0L,
0L, 2L, 2L, 0L, 0L, 0L, 0L, 0L, 75L), `GTEX-1211K-1926-SM-5EQLB` = c(0L,
1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 114L), `GTEX-11TT1-2126-SM-5GU5Y` = c(2L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 49L), `GTEX-ZT9W-2026-SM-51MRA` = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 70L), `GTEX-1KXAM-2326-SM-CYPTD` = c(0L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 20L), `GTEX-18A67-0226-SM-7LG67` = c(0L,
0L, 5L, 2L, 0L, 0L, 1L, 0L, 0L, 94L), `GTEX-14BMU-2126-SM-5S2TS` = c(0L,
0L, 0L, 3L, 0L, 0L, 0L, 0L, 0L, 50L), `GTEX-13PVR-2426-SM-5RQHN` = c(0L,
0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 59L), `GTEX-1211K-2226-SM-5FQU6` = c(0L,
0L, 0L, 3L, 0L, 0L, 0L, 0L, 0L, 81L), `GTEX-11TT1-2426-SM-5EQMK` = c(0L,
1L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 60L)), row.names = c("ENSG00000243485",
"ENSG00000237613", "ENSG00000186092", "ENSG00000238009", "ENSG00000222623",
"ENSG00000241599", "ENSG00000236601", "ENSG00000235146", "ENSG00000223181",
"ENSG00000237491"), class = "data.frame")
I am running an exploratory factor analysis and am specifying that the factor analysis results be loaded onto f2.
My code is below. The first line runs but when I go to run my next line of code, where I reference f2, I get a message "object 'f2' not found".
So somehow the assignment isn't working. Am I missing something really obvious? The factor analysis uses the psych package. I have checked the documentation and the examples they give assign factor analysis results to objects similarly, so I'm a bit stumped. Any pointers would be greatly appreciated.
f2 <- fa(MDI, nfactors = 30, n.obs = 286, rotation = "promax", min.err = 0.001,
fm = "wls", cor = "poly")
load = loadings(f2)
print(load, sort = TRUE, digits = 2, cutoff = 0.001)
plot(load)
identify(load, labels = names(MDI))
plot(f2, labels = names(MDI))
Below is dput of the correlation matrix so it can be reproducible.
> dput(MDI)
structure(list(X = structure(c(1L, 12L, 23L, 25L, 26L, 27L, 28L,
29L, 30L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L), .Label = c("mdi1",
"mdi10", "mdi11", "mdi12", "mdi13", "mdi14", "mdi15", "mdi16",
"mdi17", "mdi18", "mdi19", "mdi2", "mdi20", "mdi21", "mdi22",
"mdi23", "mdi24", "mdi25", "mdi26", "mdi27", "mdi28", "mdi29",
"mdi3", "mdi30", "mdi4", "mdi5", "mdi6", "mdi7", "mdi8", "mdi9"
), class = "factor"), mdi1 = c(1, 0.3936173, 0.4689895, 0.3723157,
0.5000249, 0.4007723, 0.4752565, 0.3299713, 0.4467554, 0.3092035,
0.4587867, 0.3502716, 0.4765846, 0.4296331, 0.4279444, 0.3978138,
0.3130349, 0.4217768, 0.4217768, 0.3941672, 0.442678, 0.4143811,
0.4883476, 0.3818616, 0.4253592, 0.4220679, 0.3341886, 0.2904774,
0.4125257, 0.471747), mdi2 = c(0.3936173, 1, 0.5687221, 0.5503958,
0.3579519, 0.5524491, 0.4113922, 0.5692459, 0.5244077, 0.4519596,
0.4691271, 0.3328134, 0.3909096, 0.5207473, 0.517872, 0.4460308,
0.5357907, 0.5271745, 0.5656711, 0.6416844, 0.5933588, 0.5301733,
0.4632707, 0.3692169, 0.3899222, 0.6722428, 0.571866, 0.4770556,
0.4447538, 0.4801506), mi3 = c(0.4689895, 0.5687221, 1, 0.5337568,
0.4605771, 0.5801225, 0.4748034, 0.5027398, 0.6493962, 0.4371995,
0.4814276, 0.5174168, 0.4575024, 0.5161417, 0.7302354, 0.443922,
0.4503891, 0.6403537, 0.4638545, 0.5755256, 0.6559644, 0.5669309,
0.4882669, 0.540937, 0.4305827, 0.6208696, 0.5774123, 0.4337106,
0.5007241, 0.5812161), mdi4 = c(0.3723157, 0.5503958, 0.5337568,
1, 0.4647914, 0.5432398, 0.5222107, 0.480119, 0.5095777, 0.6127156,
0.5411, 0.3438971, 0.5132041, 0.4708869, 0.5773365, 0.640864,
0.5419371, 0.4278067, 0.4294387, 0.5762886, 0.6173602, 0.696368,
0.4768973, 0.4312955, 0.4800561, 0.4966285, 0.4940535, 0.6449681,
0.4448795, 0.4511662), mdi5 = c(0.5000249, 0.3579519, 0.4605771,
0.4647914, 1, 0.529076, 0.4627546, 0.4322669, 0.5266816, 0.4193437,
0.5274925, 0.355744, 0.4748984, 0.3943626, 0.5452649, 0.4282942,
0.3884295, 0.4405988, 0.5013351, 0.4372788, 0.5033538, 0.449599,
0.4719872, 0.5221968, 0.4572666, 0.478281, 0.4474777, 0.436465,
0.6423572, 0.5367758), mdi6 = c(0.4007723, 0.5524491, 0.5801225,
0.5432398, 0.529076, 1, 0.5481986, 0.5292259, 0.554901, 0.5197566,
0.6618723, 0.7776074, 0.5538152, 0.5513789, 0.6005339, 0.5479274,
0.5154317, 0.7863542, 0.5508043, 0.6893594, 0.5754793, 0.6092226,
0.5590816, 0.7415316, 0.5702535, 0.7306869, 0.6161738, 0.5381451,
0.5487092, 0.7739138), mdi7 = c(0.4752565, 0.4113922, 0.4748034,
0.5222107, 0.4627546, 0.5481986, 1, 0.4208138, 0.5818144, 0.5123467,
0.5154297, 0.5182619, 0.6342495, 0.5054629, 0.5154232, 0.550466,
0.4921495, 0.4687262, 0.4268752, 0.56955, 0.5046245, 0.5563658,
0.544639, 0.4961694, 0.6133689, 0.5084869, 0.4299369, 0.5220904,
0.4294706, 0.4739928), mdi8 = c(0.3299713, 0.5692459, 0.5027398,
0.480119, 0.4322669, 0.5292259, 0.4208138, 1, 0.5723092, 0.3119612,
0.4675261, 0.3380419, 0.353584, 0.4541021, 0.5421594, 0.474245,
0.6079999, 0.5235899, 0.5335896, 0.4957257, 0.5442768, 0.4974862,
0.5023641, 0.4025193, 0.4116167, 0.5727691, 0.6270551, 0.4208924,
0.5064872, 0.4869765), mdi9 = c(0.4467554, 0.5244077, 0.6493962,
0.5095777, 0.5266816, 0.554901, 0.5818144, 0.5723092, 1, 0.490689,
0.5181651, 0.4850319, 0.5356553, 0.6158338, 0.6559043, 0.5307519,
0.5871398, 0.5846594, 0.5470594, 0.6284931, 0.6879265, 0.6163574,
0.512804, 0.5047779, 0.5466345, 0.613476, 0.5883362, 0.506302,
0.4979364, 0.5808664), mdi10 = c(0.3092035, 0.4519596, 0.4371995,
0.6127156, 0.4193437, 0.5197566, 0.5123467, 0.3119612, 0.490689,
1, 0.5118569, 0.4462334, 0.4532171, 0.4315306, 0.4522421, 0.7588315,
0.4401081, 0.4350122, 0.4499751, 0.5206525, 0.5352926, 0.6998865,
0.4755847, 0.4100334, 0.4787971, 0.453012, 0.4734884, 0.7813307,
0.535401, 0.4395691), mdi11 = c(0.4587867, 0.4691271, 0.4814276,
0.5411, 0.5274925, 0.6618723, 0.5154297, 0.4675261, 0.5181651,
0.5118569, 1, 0.5527827, 0.501612, 0.5149324, 0.540138, 0.5069535,
0.528538, 0.579202, 0.5901564, 0.5299329, 0.5250493, 0.5154014,
0.5127527, 0.5788864, 0.5161334, 0.507289, 0.5158013, 0.5344951,
0.5978617, 0.647102), mdi12 = c(0.3502716, 0.3328134, 0.5174168,
0.3438971, 0.355744, 0.7776074, 0.5182619, 0.3380419, 0.4850319,
0.4462334, 0.5527827, 1, 0.5154903, 0.4620118, 0.472202, 0.4547294,
0.4840607, 0.8285936, 0.5358637, 0.5490359, 0.4616615, 0.4249117,
0.4808445, 0.7267043, 0.552395, 0.5925844, 0.4751664, 0.3929154,
0.4023344, 0.6972608), mdi13 = c(0.4765846, 0.3909096, 0.4575024,
0.5132041, 0.4748984, 0.5538152, 0.6342495, 0.353584, 0.5356553,
0.4532171, 0.501612, 0.5154903, 1, 0.517566, 0.5669901, 0.4811508,
0.4159442, 0.5916418, 0.5317423, 0.6019275, 0.5150589, 0.6103914,
0.7036702, 0.5396378, 0.7106897, 0.5663952, 0.4743636, 0.5357141,
0.4997759, 0.5310849), mdi14 = c(0.4296331, 0.5207473, 0.5161417,
0.4708869, 0.3943626, 0.5513789, 0.5054629, 0.4541021, 0.6158338,
0.4315306, 0.5149324, 0.4620118, 0.517566, 1, 0.5294991, 0.4641652,
0.5595265, 0.5568292, 0.5329007, 0.6300983, 0.5476386, 0.6433976,
0.5124435, 0.5178623, 0.4634521, 0.6025023, 0.4958374, 0.4741311,
0.4363587, 0.5922855), mdi15 = c(0.4279444, 0.517872, 0.7302354,
0.5773365, 0.5452649, 0.6005339, 0.5154232, 0.5421594, 0.6559043,
0.4522421, 0.540138, 0.472202, 0.5669901, 0.5294991, 1, 0.4969139,
0.5407898, 0.711619, 0.5776979, 0.6465131, 0.8102714, 0.6210396,
0.5843541, 0.5708951, 0.5353925, 0.6430862, 0.6773275, 0.5256203,
0.5525755, 0.5968413), mdi16 = c(0.3978138, 0.4460308, 0.443922,
0.640864, 0.4282942, 0.5479274, 0.550466, 0.474245, 0.5307519,
0.7588315, 0.5069535, 0.4547294, 0.4811508, 0.4641652, 0.4969139,
1, 0.5327385, 0.4919386, 0.4640105, 0.6189401, 0.6221125, 0.7849677,
0.5263167, 0.4961512, 0.546515, 0.4792591, 0.5387354, 0.7593365,
0.5443296, 0.4965095), mdi17 = c(0.3130349, 0.5357907, 0.4503891,
0.5419371, 0.3884295, 0.5154317, 0.4921495, 0.6079999, 0.5871398,
0.4401081, 0.528538, 0.4840607, 0.4159442, 0.5595265, 0.5407898,
0.5327385, 1, 0.5972664, 0.6531257, 0.6124992, 0.6593416, 0.5779083,
0.54295, 0.5091556, 0.4999436, 0.5534753, 0.6906962, 0.5515724,
0.5763667, 0.5257787), mdi18 = c(0.4217768, 0.5271745, 0.6403537,
0.4278067, 0.4405988, 0.7863542, 0.4687262, 0.5235899, 0.5846594,
0.4350122, 0.579202, 0.8285936, 0.5916418, 0.5568292, 0.711619,
0.4919386, 0.5972664, 1, 0.616892, 0.6776108, 0.653145, 0.6462477,
0.6133169, 0.76014, 0.5693621, 0.7255007, 0.6772965, 0.4731968,
0.6136029, 0.8215128), mdi19 = c(0.4217768, 0.5656711, 0.4638545,
0.4294387, 0.5013351, 0.5508043, 0.4268752, 0.5335896, 0.5470594,
0.4499751, 0.5901564, 0.5358637, 0.5317423, 0.5329007, 0.5776979,
0.4640105, 0.6531257, 0.616892, 1, 0.6277485, 0.5888859, 0.5781749,
0.5962161, 0.4966702, 0.525626, 0.5893053, 0.5937545, 0.4536458,
0.6023978, 0.595442), mdi20 = c(0.3941672, 0.6416844, 0.5755256,
0.5762886, 0.4372788, 0.6893594, 0.56955, 0.4957257, 0.6284931,
0.5206525, 0.5299329, 0.5490359, 0.6019275, 0.6300983, 0.6465131,
0.6189401, 0.6124992, 0.6776108, 0.6277485, 1, 0.7456018, 0.7237394,
0.5914482, 0.6174089, 0.6084753, 0.7583413, 0.6222094, 0.6093335,
0.5607048, 0.6734581), mdi21 = c(0.442678, 0.5933588, 0.6559644,
0.6173602, 0.5033538, 0.5754793, 0.5046245, 0.5442768, 0.6879265,
0.5352926, 0.5250493, 0.4616615, 0.5150589, 0.5476386, 0.8102714,
0.6221125, 0.6593416, 0.653145, 0.5888859, 0.7456018, 1, 0.6836611,
0.5767896, 0.5020915, 0.5302819, 0.6788499, 0.7302629, 0.5532899,
0.514876, 0.5369505), mdi22 = c(0.4143811, 0.5301733, 0.5669309,
0.696368, 0.449599, 0.6092226, 0.5563658, 0.4974862, 0.6163574,
0.6998865, 0.5154014, 0.4249117, 0.6103914, 0.6433976, 0.6210396,
0.7849677, 0.5779083, 0.6462477, 0.5781749, 0.7237394, 0.6836611,
1, 0.6970878, 0.5551017, 0.5309829, 0.669629, 0.618117, 0.7725701,
0.5368407, 0.6161932), mdi23 = c(0.4883476, 0.4632707, 0.4882669,
0.4768973, 0.4719872, 0.5590816, 0.544639, 0.5023641, 0.512804,
0.4755847, 0.5127527, 0.4808445, 0.7036702, 0.5124435, 0.5843541,
0.5263167, 0.54295, 0.6133169, 0.5962161, 0.5914482, 0.5767896,
0.6970878, 1, 0.5780347, 0.5722519, 0.6007872, 0.6153544, 0.579486,
0.5826146, 0.5400445), mdi24 = c(0.3818616, 0.3692169, 0.540937,
0.4312955, 0.5221968, 0.7415316, 0.4961694, 0.4025193, 0.5047779,
0.4100334, 0.5788864, 0.7267043, 0.5396378, 0.5178623, 0.5708951,
0.4961512, 0.5091556, 0.76014, 0.4966702, 0.6174089, 0.5020915,
0.5551017, 0.5780347, 1, 0.5823804, 0.6163705, 0.5893418, 0.4599374,
0.4879448, 0.7233099), mdi25 = c(0.4253592, 0.3899222, 0.4305827,
0.4800561, 0.4572666, 0.5702535, 0.6133689, 0.4116167, 0.5466345,
0.4787971, 0.5161334, 0.552395, 0.7106897, 0.4634521, 0.5353925,
0.546515, 0.4999436, 0.5693621, 0.525626, 0.6084753, 0.5302819,
0.5309829, 0.5722519, 0.5823804, 1, 0.6287262, 0.4351833, 0.541565,
0.488426, 0.5750416), mdi26 = c(0.4220679, 0.6722428, 0.6208696,
0.4966285, 0.478281, 0.7306869, 0.5084869, 0.5727691, 0.613476,
0.453012, 0.507289, 0.5925844, 0.5663952, 0.6025023, 0.6430862,
0.4792591, 0.5534753, 0.7255007, 0.5893053, 0.7583413, 0.6788499,
0.669629, 0.6007872, 0.6163705, 0.6287262, 1, 0.6485229, 0.6028357,
0.5814636, 0.6474577), mdi27 = c(0.3341886, 0.571866, 0.5774123,
0.4940535, 0.4474777, 0.6161738, 0.4299369, 0.6270551, 0.5883362,
0.4734884, 0.5158013, 0.4751664, 0.4743636, 0.4958374, 0.6773275,
0.5387354, 0.6906962, 0.6772965, 0.5937545, 0.6222094, 0.7302629,
0.618117, 0.6153544, 0.5893418, 0.4351833, 0.6485229, 1, 0.5630586,
0.5338222, 0.5340758), mdi28 = c(0.2904774, 0.4770556, 0.4337106,
0.6449681, 0.436465, 0.5381451, 0.5220904, 0.4208924, 0.506302,
0.7813307, 0.5344951, 0.3929154, 0.5357141, 0.4741311, 0.5256203,
0.7593365, 0.5515724, 0.4731968, 0.4536458, 0.6093335, 0.5532899,
0.7725701, 0.579486, 0.4599374, 0.541565, 0.6028357, 0.5630586,
1, 0.5835477, 0.5081215), mdi29 = c(0.4125257, 0.4447538, 0.5007241,
0.4448795, 0.6423572, 0.5487092, 0.4294706, 0.5064872, 0.4979364,
0.535401, 0.5978617, 0.4023344, 0.4997759, 0.4363587, 0.5525755,
0.5443296, 0.5763667, 0.6136029, 0.6023978, 0.5607048, 0.514876,
0.5368407, 0.5826146, 0.4879448, 0.488426, 0.5814636, 0.5338222,
0.5835477, 1, 0.611525), mdi30 = c(0.471747, 0.4801506, 0.5812161,
0.4511662, 0.5367758, 0.7739138, 0.4739928, 0.4869765, 0.5808664,
0.4395691, 0.647102, 0.6972608, 0.5310849, 0.5922855, 0.5968413,
0.4965095, 0.5257787, 0.8215128, 0.595442, 0.6734581, 0.5369505,
0.6161932, 0.5400445, 0.7233099, 0.5750416, 0.6474577, 0.5340758,
0.5081215, NA, 1)), class = "data.frame", row.names = c(NA, -30L
))
I was able to use the raw data as input for MDI and the factor analysis ran with error messages (in comment below so that this post isn't super long). The actual dataset is really big but I created a smaller dataset from it that generates the same error message when I run the factor analysis. THe dput for that smaller data set is below.
>dput(MDI)
structure(list(MDIdisengagement = c(2L, 1L, 1L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 1L, 3L,
1L, 4L, 2L, 0L, 1L, 0L, 2L, 4L, 2L, 0L, 0L, 1L, 1L, 0L, 2L, 1L,
1L, 1L, 0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, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 1L, 1L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 0L, 2L, 0L, 0L,
0L, 3L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
3L, 0L, 0L, 0L, 0L, 4L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 1L, 2L, 1L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 1L, 1L,
0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 7L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L,
0L, 1L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 7L, 0L, 0L, 1L, 1L, 0L, 0L,
0L, 4L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L,
2L, 0L, 0L, 3L, 1L, 0L, 0L, 4L, 0L, 0L, 0L, 0L, 4L, 0L, 0L, 2L,
0L, 0L)), class = "data.frame", row.names = c(NA, -291L))
You have a few problems going on in your call to fa. First you need to remove the X column to provide a proper correlation matrix. This may not be an issue for you but of course is for your dput example. However even after fixing this the main issue is with your call to polychoric correlation. If you want to specify cor = "poly" you need to use the discrete data.
What I would suggest is to run your call to fa using the discrete data with only the measurement variables and no extra variables like X. If you are still getting errors then please update your example to include the discrete data and I can try to help you.
EDIT: So now your big problem is that you only have 6 items and in factor analysis you usually want a minimum of three items per factor which in your case would leave you with at most 2 factors but even that is pushing it. With nfactors=1 it will work but not with nfactors>1 To see why you are having issues you can look at the eigenvalues of your correlation matrix like so:
eigen(polychoric(MDI)$rho)
This produces the following output:
$values
[1] 4.76730952 0.68445132 0.28440838 0.18855401 0.05141578 0.02386099
As you can see, nearly all of the variance is being explained by the first factor and there is little left after. Therefore, it is not surprising that you are getting errors when trying to extract more than one factor. A scree plot will visually show this.
So this will work but the results are probably not very interesting:
f2 <- fa(MDI,nfactors=1,rotation="promax", min.err= 0.001, fm="wls", cor="poly")
Does that make sense?