zoukankan      html  css  js  c++  java
  • pearson相关分析在R中的实现

    三个相关性函数:

    cor():R自带的,输入数据可以是vector,matrix,data.frame,输出两两的相关系数R值

    cor.test():R自带的,输入数据只能是两个vector,输出两个变量的相关系数R值,显著性水平a值

    corr.test():psych包的,输入数据可以是data.frame,输出两两变量的相关系数R值,显著性水平a值

    > cor(state.x77)
                Population     Income  Illiteracy    Life Exp     Murder     HS Grad      Frost        Area
    Population  1.00000000  0.2082276  0.10762237 -0.06805195  0.3436428 -0.09848975 -0.3321525  0.02254384
    Income      0.20822756  1.0000000 -0.43707519  0.34025534 -0.2300776  0.61993232  0.2262822  0.36331544
    Illiteracy  0.10762237 -0.4370752  1.00000000 -0.58847793  0.7029752 -0.65718861 -0.6719470  0.07726113
    Life Exp   -0.06805195  0.3402553 -0.58847793  1.00000000 -0.7808458  0.58221620  0.2620680 -0.10733194
    Murder      0.34364275 -0.2300776  0.70297520 -0.78084575  1.0000000 -0.48797102 -0.5388834  0.22839021
    HS Grad    -0.09848975  0.6199323 -0.65718861  0.58221620 -0.4879710  1.00000000  0.3667797  0.33354187
    Frost      -0.33215245  0.2262822 -0.67194697  0.26206801 -0.5388834  0.36677970  1.0000000  0.05922910
    Area        0.02254384  0.3633154  0.07726113 -0.10733194  0.2283902  0.33354187  0.0592291  1.00000000
    > cor.test(state.x77[,1],state.x77[,2])
    
    	Pearson's product-moment correlation
    
    data:  state.x77[, 1] and state.x77[, 2]
    t = 1.475, df = 48, p-value = 0.1467
    alternative hypothesis: true correlation is not equal to 0
    95 percent confidence interval:
     -0.07443435  0.45991855
    sample estimates:
          cor 
    0.2082276 
    
    > corr.test(state.x77)
    Call:corr.test(x = state.x77)
    Correlation matrix 
               Population Income Illiteracy Life Exp Murder HS Grad Frost  Area
    Population       1.00   0.21       0.11    -0.07   0.34   -0.10 -0.33  0.02
    Income           0.21   1.00      -0.44     0.34  -0.23    0.62  0.23  0.36
    Illiteracy       0.11  -0.44       1.00    -0.59   0.70   -0.66 -0.67  0.08
    Life Exp        -0.07   0.34      -0.59     1.00  -0.78    0.58  0.26 -0.11
    Murder           0.34  -0.23       0.70    -0.78   1.00   -0.49 -0.54  0.23
    HS Grad         -0.10   0.62      -0.66     0.58  -0.49    1.00  0.37  0.33
    Frost           -0.33   0.23      -0.67     0.26  -0.54    0.37  1.00  0.06
    Area             0.02   0.36       0.08    -0.11   0.23    0.33  0.06  1.00
    Sample Size 
    [1] 50
    Probability values (Entries above the diagonal are adjusted for multiple tests.) 
               Population Income Illiteracy Life Exp Murder HS Grad Frost Area
    Population       0.00   1.00       1.00     1.00   0.23    1.00  0.25 1.00
    Income           0.15   0.00       0.03     0.23   1.00    0.00  1.00 0.16
    Illiteracy       0.46   0.00       0.00     0.00   0.00    0.00  0.00 1.00
    Life Exp         0.64   0.02       0.00     0.00   0.00    0.00  0.79 1.00
    Murder           0.01   0.11       0.00     0.00   0.00    0.01  0.00 1.00
    HS Grad          0.50   0.00       0.00     0.00   0.00    0.00  0.16 0.25
    Frost            0.02   0.11       0.00     0.07   0.00    0.01  0.00 1.00
    Area             0.88   0.01       0.59     0.46   0.11    0.02  0.68 0.00
    
     To see confidence intervals of the correlations, print with the short=FALSE option
    

      

  • 相关阅读:
    macOS 10.13 High Sierra PHP开发环境配置
    Mac brew安装redis
    【PHP】进一法取整、四舍五入取整、忽略小数等的取整数方法大全
    解决上传app store卡在正在通过iTunes Store鉴定
    PHP 时间操作
    GO获取随机数
    GO语言数组,切片,MAP总结
    性能规范参考指标
    Jmeter聚合报告理解
    性能概述及技术指南
  • 原文地址:https://www.cnblogs.com/timeisbiggestboss/p/8477138.html
Copyright © 2011-2022 走看看