annotate PCA.R @ 9:2e8c9032e8d8 draft

Uploaded
author mb2013
date Tue, 20 May 2014 03:27:01 -0400
parents 5aaede6275f9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
1 # The tool PCA creates a Principal Component Analysis on Procrustes coordinates.
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
2 # MB
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
3
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
4 #commands of commandline
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
5 args <- commandArgs(TRUE)
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
6 #input file: procrustes coordinates
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
7 input <- args[1]
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
8 #output file
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
9 output <- args[2]
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
10 output2 <- args[3]
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
11
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
12 #package geomorph
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
13 suppressMessages(library("geomorph"))
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
14
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
15 #reading of coordinates
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
16 read <- read.csv(file <- input,header = TRUE)
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
17 #principal component analysis with princomp, using covariance matrix of coordinates
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
18 pca <- princomp(x=cov(read))
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
19
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
20 #output pca scores
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
21 write.csv(pca$scores,output, row.names = FALSE)
5aaede6275f9 Uploaded
mb2013
parents:
diff changeset
22 write.csv(pca$sdev, output2, row.names = FALSE)