Using weight column in PCA analysis with R

1.4k views Asked by At

I have a column in my data file which corresponds to weight of individuals. The data looks like

> library(FactoMineR)
> mydata <- read.csv('test.csv', header=T,row.names=1)
> mydata
       V1 V2 V3   WG 
P1.K1 218 30 10 1.00 
P2.K1 218 23 15 0.10  
P2.K2  30 32 17 0.88 
P2.K3   5 12 14 0.02 

When I use the following command,

> res.pca <- PCA(mydata)

It uses the WG column as an active variable as can be seen in the figure below.

enter image description here

On the other hand, if I use

> res.pca <- PCA(mydata, quanti.sup=4)

I still see WG in the graph of variables.

enter image description here

I want to exclude that in the PCA analysis as an active variable. Instead I want to use that as weight for each row. So, the weight of P1.K1 is 1 while the weight of P2.K2 is 0.88. How can I do that?

1

There are 1 answers

0
kangaroo_cliff On

PCA in FactoMineR has an option to provide row weights. I think what you are after is the folowwing.

res.pca <- PCA(mydata[, 1:3], row.w = mydata[, 4])