0

I want to do an oblique PCA using Promax on my data. It looks like many famous packages only handle orthogonal rotations or no rotation at all.

I somehow managed to do it using "Principal" from the "Psych" package:

pca <- principal(DataN[,2:6], nfactors=2, rotate="promax")

I have exactly what I need, 2 components, correlated to each other, with 5 variables. Using biplot(pca) I got almost exactly the graph I want... except I'd like to color my points based on a categorical variable (Men vs. women). Basically using ggplot I could go on (DataN, groups = DataN$Gender) and it would automatically color my data depending on the sex.

But here nothing works. I have tried many different things, but promax rotation only seems to be doable using "psych", which is not compatible with ggbiplot etc.

I'm really new to R, and I found no way to do it using the traditional "biplot". Could somebody help ? Thank you very much.

Edit : Well my data goes like this :

Sex     numericvar1     numvar2     numvar3     numvar4      numvar5
M          5              7          8            3              2
F          4              4          3            2              5
M          7              5          6            4              3
F          4              6          5            4              3

My code was pretty simple :

library(psych)
biplot(principal(myData,nfactors = 2, rotate = "promax"))
Manhervart
  • 21
  • 4
  • https://stats.stackexchange.com/questions/5774/can-principal-component-analysis-be-applied-to-datasets-containing-a-mix-of-cont – Adam Quek Aug 06 '19 at 03:21
  • Hi, thanks but I don't want to incorporate the men/women in the analysis, i just want to colorize my PCA plot points depending on it – Manhervart Aug 06 '19 at 04:06
  • Can you provide a [reproducible example](https://stackoverflow.com/a/5963610/1552004) (i.e., data + code)? – Dan Aug 06 '19 at 11:08

1 Answers1

0

When using a new function it is good to read the manual page for that function. In this case the biplot.psych function in the psych package has an example labeled, "#now plot with different colors and shapes for males and females". The example is a bit complicated. This is simpler and uses the data set "iris" on three different species but it should be easy to adapt:

data(iris)
iris.pca <- principal(iris[, -5], nfactors=2, rotate="promax")
grp <- as.numeric(iris$Species)
biplot(iris.pca, pch=15:17, group=grp)

This plots each of the three species a different symbol and color using the first three colors in the default palette(). You must define a symbol for each group in the pch= argument although c(16, 16, 16) would use the same symbol for each group. The group= argument must identify the group for each observation.

dcarlson
  • 10,936
  • 2
  • 15
  • 18
  • Thanks, but for some reason it didn't work for me I kept getting "NAs introduced by coercion". But I found the solution, using "as.factor(mydata$gender)" instead of "as.numeric". Indeed i Had to fill the pch=argument. Thanks ! – Manhervart Aug 06 '19 at 19:51
  • Apparently gender was a character vector. That is why it is so important to show the structure of the data - str(data) or dput(data). A printout of the data does not show those important details. – dcarlson Aug 08 '19 at 03:20