I have a bit mathematical question I am interested in. Principal component analysis (PCA) has mathematically multiple solutions. One way is to use SVD.

I have prepared an example bellow. I am curious when I plot U matrix observations relative positions are exactly the same relatively to each other. However when we use prcom function that thas PCA analysis and we use X matrix.

We can see that observation positions on PC1 and PC2 low-dimmensional space are (relatively) the same as with U matrix in SVD. Only different thing is scalling.

I now that to obtain the same values as in the X matrix from prcom function we need to get matrix product of (Centered) observation and VT matrix from SVD.

My question is if this step product of C and VT is really necessary taking into account that observations relative position is the same.


# Loading The Data
X <- as.data.frame(datasets::USArrests)

# Centering the data - Z-standardization
C <- t(t(X) - colMeans(X))
C <- t(t(C) / colSds(C))

SVD_REs <- svd(C)

V <- 
  SVD_REs %>% 
  broom::tidy(matrix = 'v') %>% 
  pivot_wider(names_from = PC,
              values_from = value,
              names_prefix = 'PC') %>% 
  mutate(column = colnames(X)[column])

U <- 
  SVD_REs %>% 
  broom::tidy(matrix = 'u') %>% 
  pivot_wider(names_from = PC,
              values_from = value,
              names_prefix = 'PC') %>% 
  mutate(row = rownames(X)[row])

U %>% 
  ggplot(aes(PC1, PC2, label  = row)) + 
  geom_point() + 

# NOW USE PCA build-in function
PCA_FUN <- prcomp(X, center = T, scale. = T)

# Their relative possition is Same as in U matrix. However, scaling is different
PCA_FUN$x %>% 
  as.data.frame() %>% 
  ggplot(aes(PC1, PC2, label = rownames(.))) + 
  geom_point() + 

  • $\begingroup$ Could you please tell us what "C" refers to and what a "step product" might be? $\endgroup$ – whuber Nov 6 '20 at 15:49
  • $\begingroup$ C is centered Data matrix. and step product should have been written matrix multiplication. $\endgroup$ – Petr Nov 6 '20 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.