0

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, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 2L, 0L, 0L, 0L, 
1L, 4L, 1L, 0L, 3L, 2L, 1L, 0L, 0L, 2L, 0L, 1L, 1L, 2L, 4L, 7L, 
0L, 0L, 0L, 1L, 3L, 0L, 2L, 0L, 7L, 0L, 4L, 0L, 1L, 0L, 0L, 0L, 
1L, 1L, 1L, 2L, 2L, 0L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 
0L, 0L, 0L, 3L, 2L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 2L, 
0L, 4L, 2L, 4L, 2L, 3L, 1L, 1L, 2L, 4L, 3L, 0L, 2L, 4L, 1L, 1L, 
1L, 0L, 1L, 0L, 1L, 3L, 1L, 4L, 1L, 1L, 2L, 4L, 3L, 0L, 1L, 0L, 
1L, 0L, 0L, 2L, 0L, 0L, 1L, 1L, 3L, 1L, 0L, 1L, 2L, 4L, 2L, 1L, 
1L, 2L, 3L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 4L, 2L, 0L, 2L, 0L, 1L, 
0L, 2L, 4L, 0L, 2L, 0L, 2L, 2L, 4L, 0L, 0L, 1L, 1L, 2L, 2L, 2L, 
1L, 1L, 2L, 3L, 0L, 2L, 0L, 1L, 3L, 7L, 1L, 2L, 2L, 0L, 0L, 3L, 
0L, 1L, 1L, 0L, 2L, 2L, 3L, 0L, 2L, 2L, 1L, 0L, 2L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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))
Z.Lin
  • 28,055
  • 6
  • 54
  • 94
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. If that's the error you are getting it seems very unlikely that the first line is actually running correctly. Are you sure there's not some other syntax error going in somewhere in code you haven't shown us? – MrFlick May 14 '19 at 16:20
  • Thanks! I'm still new to R and learning! My other other code before the fator analysis code is MDI <- read.csv("PolychoricMatrixfor EFA.csv") #Reading in polychoric matrix MDI <- data.frame(MDI) #Making it into a dataframe to be easier to work with names(MDI). These all seem to work fine. So the issue may be with the matrix? – Kevin Jefferson May 14 '19 at 16:56

1 Answers1

0

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?

Jason Johnson
  • 451
  • 3
  • 7
  • Thank you for this! So I guess I didn't have to compute to polychoric matrix myself for the EFA afterall. I ran this with the raw data as the imput for MDI. The factor analysis works although I get a strange error message: – Kevin Jefferson May 14 '19 at 19:37
  • "Error in (function (L, Tmat = diag(ncol(L)), gam = 0, normalize = FALSE, : unused argument (rotation = "promax") In addition: Warning messages: 1: In matpLower(x, nvar, gminx, gmaxx, gminy, gmaxy) : 424 cells were adjusted for 0 values using the correction for continuity. Examine your data carefully. – Kevin Jefferson May 14 '19 at 19:37
  • 2: In cor.smooth(mat) : Matrix was not positive definite, smoothing was done Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), : 'data' must be of a vector type, was 'NULL' In addition: Warning message: In fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate = rotate, : The requested transformaton failed, Promax was used instead as an oblique transformation." – Kevin Jefferson May 14 '19 at 19:37
  • This error message confuses me because there are no missing data. I only included complete observations in the raw data. Also I specified a promax rotation so I don;t understand why it looks like it tried to use oblique rotation and then defaulted to promax – Kevin Jefferson May 14 '19 at 19:38
  • Let me figure out how to best share data. (Dput?) I'm new to learning R-- so I don't know how to best share data on these forums – Kevin Jefferson May 14 '19 at 19:40
  • OK I don;t know if I did this the best way or not but I used dput and added it to my question above. – Kevin Jefferson May 14 '19 at 19:50
  • Your `dput` was fine and I was able to load your data and you can get rid of the `n.obs` argument since MDI has number of rows. I will add more comments to my answer. – Jason Johnson May 14 '19 at 22:39