3
$\begingroup$

Does anyone know where I can find an algorithm, as well as an R implementation of it, to carry out sparse principal component analysis (PCA)?

$\endgroup$
  • 2
    $\begingroup$ Requests for where to find code might be argued not to be directly on topic. At that link, see the list of topics and the section headed There are certain subjects that will probably get better responses on our sister sites. and see if you can either edit your post to make it more clearly on topic, or whether there might be a better location for the question. $\endgroup$ – Glen_b Jun 5 '14 at 8:57
  • 1
    $\begingroup$ This question appears to be off-topic because it is about a request for code. $\endgroup$ – Nick Cox Jun 5 '14 at 9:41
  • 2
    $\begingroup$ @user603 I agree with you in general that we do not want to send programmers away as a policy. The problem here is that the question explicitly asks just for R code. If it were changed to request an algorithm I think there would be no controversy. $\endgroup$ – whuber Jun 5 '14 at 13:14
  • 1
    $\begingroup$ For the record, the original version was closed after votes by 4 people, 1 being me. It was then revised and re-opened. It's inaccurate therefore to direct disagreement at me personally; I merely voiced the doubt in the comment above. $\endgroup$ – Nick Cox Jun 6 '14 at 11:04
  • 2
    $\begingroup$ @user603 Thanks for your comment; I take no offence; I was just underlining facts. I don't know about "in general": in my experience, most poor questions shouldn't be edited to a different question because a good underlying question cannot be identified. But in this case you did edit the question to an acceptable one. Whether it was the OP's real question remains unclear. A side-effect of the edit is that neither of the two up-voted answers, both posted before your edit, really answers the question as it stands! Oh well. $\endgroup$ – Nick Cox Jun 6 '14 at 12:47
4
$\begingroup$

Another good package is the elasticnet package that Zou and Hastie put out. It has the function spca.

Be careful to select a good value of $\lambda$, the sparsity parameter (or vector of them).

I would be curious to know which package ends up working better for you since the other package mentioned by @Stephan Kolassa is a year newer and is by Hastie's coauthor, Tibshirani.

$\endgroup$
1
$\begingroup$

Which function in which package are you interested in? All code is available on CRAN. For instance, if you are thinking about the PMA package (just the first one I found by googling for "CRAN Sparse Principal Components Analysis"), you can find the source code here.

$\endgroup$
  • $\begingroup$ Thank you very much for your useful answer.I want to use general form of lasso which elasticnet to select a group of highly correlated variables.if you have any idea which is better please tell me your opinion. $\endgroup$ – user46759 Jun 7 '14 at 7:16

Your Answer

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.