Extracting output from nfactors function in psych pacakge in R

42 Views Asked by At

I have a simple reprex below showing nfactors function from the psych package. I am hoping to find a relatively easy way to extract the paragraph it provides above the dataframe that it puts out.

I want to essentially save this table into an object n R for later use. I need to do repeated runs and I need access to this information.

#> Number of factors of  VSS of 24 mental tests 
#> Call: vss(x = x, n = n, rotate = rotate, diagonal = diagonal, fm = fm, 
#>     n.obs = n.obs, plot = FALSE, title = title, use = use, cor = cor)
#> VSS complexity 1 achieves a maximimum of 0.8  with  1  factors
#> VSS complexity 2 achieves a maximimum of 0.85  with  2  factors
#> The Velicer MAP achieves a minimum of 0.02  with  4  factors 
#> Empirical BIC achieves a minimum of  -473.59  with  8  factors
#> Sample Size adjusted BIC achieves a minimum of  7.77  with  16  factors

I tried a couple of options and even some of the helper functions in the package but I am not having any success. Somewhere in the output object it needs to be contained but from the structure it is not at all evident how this works.

Full reprex here:


library(psych)
#> Warning: package 'psych' was built under R version 4.0.5

test_data <- Harman74.cor$cov
output <- psych::nfactors(test_data,title="VSS of 24 mental tests")
#> n.obs was not specified and was arbitrarily set to 1000.  This only affects the chi square values.


str(output)
#> List of 4
#>  $ title    : chr "VSS of 24 mental tests"
#>  $ map      : num [1:20] 0.0245 0.0216 0.0175 0.0174 0.0208 ...
#>  $ vss.stats:'data.frame':   20 obs. of  16 variables:
#>   ..$ dof    : num [1:20] 252 229 207 186 166 147 129 112 96 81 ...
#>   ..$ chisq  : num [1:20] 4608 3164 2217 1700 1414 ...
#>   ..$ prob   : num [1:20] 0.00 0.00 0.00 2.54e-242 1.13e-196 ...
#>   ..$ sqresid: num [1:20] 16.83 12.68 9.97 7.97 7.25 ...
#>   ..$ fit    : num [1:20] 0.796 0.846 0.879 0.904 0.912 ...
#>   ..$ RMSEA  : num [1:20] 0.1315 0.1132 0.0985 0.0902 0.0867 ...
#>   ..$ BIC    : num [1:20] 2867 1582 788 415 267 ...
#>   ..$ SABIC  : num [1:20] 3668 2309 1445 1005 794 ...
#>   ..$ complex: num [1:20] 1 1.5 1.78 1.89 2.01 ...
#>   ..$ eChisq : num [1:20] 5156 2907 1653 920 725 ...
#>   ..$ SRMR   : num [1:20] 0.0966 0.0726 0.0547 0.0408 0.0362 ...
#>   ..$ eCRMS  : num [1:20] 0.1011 0.0797 0.0632 0.0497 0.0467 ...
#>   ..$ eBIC   : num [1:20] 3416 1325 223 -365 -422 ...
#>   ..$ eRMS   : num [1:20] 0.0966 0.0726 0.0547 0.0408 0.0362 ...
#>   ..$ cfit.1 : num [1:20] 0.796 0.553 0.456 0.42 0.4 ...
#>   ..$ cfit.2 : num [1:20] 0 0.846 0.789 0.738 0.708 ...
#>  $ call     : language vss(x = x, n = n, rotate = rotate, diagonal = diagonal, fm = fm, n.obs = n.obs,      plot = FALSE, title = title,| __truncated__
#>  - attr(*, "class")= chr [1:2] "psych" "vss"

