2
$\begingroup$

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))
New contributor
A_cor is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$

1 Answer 1

0
$\begingroup$

The answer is in the code that you present, in particular, the following function call:

cph(S ~ ps)

that fits a Cox proportional hazards model for survival outcomes S against a set of sparse PCA scores called ps. You can do the same for any type of regression.

Earlier code shows where that predictor ps comes from.

pcs <- s$scores # pick off sparse PCs

with ps just a subset of pcs:

for(i in 1:10) {
  ps <- pcs[,1:i]
  aic[i] <- AIC(cph(S ~ ps))
} 
$\endgroup$

Your Answer

A_cor is a new contributor. Be nice, and check out our Code of Conduct.

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.