Supplementary Observations, Variables or Groups

Marie Chavent

2017-10-20

library(PCAmixdata)

Supplementary variables and groups

In PCAmix

data(wine)
X.quanti <- splitmix(wine)$X.quanti[,1:5]
X.quali <- splitmix(wine)$X.quali[,1,drop=FALSE]
X.quanti.sup <-splitmix(wine)$X.quanti[,28:29]
X.quali.sup <-splitmix(wine)$X.quali[,2,drop=FALSE]
pca<-PCAmix(X.quanti,X.quali,ndim=4,graph=FALSE)
pca2 <- supvar(pca,X.quanti.sup,X.quali.sup)
plot(pca2,choice="levels")

plot(pca2,choice="cor")

plot(pca2,choice="sqload")

In MFAmix

data(wine)
X.quanti <- splitmix(wine)$X.quanti[,1:5]
X.quali <- splitmix(wine)$X.quali[,1,drop=FALSE]
X.quanti.sup <- splitmix(wine)$X.quanti[,28:29]
X.quali.sup <- splitmix(wine)$X.quali[,2,drop=FALSE]
data <- cbind(X.quanti,X.quali)
data.sup <- cbind(X.quanti.sup,X.quali.sup)

groups <-c(1,2,2,3,3,1)
name.groups <- c("G1","G2","G3")
mfa <- MFAmix(data,groups,name.groups,ndim=4,rename.level=TRUE,graph=FALSE)


groups.sup <- c(1,1,2)
name.groups.sup <- c("Gsup1","Gsup2")
mfa.sup <- supvar(mfa,data.sup,groups.sup,name.groups.sup,rename.level=TRUE)
plot(mfa.sup,choice="sqload",coloring.var="groups")

plot(mfa.sup,choice="axes",coloring.var="groups")

plot(mfa.sup,choice="groups",coloring.var="groups")

plot(mfa.sup,choice="levels",coloring.var="groups")

plot(mfa.sup,choice="levels")

plot(mfa.sup,choice="cor",coloring.var = "groups")

Case of a single group

#devtools::install_github("chavent/PCAmixdata")
library(PCAmixdata)
data(wine)
X.quanti <- splitmix(wine)$X.quanti[,1:5]
X.quali <- splitmix(wine)$X.quali[,1,drop=FALSE]
X.quali.sup <- splitmix(wine)$X.quali[,2,drop=FALSE]
data <- cbind(X.quanti,X.quali)

groups <-c(1,1,1,2,2,2)
name.groups <- c("G1","G2")
mfa <- MFAmix(data,groups,name.groups,ndim=4,rename.level=TRUE,graph=FALSE)

groups.sup <- c(1)
name.groups.sup <- "Gsup1"
mfa.sup <- supvar(mfa,X.quali.sup,groups.sup,name.groups.sup,rename.level=TRUE)
plot(mfa.sup,choice="levels",coloring.var = "groups")

groups.sup <- c(1,1,2)
name.groups.sup <- c("Gsup1","Gsup2")
mfa.sup <- supvar(mfa,data.sup,groups.sup,name.groups.sup,rename.level=TRUE)
plot(mfa.sup,choice="sqload",coloring.var="groups")

plot(mfa.sup,choice="axes",coloring.var="groups")

plot(mfa.sup,choice="groups",coloring.var="groups")

plot(mfa.sup,choice="levels",coloring.var="groups")

plot(mfa.sup,choice="levels")

plot(mfa.sup,choice="cor",coloring.var = "groups")

New observations.

In PCAmix

data(wine)
X.quanti <- splitmix(wine)$X.quanti[,1:5]
X.quali <- splitmix(wine)$X.quali
n <- nrow(wine)
sub <- sample(1:n,10)
pca<-PCAmix(X.quanti[sub,],X.quali[sub,],ndim=4,graph=FALSE)
pred <- predict(pca,X.quanti[-sub,],X.quali[-sub,])
plot(pca,axes=c(1,2))
points(pred[,c(1,2)],col=2,pch=16)
text(pred[,c(1,2)], labels = rownames(X.quanti[-sub,1:5]), col=2,pos=3)