output
#> 
#> Number of factors of  VSS of 24 mental tests 
#> Call: vss(x = x, n = n, rotate = rotate, diagonal = diagonal, fm = fm, 
#>     n.obs = n.obs, plot = FALSE, title = title, use = use, cor = cor)
#> VSS complexity 1 achieves a maximimum of 0.8  with  1  factors
#> VSS complexity 2 achieves a maximimum of 0.85  with  2  factors
#> The Velicer MAP achieves a minimum of 0.02  with  4  factors 
#> Empirical BIC achieves a minimum of  -473.59  with  8  factors
#> Sample Size adjusted BIC achieves a minimum of  7.77  with  16  factors
#> 
#> Statistics by number of factors 
#>    vss1 vss2   map dof   chisq     prob sqresid  fit RMSEA     BIC  SABIC
#> 1  0.80 0.00 0.025 252 4.6e+03  0.0e+00    16.8 0.80 0.131 2867.37 3667.7
#> 2  0.55 0.85 0.022 229 3.2e+03  0.0e+00    12.7 0.85 0.113 1582.09 2309.4
#> 3  0.46 0.79 0.017 207 2.2e+03  0.0e+00    10.0 0.88 0.099  787.52 1445.0
#> 4  0.42 0.74 0.017 186 1.7e+03 2.5e-242     8.0 0.90 0.090  414.67 1005.4
#> 5  0.40 0.71 0.021 166 1.4e+03 1.1e-196     7.2 0.91 0.087  266.96  794.2
#> 6  0.40 0.71 0.024 147 1.2e+03 1.3e-168     6.3 0.92 0.085  205.79  672.7
#> 7  0.40 0.70 0.028 129 1.0e+03 3.2e-143     5.6 0.93 0.084  154.10  563.8
#> 8  0.41 0.70 0.030 112 8.4e+02 1.4e-112     5.0 0.94 0.081   70.04  425.8
#> 9  0.42 0.60 0.034  96 6.5e+02  1.6e-83     4.5 0.95 0.076  -11.18  293.7
#> 10 0.40 0.59 0.040  81 5.2e+02  1.9e-64     4.0 0.95 0.073  -44.04  213.2
#> 11 0.40 0.59 0.047  67 3.8e+02  5.6e-46     3.8 0.95 0.069  -78.97  133.8
#> 12 0.39 0.58 0.056  54 3.3e+02  1.4e-40     3.4 0.96 0.071  -46.81  124.7
#> 13 0.37 0.59 0.066  42 2.3e+02  3.8e-27     3.1 0.96 0.066  -63.56   69.8
#> 14 0.35 0.57 0.078  31 1.4e+02  3.9e-15     2.9 0.97 0.058  -77.97   20.5
#> 15 0.36 0.54 0.091  21 9.0e+01  1.4e-10     2.5 0.97 0.057  -54.69   12.0
#> 16 0.36 0.55 0.107  12 5.3e+01  4.9e-07     2.3 0.97 0.058  -30.34    7.8
#> 17 0.35 0.55 0.134   4 2.7e+01  2.0e-05     1.7 0.98 0.076   -0.63   12.1
#> 18 0.35 0.53 0.171  -3 6.3e+00       NA     1.7 0.98    NA      NA     NA
#> 19 0.30 0.49 0.206  -9 9.5e-06       NA     1.9 0.98    NA      NA     NA
#> 20 0.31 0.53 0.264 -14 1.2e-05       NA     1.8 0.98    NA      NA     NA
#>    complex  eChisq    SRMR eCRMS eBIC
#> 1      1.0 5.2e+03 9.7e-02 0.101 3416
#> 2      1.5 2.9e+03 7.3e-02 0.080 1325
#> 3      1.8 1.7e+03 5.5e-02 0.063  223
#> 4      1.9 9.2e+02 4.1e-02 0.050 -365
#> 5      2.0 7.2e+02 3.6e-02 0.047 -422
#> 6      2.0 5.6e+02 3.2e-02 0.044 -457
#> 7      2.2 4.3e+02 2.8e-02 0.041 -463
#> 8      2.3 3.0e+02 2.3e-02 0.037 -474
#> 9      2.7 2.0e+02 1.9e-02 0.033 -459
#> 10     2.7 1.4e+02 1.6e-02 0.029 -419
#> 11     2.8 1.0e+02 1.4e-02 0.028 -359
#> 12     2.7 7.6e+01 1.2e-02 0.027 -297
#> 13     2.7 5.3e+01 9.8e-03 0.025 -237
#> 14     2.8 2.9e+01 7.3e-03 0.022 -185
#> 15     2.7 1.5e+01 5.3e-03 0.019 -130
#> 16     2.7 8.2e+00 3.8e-03 0.018  -75
#> 17     2.8 4.0e+00 2.7e-03 0.022  -24
#> 18     2.9 9.5e-01 1.3e-03    NA   NA
#> 19     2.8 1.2e-06 1.5e-06    NA   NA
#> 20     2.7 1.5e-06 1.6e-06    NA   NA

Created on 2023-06-07 by the reprex package (v2.0.1)
0

There are 0 best solutions below