0
$\begingroup$

For a class project, my group and I are looking to play around with PCR since we didn't get a chance to dive into much details in class. We were going to look at a few different ways to select the principal components used in PCR beyond the default way R does. One of these that we wanted to look at was just a couple random samples, and seeing how they compare to the default R method. However, I can't find anything in tutorials or the R functions for pcr that let you specify the components themselves - only the number of components used (Right now I'm mainly using the pcr function from the pls package). Is there any package or function that will allow me to specify the components, or will I have to make my own function?

Thank you!

$\endgroup$
  • 1
    $\begingroup$ What different ways did you have in mind? It's not clear to me if you want to select particular PCs to explore, or if you want to make different linear combinations (which wouldn't really be PCs then). $\endgroup$ – Aaron - Reinstate Monica Apr 29 at 1:53
0
$\begingroup$

The best way that I'm aware of is to apply the standard linear model function against the selected PCA scores. See example below, assuming your independent variables are held in data and dependent variable is found in yVector, and z is the number of columns you want to sample.

pca <- princomp( ~ ., data=data, cor=T)
sample <- pca$scores[, sample(ncol(pca$scores), z)])
combined <- data.frame(Y=yVector, sample)
pcrModel <- lm(Y~., data=combined) 
$\endgroup$

Your Answer

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

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