How to get first 8 components from PCA using pcromp package?

1k views Asked by At

I am implementing a PCA using prcomp.

pcaunemp <- prcomp(rawtChange,center = TRUE, scale=FALSE)

I am using the lm function for regression like so:

reg <- lm(tr[5:365,1] ~ tr[1:361,1] + tr[2:362,1] + tr[3:363,1] + tr[4:364,1])

If I want to only use the first 8 components as independent variables for a regression, how do I extract the components?

1

There are 1 answers

0
Thelonious Monk On BEST ANSWER

I can extract first 8 PCs with:

pcaunemp$x[, 1:8]

Credits to 李哲源 who answered in the comments