[adegenet-forum] plot.spca:\screeplot.spca Error in FUN(newX[, i], ...) : object lengths differ

Jombart, Thibaut t.jombart at imperial.ac.uk
Thu May 20 11:35:52 CEST 2010


Dear Nevil, 

the error comes from the fact that the genind object which was used to perform a sPCA needs be present in the workspace when summary.spca is called (itself called when doing a screeplot of spca objects). The printing of mygenindSPCA reads:

> mygenindSPCA
	########################################
	# spatial Principal Component Analysis #
	########################################
class: spca
$call: spca(obj = get(i), scannf = F, nfposi = 1, nfnega = 1, type = 1, 
    ask = F)

$nfposi: 1 axis-components saved
$nfnega: 1 axis-components saved

...

so the object sought is get(i), and i is :
> i
[1] "mygenind1"

So that is the wrong object. In you 'for' loop, make sure to reset 'i' so that the right object is used at each iteration. For instance:
i <- "mygenind"
screeplot(mygenindSPCA)

works.

Cheers

Thibaut. 


--
######################################
Dr Thibaut JOMBART
MRC Centre for Outbreak Analysis and Modelling
Department of Infectious Disease Epidemiology
Imperial College - Faculty of Medicine
St Mary’s Campus
Norfolk Place
London W2 1PG
United Kingdom
Tel. : 0044 (0)20 7594 3658
t.jombart at imperial.ac.uk
http://sites.google.com/site/thibautjombart/
http://adegenet.r-forge.r-project.org/

________________________________________
From: adegenet-forum-bounces at lists.r-forge.r-project.org [adegenet-forum-bounces at lists.r-forge.r-project.org] On Behalf Of Nevil Amos [nevil.amos at gmail.com]
Sent: 19 May 2010 16:37
To: adegenet-forum at lists.r-forge.r-project.org
Subject: [adegenet-forum] plot.spca:\screeplot.spca Error in FUN(newX[, i], ...) : object lengths differ

I am getting the following error for some of my data, I cannot trace the
inconsistency in the two data-sets, I have attached  a workspace
containing two datasets ( mydata1 and mydata2) used to construct genind
objects, then spca and plot the spca and below is the code to do this
automatically (plots output to pdf, but error occurs when plotting to
screen too, one works OK and the other does not  the  error results in a
failure to produce the screeplot.  I have a large number of datasets to
examine and many are showing this error, any indication of where to look
to correct the error would be appreciated.

If I na.omit(mydata) I get the following additonal warning:

In addition: Warning messages:
1: Chernobyl! trL>n 729.34
2: Chernobyl! trL>n 729.34
3: In sqrt(sum.squares/one.delta) : NaNs produced

Nevil Amos


#Formats data to genind
mydata <- mydata[order(mydata$Site_Name) , ]
n<-ncol(mydata)
geno=mydata[,c(9:n)]
Site=factor(mydata[,c(3)])
BirdID=mydata[,c(2)]
XY=mydata[,c(7:8)]
mygenind<-df2genind(geno, sep="/",
ind.names=BirdID,ncode=3,pop=Site,loc.names=NULL,   missing="NA",
ploidy=2, type=c("codom"))
mygenind at other$xy<-(jitter(as.matrix(XY),fac=2))

mydata1 <- mydata1[order(mydata1$Site_Name) , ]
n<-ncol(mydata1)
geno=mydata1[,c(9:n)]
Site=factor(mydata1[,c(3)])
BirdID=mydata1[,c(2)]
XY=mydata1[,c(7:8)]
mygenind1<-df2genind(geno, sep="/",
ind.names=BirdID,ncode=3,pop=Site,loc.names=NULL,   missing="NA",
ploidy=2, type=c("codom"))
mygenind1 at other$xy<-(jitter(as.matrix(XY),fac=2))

#gets list of genind objects from list of all objects
objno<-(grep(pattern="genind",ls()))
genindlist<-(ls()[objno])
rm(objno)
#runs spca on all and keeps pc1 and pc(last)
pdf("spca_plots.pdf",12,8)
for(i in genindlist){
     x<-spca(get(i),type=1,scannf=F,nfposi=1,nfnega=1,ask=F)
     nam=paste(i,"SPCA", sep="")
     assign(nam,x)
     rm(x)
     rm(nam)

}
#produces pdf containing plots for initial examination
rm(genindlist)
slist<-ls()[(grep(pattern="SPCA$",ls()))]
for (s in slist){
     #print (s)
     plot.spca(get(s))
     }
dev.off()


More information about the adegenet-forum mailing list