Error In Int_Abline While Doing Pca Using R
1
0
Entering edit mode
10.9 years ago
grosy ▴ 100

I have a 12X8 dataset for doing PCA.

And I am using the following code:

bumpus <- read.csv("pca.csv", header=TRUE)
bumpus <- bumpus[,-1]
boxplot(bumpus, main="Boxplot of Bumpus' data")

# we first standardize the data:
bumpus.scaled <- data.frame( apply(bumpus,2,scale) )
boxplot(bumpus.scaled, main="Boxplot of standardized Bumpus' data")

pca.res <- prcomp(bumpus.scaled, retx=TRUE)
pca.res

# note:
# PC.1 is some kind of average of all the measurements 
#    => measure of size of the bird
# PC.2 has a negative weight for 'sternum' 
#    and positive weights for 'alar', 'head' and 'humerus'
#    => measure of shape of the bird

# first two principal components:
pca.res$x[,1:2]
plot(pca.res$x[,1:2], pch="", main="PC.1 and PC.2 for Bumpus' data (blue=survived, red=died)")
text(pca.res$x[,1:2], labels=c(1:49), col=c(rep("blue",21),rep("red",28)))
abline(v=0, lty=2)
abline(h=0, lty=2)

# compare to segment plot:
windows()
palette(rainbow(12, s = 0.6, v = 0.75)) 
stars(bumpus, labels=c(1:49), nrow=6, key.loc=c(20,-1), 
      main="Segment plot of Bumpus' data", draw.segment=TRUE) 

# compare to biplot:
windows()
biplot(pca.res, scale=0)
# what do the arrows mean?
# consider the arrow for sternum:
abline(0, pca.res$rotation[5,2]/pca.res$rotation[5,1])
# consider the arrow for head:
abline(0, pca.res$rotation[3,2]/pca.res$rotation[3,1])

Second line from last (abline(0, pca.res$rotation[5,2]/pca.res$rotation[5,1])) shows an error

Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) : 
  subscript out of bounds

The dataset looks like this

DATASET

Could anyone please tell me how to rectify this error?

Please Help!

pca r • 3.6k views
ADD COMMENT
2
Entering edit mode
10.9 years ago
Pavel Senin ★ 1.9k

In fact, everything works in your code, when I change the data (I can't read the picture into ;-) )

bumpus <- data.frame(matrix(rnorm(8*11),byrow=T,ncol=8))
names(bumpus)=c("A","R","N","D","C","E","Q","G")
boxplot(bumpus, main="Boxplot of Bumpus' data")
`

but, you may want to set options(error=recover) in R to figure out where you are trying to access an array out of its boundary

Here is the plot with rnorm and your code:

enter image description here

ADD COMMENT

Login before adding your answer.

Traffic: 2161 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6