简体   繁体   English

软件包“ psych”的因子分析中未找到对象“ w”的错误

[英]Object 'w' not found error in factor analysis with package 'psych'

A lot of questions about factor analysis on these pages. 这些页面上有很多关于因子分析的问题。 I have browsed through them but nothing seems similar, so hopefully someone can help. 我已经浏览了它们,但是似乎没有相似之处,因此希望有人可以提供帮助。

I am running a factor analysis on some survey questions where I expect some latent constructs to emerge. 我正在对一些调查问题进行因子分析,我希望这些潜在问题会出现。 I am running either principal axes or minres and get the same problem, as detailed below. 我正在运行主轴或minres并遇到相同的问题,如下所述。

My dataset contains many discrete variables and a reasonable amount of missing variables coded as NA , but even after removing all NA the problem persists: 我的数据集包含许多离散变量和相当数量的缺失变量,编码为NA ,但是即使删除了所有NA ,问题仍然存在:

minres.out <- factor.minres(r = res, nfactors = 5, residuals=F, rotate = "varimax", n.obs=NA, scores=F, SMC=T, missing=F, min.err=0.001, ,max.iter=50, symmetric=T,warnings=T,fm="minres")
  minres.out

minres.out2 <- fa(r = res, nfactors = 5, residuals=F, rotate = "oblimin", n.obs=NA, scores=F, SMC=T, missing=F, impute="median",min.err=0.001, ,max.iter=50, symmetric=T,warnings=T,fm="minres", alpha=0.1, p=0.05,oblique.scores=F, use="pairwise")
  minres.out2

The first one uses the deprecated version and gives me a warning, but it works. 第一个使用了不推荐使用的版本,并给了我一个警告,但是它可以工作。 The second one gives me the following error: 第二个给我以下错误:

Error in factor.scores(x.matrix, f = Structure, method = scores) : 
  object 'w' not found

I have no object w in my data, but I do not really understand what this object is meant to be in the first place. 我的数据中没有对象w ,但是我真的不了解该对象的初衷。

Running traceback() gives me: 运行traceback()给我:

3: factor.scores(x.matrix, f = Structure, method = scores)
2: fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate = rotate, 
       scores = scores, residuals = residuals, SMC = SMC, covar = covar, 
       missing = FALSE, impute = impute, min.err = min.err, max.iter = max.iter, 
       symmetric = symmetric, warnings = warnings, fm = fm, alpha = alpha, 
       oblique.scores = oblique.scores, np.obs = np.obs, use = use, 
       ...)
1: fa(r = res, nfactors = 5, residuals = F, rotate = "oblimin", 
       n.obs = NA, scores = F, SMC = T, missing = F, impute = "median", 
       min.err = 0.001, , max.iter = 50, symmetric = T, warnings = T, 
       fm = "minres", alpha = 0.1, p = 0.05, oblique.scores = F, 
       use = "pairwise")

Not very enlightening to me. 对我不是很有启发。 Any suggestions regarding this w ? 对此有什么建议w

I went through the code line-by-line. 我逐行检查了代码。 It seems that scores cannot be passed as an argument to the factor.scores function. 似乎scores不能作为参数传递给factor.scores函数。 It goes through a switch statement and none of the branches activates, so you end up with no value for w which causes it to fail. 它通过switch语句,并且没有分支激活,因此最终没有w值,这导致它失败。 You could try copying and pasting the following silly fix into your R session and then running your code again: 您可以尝试将以下愚蠢的修复程序复制并粘贴到R会话中,然后再次运行代码:

fa <- function(r, nfactors = 1, n.obs = NA, n.iter = 1, rotate = "oblimin", 
    scores = "regression", residuals = FALSE, SMC = TRUE, covar = FALSE, 
    missing = FALSE, impute = "median", min.err = 0.001, max.iter = 50, 
    symmetric = TRUE, warnings = TRUE, fm = "minres", alpha = 0.1, 
    p = 0.05, oblique.scores = FALSE, np.obs = NULL, use = "pairwise", 
    ...){

scores <- c("a","b")
psych::fa(r, nfactors = 1, n.obs = NA, n.iter = 1, rotate = "oblimin", 
    scores = "regression", residuals = FALSE, SMC = TRUE, covar = FALSE, 
    missing = FALSE, impute = "median", min.err = 0.001, max.iter = 50, 
    symmetric = TRUE, warnings = TRUE, fm = "minres", alpha = 0.1, 
    p = 0.05, oblique.scores = FALSE, np.obs = NULL, use = "pairwise", 
    ...)
}

I had this same error. 我有同样的错误。 Mine was caused because I tried to pass "Regression" to scores instead of "regression". 我的原因是我试图将“回归”传递给分数而不是“回归”。 So make sure that what you're passing to scores is an acceptable parameter option. 因此,请确保传递给分数的内容是可接受的参数选项。

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

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