如何从 R 中的 mixedCor {psych} 相关性中提取 p 值

How to extract the p values from mixedCor {psych} correlation in R

您好,我正在使用包 psych 中的 mixedCor 来分析混合数据。 有没有人有使用这个包的经验?是否可以设置显着性水平以及如何绘制结果?

library(psych)

# I have data set consist of continues variables:
> class(scd)
[1] "data.frame"
> dim(scd)
[1] 1000    7
# and data set consist of dummy variables:
> class(bian)
[1] "data.frame"
> dim(bian)
[1] 1000    4




n<-mixed.cor(x = scd, p = bian)

> n
Call: mixed.cor(x = scd, p = bian)
                     Age   Rlgsn Intip IoNPO Incom Dntnf Dntna Gendr Chldr Pet   Vlntr
Age                   1.00                                                            
Religiousness        -0.07  1.00                                                      
Interest in politics -0.19  0.04  1.00                                                
Impact of NPO's       0.01  0.10  0.09  1.00                                          
Income                0.37 -0.02 -0.14  0.01  1.00                                    
Donation frequency    0.08 -0.15 -0.06 -0.08  0.00  1.00                              
Donation amount       0.06 -0.10 -0.05  0.04  0.20  0.04  1.00                        
Gender               -0.06  0.15 -0.20  0.16  0.08 -0.05 -0.04  1.00                  
Children              1.00 -0.18 -0.23  0.05  0.42  0.11  0.18 -0.15  1.00            
Pet                   0.06  0.18  0.06  0.03  0.02  0.02 -0.07 -0.17  0.08  1.00      
Volunteer             0.05 -0.24 -0.23 -0.21  0.03  0.09  0.07 -0.02  0.10  0.04  1.00

问题是我无法将此输出 table 复制到 data.frame,而且我找不到过滤重要值的方法。

> n$rho
Call: 
Error: $ operator is invalid for atomic vectors

这是我在尝试访问相关性时遇到的错误 table

您正在寻找这样的东西吗?

n <- cor.ci(bfi[,c(1:5,26,28)],poly=TRUE, plot=F)

CorrTable <- n["rho"]

> CorrTable
$rho
               A1         A2          A3         A4         A5      gender         age
A1      1.0000000 -0.4084638 -0.32251744 -0.1754424 -0.2278395 -0.22858169 -0.17421138
A2     -0.4084638  1.0000000  0.55545103  0.3897144  0.4488210  0.25291876  0.12489782
A3     -0.3225174  0.5554510  1.00000000  0.4080689  0.5728565  0.20226959  0.07472984
A4     -0.1754424  0.3897144  0.40806891  1.0000000  0.3552859  0.19972576  0.16000917
A5     -0.2278395  0.4488210  0.57285647  0.3552859  1.0000000  0.13536493  0.13808548
gender -0.2285817  0.2529188  0.20226959  0.1997258  0.1353649  1.00000000  0.06197663
age    -0.1742114  0.1248978  0.07472984  0.1600092  0.1380855  0.06197663  1.00000000

#Get table of confidence intervals and only keep those with p<.05
require(dplyr)
Significant <- data.frame(n["ci"]) %>% mutate(Correlation=row.names(.)) %>% filter(ci.p<.05)

> Significant
       ci.lower     ci.low.e   ci.upper    ci.up.e         ci.p Correlation
1  -0.452232197 -0.453877196 -0.3619042 -0.3604374 0.000000e+00       A1-A2
2  -0.361218278 -0.356008043 -0.2747760 -0.2771704 0.000000e+00       A1-A3
3  -0.218952806 -0.219826548 -0.1276200 -0.1333996 5.060397e-13       A1-A4
4  -0.264688484 -0.259502965 -0.1872032 -0.1842328 0.000000e+00       A1-A5
5  -0.284548998 -0.281365660 -0.1692228 -0.1760545 2.300382e-13    A1-gendr
6  -0.212549644 -0.208996817 -0.1330437 -0.1246278 2.220446e-16      A1-age
7   0.521920083  0.521444647  0.5913877  0.5843988 0.000000e+00       A2-A3
8   0.352456028  0.354520611  0.4295087  0.4306129 0.000000e+00       A2-A4
9   0.410979114  0.413714402  0.4873637  0.4893516 0.000000e+00       A2-A5
10  0.203734982  0.209240328  0.2988768  0.2938920 0.000000e+00    A2-gendr
11  0.082020319  0.085666776  0.1642994  0.1645434 7.251809e-09      A2-age
12  0.368357960  0.372292822  0.4385225  0.4361084 0.000000e+00       A3-A4
13  0.535389947  0.537376171  0.6081013  0.6029797 0.000000e+00       A3-A5
14  0.151224464  0.156345001  0.2473505  0.2419796 5.551115e-15    A3-gendr
15  0.027669312  0.022842270  0.1163394  0.1134321 1.520197e-03      A3-age
16  0.312018205  0.310561702  0.3944081  0.3923113 0.000000e+00       A4-A5
17  0.141115630  0.143278359  0.2585775  0.2595806 1.389824e-10    A4-gendr
18  0.120141021  0.122818756  0.1954795  0.1906974 1.110223e-15      A4-age
19  0.080374786  0.085360533  0.1917875  0.1914606 2.492361e-06    A5-gendr
20  0.091283846  0.088516320  0.1776239  0.1734189 1.957320e-09      A5-age
21  0.005062216  0.002824092  0.1094059  0.1012318 3.179484e-02   gendr-age