Skip to content

Instantly share code, notes, and snippets.

@mbannert
Created November 6, 2015 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbannert/d0863cf8a98f758a5bc8 to your computer and use it in GitHub Desktop.
Save mbannert/d0863cf8a98f758a5bc8 to your computer and use it in GitHub Desktop.
made up example list wise PCA with AIC
# just an implementation example that does not make a whole lot of sense...
library(MASS)
y <- mtcars$mpg
ll <- list(cars1 = mtcars[,-1], cars2 = mtcars[,-1]*100)
out_put_list <- lapply(ll,function(x){
pca <- prcomp(x,scale.=T)
pca_scores <- as.data.frame(pca$x)
# maybe give back the result and do it
# multiple dfs
fit1 <- lm(y ~ .,data =pca_scores)
best_model <- stepAIC(fit1)
best_model
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment