You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用lavaan::cfa执行验证性因子分析时遭遇「unused arguments」错误的技术求助

Fixing unused arguments Error in lavaan's cfa() Function

It looks like you’re hitting two key issues here: invalid arguments passed to the cfa() function, and incorrect comment syntax in your model string. Let’s break down how to fix both:

1. Invalid Arguments in cfa()

The error unused arguments (text = theory_syn_eq, reference.indicators = FALSE) occurs because:

  • Lavaan’s cfa() function doesn’t accept a text parameter—you should pass your model using the model argument (or directly as the first positional input).
  • There’s no reference.indicators parameter. If your goal is to avoid using reference indicators (i.e., fix latent variable variances instead of locking an indicator’s loading to 1), use std.lv = TRUE instead.

2. Incorrect Comment Syntax in Model String

Lavaan uses # to define group models, not for comments. To add descriptive labels for your factors, replace # with // (the proper syntax for comments in lavaan’s model language). Your original string uses # which will cause parsing errors.

Corrected Code

Here’s the fixed version of your code:

# Fix model syntax comments
theory_syn_eq <- " 
ZAV: Z1, Z2, Z3, Z4, Z5, Z6 // Závažnost 
DOP: D1, D2, D3, D4, D5, D6 // Dopadení 
PPZ: Pr1, Pr2, Pr3, Pr4, Pr5, Pr6 // Problémproživot 
ROD: R1, R2, R3, R4, R5, R6 // Rodiče 
PRA: P1, P2, P3, P4, P5, P6 // Přátele 
SP: S1, S2, S3, S4, S5, S6 // Školapráce 
"

# Use correct cfa() arguments
library(lavaan)
theory_syn <- cfa(model = theory_syn_eq, std.lv = TRUE)

Explanation

  • std.lv = TRUE: This tells lavaan to set each latent variable’s variance to 1, instead of fixing the first indicator’s loading to 1 (the default behavior). This achieves what you were aiming for with reference.indicators = FALSE.
  • // for comments: This ensures lavaan parses your model correctly without misinterpreting factor labels as group specifications.

If you still run into issues, double-check that your dataset includes all variables listed in the model (Z1-Z6, D1-D6, etc.) and that you’ve loaded the lavaan package before running cfa().

内容的提问来源于stack exchange,提问作者David Kružlík

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 08:52:47