简体   繁体   中英

factanal in Base R and handling of NAs

I have a data.frame called D shown HERE . I'm want to use the factanal function in base R on the first 8 columns of D .

I'm wondering, however, why I get the following error: 'x' must contain finite values only while I have set for NA s 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

The documentation states that the na.action argument applies only if a formula is passed as x . If you want to pass a data.frame with missing values you need to subset it.

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 

Or same result:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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