[英]In R Latent Variable Analysis understanding problem and get error Lavaan package
My problem statement is to identify the factors that affects net promoter score我的问题陈述是确定影响净推荐值的因素
I am using lavaan package testing with sample data我正在使用带有示例数据的 lavaan 包测试
Below is the code下面是代码
library(lavaan)
age=c(24,56,34)
weight=c(76,55,66)
nps=c(9,4,5)
df=c(age,weight,nps)
mat1=matrix(c(cov(abs(scale(df)))),3,3,byrow=TRUE)
mod2 <- "weight ~ age \n weight ~ nps"
mod1 <- "nps ~ age \n nps ~ weight"
mat1=matrix(c(cor(abs(scale(df)))),3,3,byrow=TRUE)
colnames(mat1) <- rownames(mat1) <- c("age", "weight", "nps")
mod1fit <- sem(mod1, sample.cov = mat1, sample.nobs = 100)
From above example can anyone help in understanding nobs[Number of Observations=100]
.从上面的例子中,任何人都可以帮助理解
nobs[Number of Observations=100]
。 Usually in ML observations says about number of rows but I don't know the meaning here of nobs parameter .通常在 ML 观察中说的是行数,但我不知道 nobs 参数的含义。
I have used below link to learn我已经使用下面的链接来学习
https://www.jaredknowles.com/journal/2013/9/1/latent-variable-analysis-with-r-getting-setup-with-lavaan https://www.jaredknowles.com/journal/2013/9/1/latent-variable-analysis-with-r-getting-setup-with-lavaan
When I run above code I get error as below当我运行上面的代码时,我收到如下错误
Error in lav_samplestats_icov(COV = cov[[g]], ridge = ridge, x.idx = x.idx[[g]], :
lavaan ERROR: sample covariance matrix is not positive-definite
The lavaan
manual (that you can access from within the R console via the command ?sem
) states that the argument sample.nobs
refers to lavaan
手册(您可以通过命令?sem
从 R 控制台中访问)指出参数sample.nobs
指的是
Number of observations if the full data frame is missing and only sample moments are given.
如果缺少完整数据框且仅给出样本矩,则观察次数。 For a multiple group analysis, a list or a vector with the number of observations for each group.
对于多组分析,包含每个组的观察数的列表或向量。
Considering the error message: I'm not really sure what you are trying to acchieve with that following line of code考虑到错误消息:我不太确定您要使用以下代码行实现什么
mat1=matrix(c(cov(abs(scale(df)))),3,3,byrow=TRUE)
This however leads to a non-positive definite sample covariance matrix that looks like this然而,这会导致非正定样本协方差矩阵看起来像这样
> mat1
age weight nps
age 1 1 1
weight 1 1 1
nps 1 1 1
If age
, weight
and nps
are factors (for which you have three observations each) then如果
age
, weight
和nps
是因素(对于它们每个都有三个观察值),那么
mat1 <- cor(data.frame(age,weight,nps))
might produce the intended covariance matrix.可能会产生预期的协方差矩阵。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.