I'm simulating data for SEM (structural equation model) with psych
package. I used the code given on page 17 of Using the psych package to generate and test structural models . The code is
library(psych)
set.seed(42)
fx <- matrix(c(0.9, 0.8, 0.7, rep(0, 9), 0.7, 0.6, 0.5, rep(0, 9), 0.6, 0.5, 0.4), ncol = 3)
rownames(fx) <- paste("x", 1:9, sep="")
fy <- matrix(c(0.6, 0.5, 0.4), ncol=1)
rownames(fy) <- paste("y", 1:3, sep="")
Phi <- matrix(c(1, 0.48, 0.32, 0.4, 0.48, 1, 0.32, 0.3, 0.32, 0.32, 1, 0.2, 0.4, 0.3, 0.2, 1), ncol = 4)
twelveV <- sim.structure(fx=fx, Phi=Phi, fy=fy, n=100, raw=TRUE)
round(twelveV$model, 2)
round(twelveV$model-twelveV$r, 2)
twelveV$observed
Then I tried to use sem
package to analyse the simulated data. The code is
sem.mod <- structure.sem(twelveV$model)
library(sem)
sem.fit <- sem(sem.mod, twelveV$r, 100)
This code is giving the following error message:
Error in solve.default(diag(m) - A) :
Lapack routine dgesv: system is exactly singular
I don't what is causing this error. Any idea, comment and/or help will be highly appreciated. Thanks
Ah, that error message was the bane of my life for a while.
Essentially (as I eventually gathered from the R-Help archives, specifically here , it means that there is redundant information in your matrix in that (at least) one column's information can be derived from one of the others.
I believe that this is related to collinearity, but i could be wrong on this point. In most cases, dropping the column that is most highly correlated with the others will solve the problem.
In a real application, its a sign to throw out some of your questions or measures.
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.