2

我不知道如何在某个值上方或下方的表格中选择性地打印值。我正在寻找的东西在 Revelle 的心理包中被称为“cut”。MWE 下面。

library("psych")
library("psychTools")
derp <- fa(ability, nfactors=3)
print(derp, cut=0.5) #removes all loadings smaller than 0.5
derp <- print(derp, cut=0.5) #apa_table still doesn't print like this

问题是,如何将该剪辑添加到 apa_table?打印 apa_table(derp) 会打印整个表,包括所有值。

4

1 回答 1

2

print-method frompsych不返回格式化的载荷,而只返回考虑的方差表。但是,您可以通过手动格式化负载表来获得所需的结果:

library("psych")
library("psychTools")
derp <- fa(ability, nfactors=3)

# Class `loadings` cannot be coerced to data.frame or matrix
class(derp$Structure)
  [1] "loadings"
# Class `matrix` is supported by apa_table()
derp_loadings <- unclass(derp$Structure)
class(derp_loadings)
  [1] "matrix"
# Remove values below "cut"
derp_loadings[derp_loadings < 0.5] <- NA

colnames(derp_loadings) <- paste("Factor", 1:3)

apa_table(
  derp_loadings
  , caption = "Factor loadings"
  , added_stub_head = "Item"
  , format = "pandoc" # Omit this in your R Markdown document
  , format.args = list(na_string = "") # Don't print NA
)
*Factor loadings*
Item        Factor 1   Factor 2   Factor 3 
----------  ---------  ---------  ---------
reason.4                          0.60     
reason.16                                  
reason.17                         0.65     
reason.19                                  
letter.7               0.61                
letter.33              0.56                
letter.34              0.65                
letter.58                                  
matrix.45                                  
matrix.46                                  
matrix.47                                  
matrix.55                                  
rotate.3    0.70                           
rotate.4    0.73                           
rotate.6    0.63                           
rotate.8    0.63                           
于 2020-05-26T09:03:54.100 回答