Principal Component Analysis in R: prcomp vs princomp |
您所在的位置:网站首页 › prcomp() › Principal Component Analysis in R: prcomp vs princomp |
Supplementary variables
Qualitative / categorical variables
The data sets decathlon2 contain a supplementary qualitative variable at columns 13 corresponding to the type of competitions. Qualitative / categorical variables can be used to color individuals by groups. The grouping variable should be of same length as the number of active individuals (here 23). groupsCalculate the coordinates for the levels of grouping variables. The coordinates for a given group is calculated as the mean coordinates of the individuals in the group. library(magrittr) # for pipe %>% library(dplyr) # everything else # 1. Individual coordinates res.ind % as_data_frame() %>% select(Dim.1, Dim.2) %>% mutate(competition = groups) %>% group_by(competition) %>% summarise( Dim.1 = mean(Dim.1), Dim.2 = mean(Dim.2) ) coord.groups ## # A tibble: 2 x 3 ## competition Dim.1 Dim.2 ## ## 1 Decastar -1.31 -0.119 ## 2 OlympicG 1.20 0.109 Quantitative variablesData: columns 11:12. Should be of same length as the number of active individuals (here 23) quanti.sup ## Rank Points ## SEBRLE 1 8217 ## CLAY 2 8122 ## BERNARD 4 8067 ## YURKOV 5 8036 ## ZSIVOCZKY 7 8004 ## McMULLEN 8 7995The coordinates of a given quantitative variable are calculated as the correlation between the quantitative variables and the principal components. # Predict coordinates and compute cos2 quanti.coord |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |