简体   繁体   English

在 R 潜在变量分析中理解问题并得到错误 Lavaan 包

[英]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 , weightnps是因素(对于它们每个都有三个观察值),那么

mat1 <- cor(data.frame(age,weight,nps))

might produce the intended covariance matrix.可能会产生预期的协方差矩阵。

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

相关问题 R Lavaan package 错误:一些潜在变量名与观察到的变量名冲突 - R Lavaan package ERROR: some latent variable names collide with observed variable names R Lavaan编码潜变量相互作用 - R Lavaan coding latent variable interactions R 中的 lavaan package 中的“NA * 变量”是什么? (因子分析) - What is "NA * variable" in lavaan package in R? (factor analysis) 如何在 R 中使用 lavaan 包测试潜在变量因子载荷的差异 - how test the difference in factor loadings of latent variable using lavaan package in R s + x[[i]] 中的错误:用于潜在类分析的 R - gmnl 包中的非一致数组 - Error in s + x[[i]] : non-conformable arrays in R - gmnl package for Latent Class Analysis 连续调节器和与 lavaan 中的潜在变量的交互项 - Continuous moderator and an interaction term with a latent variable in lavaan 在 lavaan 中使用单个指标指定潜在变量 - Specifying a latent variable with a single indicaror in lavaan R中的潜在配置文件分析 - Latent Profile Analysis in R 通过在 R 中的 mclust package 分析 BIC 的可重复性导致潜在的 class 分析 - Reproducibility of BIC results in latent class analysis via mclust package in R 如何使用lavaan对R中的形成潜变量进行建模,并添加控制变量 - How to model formative latent variable in R using lavaan, and also add control variables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM