もうひとつの主成分分析用ライブラリamap

Rで主成分分析を行うにはprincompやprcomnpの関数があらかじめ用意されているが
これでは物足りないなどの不満がある(変量の数が多いなど)場合は以下のように
因子負荷量をちゃんと計算する関数を提供しているサイトもある。
http://aoki2.si.gunma-u.ac.jp/R/princomp2.html(有名な青木先生のサイト)
その他にはないか見てみるとamap (Another Multidimensional Analysis Package)と
いうのもあるようだ。そこで今回はこのamapのインストールに試みることにした。
以下のようにrootになってからinstall.packages関数を使って

[user@machineA ~/pca]$ su
Password:
[root@machineA]/home/user/pca# R

R version 2.4.1 (2006-12-18)
Copyright (C) 2006 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

Rはフリーソフトウェアであり、「完全に無保証」です。
一定の条件に従えば、自由にこれを再配布することができます。
配布条件の詳細に関しては、'license()'あるいは'licence()'と入力してください。

Rは多くの貢献者による共同プロジェクトです。
詳しくは'contributors()'と入力してください。
また、RやRのパッケージを出版物で引用する際の形式については
'citation()'と入力してください。

'demo()'と入力すればデモをみることができます。
'help()'とすればオンラインヘルプが出ます。
'help.start()'でHTMLブラウザによるヘルプがみられます。
'q()'と入力すればRを終了します。

> install.packages("amap",dep=T)

      • Please select a CRAN mirror for use in this session ---

CRAN mirror

1: Argentina 2: Australia
3: Austria 4: Belgium
5: Brazil (PR) 6: Brazil (RJ)
7: Brazil (SP 1) 8: Brazil (SP 2)
9: Canada (BC) 10: Canada (ON)
11: Chile (Santiago) 12: Croatia
13: Czech Republic 14: Denmark
15: France (Toulouse) 16: France (Paris)
17: Germany (Goettingen) 18: Germany (Muenchen)
19: India 20: Ireland
21: Italy (Milano) 22: Italy (Padua)
23: Italy (Palermo) 24: Japan (Aizu)
25: Japan (Tokyo) 26: Japan (Tsukuba)
27: Korea 28: Mexico
29: Netherlands (Amsterdam 2) 30: Netherlands (Amsterdam)
31: Netherlands (Utrecht) 32: New Zealand
33: Norway 34: Poland (Oswiecim)
35: Poland (Wroclaw) 36: Portugal
37: Slovenia (Ljubljana) 38: South Africa
39: Spain (Madrid) 40: Sweden
41: Switzerland 42: Taiwan (Taichung)
43: Taiwan (Taipeh) 44: Thailand
45: UK (Bristol) 46: USA (CA 1)
47: USA (CA 3) 48: USA (IA)
49: USA (MI) 50: USA (MO)
51: USA (NC) 52: USA (PA 2)
53: USA (PA) 54: USA (WA)


選択:25
URL 'ftp://ftp.ecc.u-tokyo.ac.jp/CRAN/src/contrib/amap_0.8-2.tar.gz' を試して
います
ftp data connection made, file length 127361 bytes
開かれた URL
==================================================
downloaded 124Kb

*1210521241* Installing *source* package 'amap' ...
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for pthread_create in -lpthread... yes
configure: creating ./config.status
config.status: creating src/Makevars
** libs
gcc -std=gnu99 -I/usr/local/lib64/R/include -I/usr/local/lib64/R/include

  • I/usr/local/include/ -Wno-conversion -I/usr/local/include -fpic -g -O2
  • c acprob.c -o acprob.o

gcc -std=gnu99 -I/usr/local/lib64/R/include -I/usr/local/lib64/R/include

  • I/usr/local/include/ -Wno-conversion -I/usr/local/include -fpic -g -O2
  • c burt.c -o burt.o

gcc -std=gnu99 -I/usr/local/lib64/R/include -I/usr/local/lib64/R/include

  • I/usr/local/include/ -Wno-conversion -I/usr/local/include -fpic -g -O2
  • c diss.c -o diss.o

g++ -I/usr/local/lib64/R/include -I/usr/local/lib64/R/include

  • I/usr/local/include/ -Wno-conversion -I/usr/local/include -fpic -g -O2
  • c distance.cpp -o distance.o

g++ -I/usr/local/lib64/R/include -I/usr/local/lib64/R/include

  • I/usr/local/include/ -Wno-conversion -I/usr/local/include -fpic -g -O2
  • c distance_T.cpp -o distance_T.o

g++ -I/usr/local/lib64/R/include -I/usr/local/lib64/R/include

  • I/usr/local/include/ -Wno-conversion -I/usr/local/include -fpic -g -O2
  • c hclust.cpp -o hclust.o

g++ -I/usr/local/lib64/R/include -I/usr/local/lib64/R/include

  • I/usr/local/include/ -Wno-conversion -I/usr/local/include -fpic -g -O2
  • c hclust_T.cpp -o hclust_T.o

g++ -I/usr/local/lib64/R/include -I/usr/local/lib64/R/include

  • I/usr/local/include/ -Wno-conversion -I/usr/local/include -fpic -g -O2
  • c kmeans.cpp -o kmeans.o

g77 -fpic -g -O2 -c pop.f -o pop.o
g++ -shared -L/usr/local/lib64 -o amap.so acprob.o burt.o diss.o distance.o
distance_T.o hclust.o hclust_T.o kmeans.o pop.o -lpthread -lg2c -lm -lgcc_s
** R
** data
** demo
** exec
** inst
** help
>>> Building/Updating help pages for package 'amap'
Formats: text html latex example
Kmeans text html latex example
acp text html latex example
acpgen text html latex example
acprob text html latex
afc text html latex example
burt text html latex example
diss text html latex example
dist text html latex example
hcluster text html latex example
lubisch text html latex
plot.acp text html latex example
pop text html latex example
varrob text html latex
** building package indices ...
*1210521242* DONE (amap)

The downloaded packages are in
/tmp/RtmpDzSl33/downloaded_packages
> q()
Save workspace image? [y/n/c]: y
[root@machineA]/home/user/pca# exit

では、インストールしたので早速使ってみよう。
まずはヘルプを参照して

[user@machineA~/pca]$ R

R version 2.4.1 (2006-12-18)
Copyright (C) 2006 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

Rはフリーソフトウェアであり、「完全に無保証」です。
一定の条件に従えば、自由にこれを再配布することができます。
配布条件の詳細に関しては、'license()'あるいは'licence()'と入力してください。

Rは多くの貢献者による共同プロジェクトです。
詳しくは'contributors()'と入力してください。
また、RやRのパッケージを出版物で引用する際の形式については
'citation()'と入力してください。

'demo()'と入力すればデモをみることができます。
'help()'とすればオンラインヘルプが出ます。
'help.start()'でHTMLブラウザによるヘルプがみられます。
'q()'と入力すればRを終了します。

> library(help=amap)

パッケージ 'amap' の情報

記述:

Package: amap
Version: 0.8-2
Date: 2007-10-03
Suggests: Biobase
Title: Another Multidimensional Analysis Package
Author: Antoine Lucas
Maintainer: Antoine Lucas
Description: Tools for Clustering and Principal Component Analysis
(With robusts methods, and parallelized functions).
License: GPL
URL: http://mulcyber.toulouse.inra.fr/projects/amap/
Packaged: Wed Oct 3 19:42:11 2007; antoine
Built: R 2.4.1; x86_64-unknown-linux-gnu; 2008-05-10 20:15:30;
unix

索引:

acp Principal component analysis
acpgen Generalised principal component analysis
acprob Robust principal component analysis
afc Correspondance factorial analysis.
burt Compute burt table from a factor dataframe.
diss Compute a dissimilarity matrix
Dist Distance Matrix Computation
hcluster Hierarchical Clustering
Kmeans K-Means Clustering
lubisch Dataset Lubischew
plot.acp Graphics for Principal component Analysis
pop Optimal Partition (classification).
varrob Robust variance

これ以上の情報はディレクトリ '/usr/local/lib64/R/library/amap/doc'
にある以下の vignettes 中にあります:

amap: Introduction to amap (source, pdf)

よし、acpをやってみて、第一主成分・第二主成分でグラフ化してみよう。

> acp(samp) -> samp_result
> plot.acp(samp_result)

うむ。。。、まあ一応できたけど。これでいいんかな?