0
$\begingroup$

I have done all my principal component analysis and have my principal components (PC1 & PC2) and I know I have to multiply that by my original data set to get my new reduced data set, but I keep getting an error 'Error in Fish %*% FishPC : requires numeric/complex matrix/vector arguments'

My data set is called Fish and my Principal component matrix is FishPC My code is Fish %*% FishPC. I can provide more if needed.

Data Set Principal Component My principal component matrix

Dataset My dataset

I have tried removing the species and that also did not work.

$\endgroup$
0
$\begingroup$

You can try

Y <- as.matrix(Fish[,2:7],nrow=nrow(Fish),ncol=6)%*%as.matrix(FishPC,nrow=6,ncol=2)

However, be aware of how the PCs were computed. PCA is often performed on data that has been centered and sometimes scaled. If that is the case for your PCs, then you should also center and/or scale Fish as appropriate.

$\endgroup$
  • $\begingroup$ Unfortunately that didn't work, same error. The matrix is the right dimensions [158x6] X [6x2] so it should return a [158x2] matrix. $\endgroup$ – Hariboharry Jan 13 at 22:16
  • $\begingroup$ I think I figured it out, the matrix Fish was classed as a character matrix not a numerical one despite only having numbers in because it came from a mixed matrix. $\endgroup$ – Hariboharry Jan 13 at 22:19
  • $\begingroup$ Ah gotcha, that'll do it! Be careful about whether you need to center and/or scale, though -- PCA is almost always done on centered data (most functions will do this automatically to inputted data), so you may need to center and/or scale your input matrix Fish to get the results you expect. $\endgroup$ – Izzy Jan 14 at 3:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.