I'm trying to predict GDP per capita from about 50 variables, and the PCA shows that the two principal components explain about 40% of the variance. But I want it to show how much of the variance in GDP per capita specifically, it explains. Because when I graph GDP per capita against predicted using the first two principal components, I get an R^2 of about 90%.
When I try setting up my PCA on R, I don't know how to specify that the point of this is to explain variation in GDP per capita (not the other variables.)
pca <- prcomp(allexceptgdppc, center = TRUE, scale = TRUE)
zpca <- predict(pca, all)
Maybe I need to specify the variable GDP per capita, instead of all, but it says I must use a dataframe.
Any help would be amazing, thanks so much.