1
$\begingroup$

I need help with HOW principal components can be used like regular variables in linear and logistic regression in R.

I am analyzing a dataset which has 10 variables (including the outcome variable). Originally, I was predicting the outcome variable using different algorithms but the accuracy was not good enough, so I ran a PCA. This is my code for the PCA:

dummies <- dummyVars(" ~ .", data = trainset)
trainset_1 <- predict(dummies, newdata = trainset)
fit <- princomp(trainset_1, scores = TRUE, cor = T)
summary(fit)

I do not know how to use the principal components to predict my outcome in R Studio. My original code for multinomial logistic regression before the PCA for predicting was:

library(nnet)
REGmodel <- multinom(Outcome ~ ., data = trainset)
summary(REGmodel)

How can I modify the above code to use the variables from the principal component analysis to predict my outcome (which has 2 levels) in R Studio?

$\endgroup$

closed as off-topic by Michael Chernick, jbowman, Stephan Kolassa, mdewey, Silverfish Feb 22 '18 at 11:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Michael Chernick, jbowman, Stephan Kolassa, mdewey, Silverfish
If this question can be reworded to fit the rules in the help center, please edit the question.

3
$\begingroup$

I think you have some misunderstanding on what PCA is.

PCA is one of the "unsupervised methods", which means it explores the structures in data, but cannot be used to predict a outcome.

You can apply PCA to data to extract principle components. These principle components are some transformation of your original data and have some nice properties. However, we do not get any "prediction" out of it. (you may also noticed when apply PCA, we do not need to specify the response variable using R formula, right?)

I will make an analogy to conclude my answer. Think about a computer vision problem. Supervised methods can classify an image to a cat or dog. But PCA is just rotating and scaling the image.

$\endgroup$

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