'How to project a new data row onto PCA space using dudi.mix in R?
I have a mixed dataset (comprising continuous, ordinal and nominal variables) that is high-dimensional (with more variables than rows). I want to perform a mixed data PCA using the dudi.mix()
function in the R package ade4
. After PCA, I want to project a new supplementary row onto the PCA space, i.e. find its coordinates in the PCA coordinate system. I tried the suprow()
function in ade4
but it gives me the following error message: “Not yet implemented for 'dudi.mix'. Please use 'dudi.hillsmith'.”
I don’t want to use the dudi.hillsmith()
function because I think it only allows for mixed continuous and nominal variables, but my dataset comprises continuous, nominal and ordinal variables, and my understanding is that dudi.mix()
is the correct function to use in this case.
Is there an alternative way how I can project a new row onto the PCA space generated by dudi.mix()
?
Below an example:
# load ade4 package
library(ade4)
# a high-dimensional mixed dataset with 11 rows and 13 variables
dat <- data.frame(
a=as.numeric(c(2.5,0.5,2.2,1.9,3.1,2.3,2.0,1.0,1.5,1.1,3.4)),
b=as.numeric(c(2.4,0.7,2.9,2.2,3.0,2.7,1.6,1.1,1.6,0.9,3.1)),
c=as.numeric(c(1.3,1.1,2.4,3.1,2.2,1.3,1.5,1.8,1.1,0.5,3.8)),
d=as.numeric(c(1.9,0.9,2.1,2.3,2.8,1.9,1.9,1.3,2.9,0.8,2.9)),
e=as.numeric(c(2.2,1.2,2.5,2.9,1.9,3.1,2.1,0.9,1.8,0.9,2.8)),
f=as.factor(c(0,0,0,0,1,0,1,1,1,0,1)),
g=as.factor(c(0,1,0,0,1,0,1,0,1,0,0)),
h=as.factor(c(1,1,1,1,0,1,0,0,0,1,1)),
i=as.factor(c(1,0,0,0,0,1,0,1,0,0,0)),
j=as.ordered(c(0,1,0,2,3,4,0,1,2,4,2)),
k=as.ordered(c(1,2,1,3,4,4,1,2,2,3,3)),
l=as.ordered(c(0,1,1,2,3,2,0,1,1,3,1)),
m=as.ordered(c(0,0,1,2,1,2,2,1,0,2,1)))
# first 10 rows are used for PCA
dat.1 <- dat[1:10,]
# the 11s row should be projected onto the PCA space
dat.2 <- dat[11,]
# pca on dat.1 with 9 kept axes (i.e. number of rows - 1)
pca.res <- dudi.mix(df=dat.1, scann=FALSE, nf = 9)
# my attempt to project dat.2 onto pca.res fails
suprow(x=pca.res, Xsup=dat.2)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|