【问题标题】:factanal in Base R and handling of NAsBase R中的factanal和NA的处理
【发布时间】:2020-01-25 03:30:15
【问题描述】:

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

但是,我想知道为什么会出现以下错误:'x' must contain finite values only 而我已设置要删除 NAs?

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

【问题讨论】:

    标签: r function statistics factor-analysis


    【解决方案1】:

    文档指出,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" )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-19
      • 2017-06-23
      • 2012-07-17
      • 2018-08-07
      • 2017-04-17
      • 2012-01-17
      • 1970-01-01
      相关资源
      最近更新 更多