Base R 中的 factanal 和 NA 的处理

factanal in Base R and handling of NAs

我有一个名为 Ddata.frame 显示 HERE。我想在 D 的前 8 列上使用 base R 中的 factanal 函数。

不过,我想知道为什么会出现以下错误:'x' must contain finite values only while I have set for NAs to be removed?

D <- read.csv("https://raw.githubusercontent.com/rnorouzian/i/master/SLI.csv", h = T)

pre <- D[1:8] # separate first 8 columns

factanal(pre, factors = 1, scores = "reg", na.action = na.omit) 

# Error in cov.wt(z) : 'x' must contain finite values only

文档指出 na.action 参数仅在公式作为 x 传递时适用。如果您想传递缺少值的 data.frame,您需要对其进行子集化。

pre <- D[complete.cases(D[1:8]),1:8] 

factanal(pre, factors = 1, scores = "reg" ) 

Call:
factanal(x = pre, factors = 1, scores = "reg")

Uniquenesses:
 Q1_a  Q2_a  Q3_a  Q4_a  Q5_a  Q6_a  Q7_a  Q8_a 
0.645 0.547 0.801 0.556 0.254 0.280 0.996 0.915 

Loadings:
     Factor1
Q1_a 0.596  
Q2_a 0.673  
Q3_a 0.446  
Q4_a 0.666  
Q5_a 0.863  
Q6_a 0.848  
Q7_a        
Q8_a 0.292  

               Factor1
SS loadings      3.006
Proportion Var   0.376

Test of the hypothesis that 1 factor is sufficient.
The chi square statistic is 17.83 on 20 degrees of freedom.
The p-value is 0.599 

或相同的结果:

factanal(as.formula(paste0("~", paste0(names(D[1:8]), collapse = " + "))), data = D, na.action = "na.omit", factors = 1, scores = "reg" )