[英]factanal in Base R and handling of NAs
我有一個名為D
的data.frame
顯示在這里。 我想在D
的前8
列中使用基礎factanal
中的事實 function 。
但是,我想知道為什么會出現以下錯誤: 'x' 必須僅在我設置了要刪除的NA
'x' must contain finite values only
?
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" )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.