Carlos Guerra
2006-Nov-16 11:08 UTC
[R] Problems with principal components analysis PCA with prcomp
Dear friends, I am beginning to use R software in my academic research and I'm having some problems regarding the use of PCA. I have a table with 24445 rows and 9 columns, and I used the function prcomp() to do the analysis. Working with an example?: x<-read.table("test.txt", header=T) row.names(x)<-x[,1] x<-x[,-1] require(stats) pca<-prcomp(x, scale=T) names(pca) ## here begin my problems? know what???## My questions are: 1. How can I group my samples (rows) in a graphical way? 2. How can I extract the samples related to each group? ?or? How can I create a new column with "n" values corresponding to each group created? 3. Is it possible to extract/export the information in an object into a file with a dbf extension (e.g. test.dbf)? Best regards, Carlos +++++++++++++++++++++++++++++++ Carlos GUERRA Instituto Polit?cnico de Viana do Castelo Escola Superior Agr?ria de Ponte de Lima Mosteiro de Ref?ios do Lima 4990-706 Ponte de Lima PORTUGAL MAIL: carlosguerra at esa.ipvc.pt TEL: +351 912 407 109 +++++++++++++++++++++++++++++++ -------------- next part -------------- FID ALTIM TEMP CLI FAS 0 14 4 1 2 1 65 1 1 3 2 54 1 7 1 3 112 1 5 1 4 117 4 2 1 5 180 2 1 2 6 54 4 1 3 7 125 4 1 2 8 217 4 2 2 9 171 3 2 2 10 37 4 3 3 11 114 2 4 3 12 229 4 4 3 13 286 3 3 3 14 227 3 5 3 15 16 4 5 2 16 74 4 5 2 17 89 4 6 1 18 98 2 5 1 19 64 2 4 2 20 96 2 6 1 21 100 4 6 3 22 147 4 7 1 23 196 4 7 3 24 282 3 1 3 25 308 3 1 3
Sarah Goslee
2006-Nov-16 14:09 UTC
[R] Problems with principal components analysis PCA with prcomp
Hello Carlos, # let me save you a couple steps here> x<-read.table("test.txt", header=T, row.names=1)> pca<-prcomp(x, scale=T) > names(pca) > > ## here begin my problems? know what???##Try this for a graphical view of your data: biplot(pca) You might also want to work through the examples given in ?prcomp and ?princomp.> My questions are: > 1. How can I group my samples (rows) in a graphical way? > 2. How can I extract the samples related to each group? ?or? How can I > create a new column with "n" values corresponding to each group created?Here I see a problem... if you are interested in _groups_ in the data, you might be better off with a clustering method, of which R has an abundance. Ordination is generally about _gradients_ rather than groups - continuous change vs discrete groups. If you are determined to divide your ordination into groups, one possibility is to use conditional subsetting on the ordination values.> 3. Is it possible to extract/export the information in an object into a file > with a dbf extension (e.g. test.dbf)?help.search(dbf) finds the function write.dbf - sounds suspiciously useful. Sarah -- Sarah Goslee http://www.functionaldiversity.org