4

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)?

amoeba
  • 93,463
  • 28
  • 275
  • 317
user46759
  • 51
  • 1
  • 4
  • 2
    Requests for where to find code might be argued not to be directly [on topic](http://stats.stackexchange.com/help/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. – Glen_b Jun 05 '14 at 08:57
  • 1
    This question appears to be off-topic because it is about a request for code. – Nick Cox Jun 05 '14 at 09:41
  • @NickCox: no because it's a *statistical* code and presumably statisticians are best placed to answer. Please stop this attitude of systematically sending programmers away. It's deeming half the fun of doing stats! – user603 Jun 05 '14 at 13:10
  • 2
    @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. – whuber Jun 05 '14 at 13:14
  • @user603 Please consider the explicit policy at http://stats.stackexchange.com/help/on-topic and how far the _original_ question matched that. Also, if you want to discuss the principles or change the policy, use Meta. Finally, your reputation, like mine, entitles you to a vote on this; in a mature democracy people should be able to disagree through their votes without rancour. (Most of my activity in statistical science is computational, so I have zero bias against programming.) (I totally agree with whuber above who as usual puts his finger on the key point.) – Nick Cox Jun 05 '14 at 17:19
  • 1
    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. – Nick Cox Jun 06 '14 at 11:04
  • 1
    @NickCox: Sorry, I can see my comments was the source of a miss-understanding. I apologize. The second and third sentences were not meant to address any one user. In general, I think we should edit these kinds of questions (in the way whuber suggested) ourselves rather than closing them. It's because I think people need more help with formulating a stat question than a programming one (not fair to our community but that's the way I perceive it). – user603 Jun 06 '14 at 12:41
  • 2
    @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. – Nick Cox Jun 06 '14 at 12:47

2 Answers2

5

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.

Deathkill14
  • 2,140
  • 10
  • 17
1

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.

Stephan Kolassa
  • 95,027
  • 13
  • 197
  • 357
  • 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. – user46759 Jun 07 '14 at 07:16