简体   繁体   English

使用心理软件包为SEM模拟数据

[英]Simulating Data for SEM with psych package

I'm simulating data for SEM (structural equation model) with psych package. 我正在使用psych软件包模拟SEM(结构方程模型)的数据。 I used the code given on page 17 of Using the psych package to generate and test structural models . 我使用了使用psych软件包的第17页上给出的代码来生成和测试结构模型 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. 然后,我尝试使用sem包来分析模拟数据。 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. 从本质上讲(我最终从R-帮助档案收集,特别是在这里 ,这意味着在你的(至少)一个栏的信息可以从别人的一个衍生矩阵的冗余信息。

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. 在实际的应用程序中,它是抛出一些问题或措施的信号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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