I'm using Dr Frank Harrell's code in RMS 2nd edition. He goes into sparse PCA. Does anyone know how to code a regression model after getting the sparse component grid?
require(pcaPP)
s <- sPCAgrid(ptrans$transformed, k=10, method="sd", center=mean,
scale=sd, scores=TRUE, maxiter=10)
plot(s, type="lines", main="", ylim=c(0,3)) # Figure 8.6
addscree(s)
s$loadings
pcs <- s$scores # pick off sparse PCs
aic <- numeric(10)
for(i in 1:10) {
ps <- pcs[,1:i]
aic[i] <- AIC(cph(S ~ ps))
} # Figure 8.7
plot(1:10, aic, xlab= 'Number of Components Used ',
ylab='AIC', type='l', ylim=c(3950,4000))