zoukankan      html  css  js  c++  java
  • R语言-主成分分析

    > #########主成分分析与因子分析
    > setwd("/Users/yaozhilin/Downloads/R_edu/data")
    > pt<-read.csv("profile_telecom.csv")
    > head(pt,5)
           ID cnt_call cnt_msg cnt_wei cnt_web
    1 1964627       46      90      36      31
    2 3107769       53       2       0       2
    3 3686296       28      24       5       8
    4 3961002        9       2       0       4
    5 4174839      145       2       0       1
    > library(psych)
    > #用fa.parallel()确定主成分个数
    > fa.parallel(pt,fa="pc",n.iter = 100)

    > #用principal()进行主成分分析:nfactors =表示主成分个数,rotate = "varimax"旋转方法
    > Pc_pt<-principal(pt[,-1],nfactors = 3,rotate = "varimax",scores = T)
    > Pc_pt
    Principal Components Analysis
    Call: principal(r = pt[, -1], nfactors = 3, rotate = "varimax", scores = T)
    Standardized loadings (pattern matrix) based upon correlation matrix
              RC1  RC3  RC2 h2      u2 com
    cnt_call 0.06 0.02 1.00  1 6.5e-08 1.0
    cnt_msg  0.33 0.94 0.02  1 3.7e-04 1.2
    cnt_wei  0.98 0.19 0.06  1 1.9e-03 1.1
    cnt_web  0.88 0.48 0.06  1 3.1e-03 1.6
    
                           RC1  RC3  RC2
    SS loadings           1.84 1.15 1.00
    Proportion Var        0.46 0.29 0.25
    Cumulative Var        0.46 0.75 1.00
    Proportion Explained  0.46 0.29 0.25
    Cumulative Proportion 0.46 0.75 1.00
    
    Mean item complexity =  1.2
    Test of the hypothesis that 3 components are sufficient.
    
    The root mean square of the residuals (RMSR) is  0 
     with the empirical chi square  0.01  with prob <  NA 
    
    Fit based upon off diagonal values = 1
    > ptpc<-cbind(pt,Pc_pt$scores)
    > head(ptpc)
           ID cnt_call cnt_msg cnt_wei cnt_web        RC1        RC3        RC2
    1 1964627       46      90      36      31  0.1952344  3.8712835 -0.3726676
    2 3107769       53       2       0       2 -0.4219981 -0.6793516 -0.1552081
    3 3686296       28      24       5       8 -0.4194772  0.5202526 -0.5541321
    4 3961002        9       2       0       4 -0.2943034 -0.6714705 -0.8283602
    5 4174839      145       2       0       1 -0.5535192 -0.6802487  1.2451860
    6 5068087      186       4       3       1 -0.5413228 -0.6159420  1.8639601
    
  • 相关阅读:
    [原]如何在Android用FFmpeg+SDL2.0之同步视频
    鹤山市五泉酒厂 (“侨乡情”酒 )
    买酒的网站(转)
    泥鳅、黄鳝有关技术。
    国产 冰葡萄酒 主要生产地、品牌
    对症治疗过敏性鼻炎,依巴斯汀比氯雷他定更有效
    魔筎精粉制作 ----新化联系人
    拉肚子使用的常见药物
    一些WCF DS 的资料(参考)
    SHAREPOINT 2013 + PROJECT 2013 资料网站
  • 原文地址:https://www.cnblogs.com/ye20190812/p/13893955.html
Copyright © 2011-2022 走看看