提取psych包中主函数的输出作为数据帧 [英] Extracting output from principal function in psych package as a data frame

查看:185
本文介绍了提取psych包中主函数的输出作为数据帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用主函数时,像下面的代码一样,我得到一个很好的表,它给出了所有的标准化加载,以及一个具有特征值,比例和累积比例的表格。

  rotatepca<  -  principal(PCFdataset,nfactors = 8,rotate =varimax,scores = T)
我想将这个输出导出到一个excel文件(使用WriteXLS),但是我只能为数据框做这个输出,并且rotatepca不是数据帧,不能被强制转换成一个它似乎。我可以使用以下代码来提取标准化的加载:

  loads< -as.data.frame(unclass $ load $)

但是,我简直不知道如何访问通常显示的其他信息调用主要函数,特别是特征值和比例和累积方差。我尝试了rotatecpa $值,但是返回的是所有12个原始变量的特征值,这些变量是没有旋转的因素,我不明白。而且我还没有找到任何方法甚至尝试提取方差说明值。例如,如何创建一个看起来像R输出的数据帧,例如?

  RC2 RC3 RC8 RC1 RC4 RC5 RC6 RC7 
SS装载1.52 1.50 1.45 1.44 1.01 1.00 0.99 0.98
比例变量0.13 0.12 0.12 0.12 0.08 0.08 0.08 0.08
累积变量0.13 0.25 0.37 0.49 0.58 0.66 0.74 0.82
比例说明0.15 0.15 0.15 0.15 0.10 0.10 0.10 0.10
累计比例0.15 0.31 0.45 0.60 0.70 0.80 0.90 1.00

感谢您阅读我的帖子!

解决方案

我刚刚将此功能添加到最新(截至今天)释放灵魂1.3.10.11。
如果你

  f3<  -  fa(Thurstone,3)
#or
p3< - principal(Thurstone,3)
#then
p< - print(f3)
p#将给你
p
$虚拟
MR1 MR2 MR3
SS加载2.6411150 1.8621522 1.4951831
比例Var 0.2934572 0.2069058 0.1661315
累计变动0.2934572 0.5003630 0.6664945
比例说明0.4402995 0.3104389 0.2492616
比例0.4402995 0.7507384 1.0000000

一般来说,如果您有psych包的建议或问题,如果您与我联系,您将得到更快的答案直接。



Bill


When I use the principal function, like in the following code, I get a nice table which gives all the standardized loadings, as well as a table with the eigenvalues and the proportion and cumulative proportion explained.

rotatedpca <- principal(PCFdataset, nfactors = 8, rotate = "varimax", scores = T)

I would like to export this output to an excel file (using WriteXLS), but I can only do that for dataframes, and rotatedpca is not a dataframe and cannot be coerced into one it seems. I am able to extract the standardized loadings by using the following code:

loadings<-as.data.frame(unclass(rotatedpca$loadings))

But I cannot figure out how to access the other information that normally displays when I simply call the principal function, in particular the eigenvalues and the proportion and cumulative variance explained. I tried rotatedcpa$values, but that returns what looks like the eigenvalues for all 12 original variables as factors without rotation, which I don't understand. And I haven't been able to figure out any way to even try to extract the variance explained values. How can I simply create a dataframe that looks like the R output I get below from the principal function, for example?

                       RC2  RC3  RC8  RC1  RC4  RC5  RC6  RC7
SS loadings           1.52 1.50 1.45 1.44 1.01 1.00 0.99 0.98
Proportion Var        0.13 0.12 0.12 0.12 0.08 0.08 0.08 0.08
Cumulative Var        0.13 0.25 0.37 0.49 0.58 0.66 0.74 0.82
Proportion Explained  0.15 0.15 0.15 0.15 0.10 0.10 0.10 0.10
Cumulative Proportion 0.15 0.31 0.45 0.60 0.70 0.80 0.90 1.00

Thanks for reading my post!

解决方案

I have just added this feature to the latest (as of today) release of psych 1.3.10.11. If you either

 f3 <- fa(Thurstone,3) 
   #or
   p3 <- principal(Thurstone,3)
   #then
   p <- print(f3)
   p # will give you
    p
   $Vaccounted
                            MR1       MR2       MR3
   SS loadings           2.6411150 1.8621522 1.4951831
  Proportion Var        0.2934572 0.2069058 0.1661315
  Cumulative Var        0.2934572 0.5003630 0.6664945
  Proportion Explained  0.4402995 0.3104389 0.2492616
  Proportion            0.4402995 0.7507384 1.0000000

In general, if you have suggestions or questions re the psych package, you will get a faster answer if you contact me directly.

Bill

这篇关于提取psych包中主函数的输出作为数据帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