[adegenet-forum] Error in spdep::lag.listw(listw, x, TRUE) : object lengths differ
Jombart, Thibaut
t.jombart at imperial.ac.uk
Wed May 5 17:19:00 CEST 2010
Dear Nevil,
thanks for this update. I'm afraid there were indeed inconsistencies in the data coding in the previous version of the dataset:
> head(geno)
BMC3 Cpi1 Cpi2 Cpi3 Cpi4 Cpi5 Cpi6 Cpi7 Cpi8 FT232 Pocc6
1 9393 222222 254254 130127 271271 233245 189192 162164 135137 196196 188188
2 9393 202212 246254 124126 271271 239241 189192 164166 135145 196196 188188
3 9193 216224 254254 124124 271271 237239 186192 164166 133133 196196 188188
4 9191 204220 254254 124127 271271 239247 186189 164166 133135 196196 188188
5 9193 204216 254254 124127 271271 237247 186192 166166 133135 196196 188188
6 9393 202202 254254 124124 271283 233245 189192 164164 133139 196198 188188
BMC3 used a 2-digits coding per allele, as opposed to 3 for other loci.
The new data are OK, but you're right assuming identical locations are a problem with Delaunay triangulation. In older versions of spdep I think I remember they issued a nasty segmentation fault. This is no longer the case, but there is still a fundamental problem using this type of graph with identical locations. I have just modified chooseCN (called upon by spca when no graph is provided) so as to handle duplicate coords better. Now, the function forces the choice of another type of graph in interactive mode (with an explanation), and issues an error in non-interactive mode.
So, in essence, it is normal to get an error in this case, but now the function will issue a meaningful error. Such issue has been tackled previously on this forum. You can access the relevant email by making a research on adegenet's website with "graph choice" as keywords (http://adegenet.r-forge.r-project.org/ - see section "contact").
I've uploaded the patch to chooseCN on the website. It should be available in a couple of hours.
Best
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: Nevil Amos [nevil.amos at gmail.com]
Sent: 05 May 2010 14:08
To: Jombart, Thibaut; adegenet-forum at lists.r-forge.r-project.org
Subject: Re: Error in spdep::lag.listw(listw, x, TRUE) : object lengths differ
Dear Thaibaut,
I have been through my data again, the -9 values that you identified
were an import error, - no data coding that someone else had been using.
I cannot now see any inconsistencies in my data, all alleles have 3
digit coding, I introduced a" / "separator alleles to make a final
visual check easier, and I also tried both the option of NA and "000"
coding for missing data. The dataset attached here is smaller, again to
enable me to be sure there are no errors left.
Nevertheless I still cannot get the type 1 CN to work within spca,
though it works from the same data source mygenind at other$xy( see the
paste of the whole process from the r console below.
I am using option 1 as the default effectively as I am unsure which
other options may be appropriate for my analysis. I have successfully
run the whole SPCA process with the datasets and type 4, or the smaller
dataset now attached and type 2 CN
The only thing I can think of is that multiple individuals may have the
same xy coordinates ( ie birds captured at the same location).
I have again attached the R script, workspace and this time a file of
the dataset used.
Thanks for your help,
and for providing the package in the first place!
Nevil Amos
> setwd("d:/nevs docs/rwork/test/")
> library (adegenet)
==========================
adegenet 1.2-3 is loaded
==========================
- to start, type '?adegenet'
- to browse adegenet website, type 'adegenetWeb()'
- to post questions/comments: adegenet-forum at lists.r-forge.r-project.org
> library (RODBC)
> mydata<-read.csv("mydata.csv")
> n<-ncol(mydata)
> geno=mydata[,c(7:n)]
> Site=factor(mydata[,c(3)])
> BirdID=mydata[,c(2)]
> XY=mydata[,c(5:6)]
> mygenind<-df2genind(geno, sep="/",
ind.names=BirdID,ncode=3,loc.names=NULL, missing="NA", ploidy=2,
type=c("codom")) #change line above to include populationon data
> mygenind at other$xy <-XY
> myspca<-spca(mygenind)
Attaching package: 'ade4'
The following object(s) are masked from package:base :
within
Loading required package: sp
Loading required package: boot
Attaching package: 'boot'
The following object(s) are masked from package:survival :
aml
Loading required package: Matrix
Loading required package: lattice
Attaching package: 'lattice'
The following object(s) are masked from package:boot :
melanoma
Loading required package: MASS
Loading required package: nlme
Loading required package: maptools
Loading required package: foreign
Loading required package: deldir
deldir 0.0-12
Please note: The process for determining duplicated points
has changed from that used in version 0.0-9 (and previously).
Loading required package: coda
Loading required package: spam
Package 'spam' is loaded. Spam version 0.20-3 (2010-01-13).
Type demo( spam) for some demos, help( Spam) for an overview
of this package.
Help for individual functions is optained by adding the
suffix '.spam' to the function name, e.g. 'help(chol.spam)'.
Attaching package: 'spam'
The following object(s) are masked from package:Matrix :
norm
The following object(s) are masked from package:base :
backsolve,
forwardsolve
Attaching package: 'spdep'
The following object(s) are masked from package:ade4 :
mstree
Choose a connection network:
Delaunay triangulation (type 1)
Gabriel graph (type 2)
Relative neighbours (type 3)
Minimum spanning tree (type 4)
Neighbourhood by distance (type 5)
K nearest neighbours (type 6)
Inverse distances (type 7)
Answer: 1
Keep this graph (y/n)? y
Error in spdep::lag.listw(listw, x, TRUE) : object lengths differ
In addition: Warning message:
In spca(mygenind) :
NAs in data are automatically replaced (to mean allele frequency)
> chooseCN(mygenind at other$xy)
Choose a connection network:
Delaunay triangulation (type 1)
Gabriel graph (type 2)
Relative neighbours (type 3)
Minimum spanning tree (type 4)
Neighbourhood by distance (type 5)
K nearest neighbours (type 6)
Inverse distances (type 7)
Answer: 1
Keep this graph (y/n)? y
Neighbour list object:
Number of regions: 76
Number of nonzero links: 430
Percentage nonzero weights: 7.444598
Average number of links: 5.657895
> save.image("D:\\Nevs Docs\\Rwork\\test\\spcaerror1.RData")
>
On 4/05/2010 7:57 PM, Jombart, Thibaut wrote:
> Dear Nevil,
>
> The error likely comes from your data. Actually I can't even create a genind object using the current version of adegenet and the data you sent.
>
> The coding of genetic information is inconsistent:
> - missing values are "NA" or ""
> - first locus is coded by 2 characters by allele, others by three
> - other coding is used sometimes; for instance, ligne 370 reads:
> 202202 254-9 127127 271271
> I guess 254-9 should be 254009 (?), but df2genind is less good at guessing the coding.
>
> Please check your data, and don't hesitate to post another email if the error persists.
>
> Best
>
> Thibaut.
>
>
>
>
> ________________________________________
> From: Nevil Amos [nevil.amos at gmail.com]
> Sent: 04 May 2010 04:30
> To: Jombart, Thibaut
> Cc: adegenet-forum at lists.r-forge.r-project.org
> Subject: Re: Error in spdep::lag.listw(listw, x, TRUE) : object lengths differ
>
> Thanks for the response, I have repeated with another set of data (
> different species from the same datasource)
>
> I am still getting the same error
> There are no NA values in the coordinates
>
> The code initially reads the data from an MS access database - cannot
> append this, but I have again appended the workspace, and the R:
> commands and output are copied below and the r script attached.
>
> Type 2 and 3 connection networks also result in an error, type 4-7 run OK.
>
> thanks
>
> > setwd("d:/nevs docs/rwork/test/")
> > library (adegenet)
> ==========================
> adegenet 1.2-3 is loaded
> ==========================
>
> - to start, type '?adegenet'
> - to browse adegenet website, type 'adegenetWeb()'
> - to post questions/comments: adegenet-forum at lists.r-forge.r-project.org
>
> > library (RODBC)
> > channel<- odbcConnectAccess("Linkage_fe.mdb")
> > mydata<- sqlFetch(channel, "Toadegenet")
> > n<-ncol(mydata)
> > geno=mydata[,c(7:n)]
> > Site=mydata[,c(1)]
> > BirdID=mydata[,c(2)]
> > XY=mydata[,c(5:6)]
> > 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<-XY
> > myspca<-spca(mygenind)
>
> Attaching package: 'ade4'
>
>
> The following object(s) are masked from package:base :
>
> within
>
> Loading required package: sp
> Loading required package: boot
>
> Attaching package: 'boot'
>
>
> The following object(s) are masked from package:survival :
>
> aml
>
> Loading required package: Matrix
> Loading required package: lattice
>
> Attaching package: 'lattice'
>
>
> The following object(s) are masked from package:boot :
>
> melanoma
>
> Loading required package: MASS
> Loading required package: nlme
> Loading required package: maptools
> Loading required package: foreign
> Loading required package: deldir
> deldir 0.0-12
>
> Please note: The process for determining duplicated points
> has changed from that used in version 0.0-9 (and previously).
>
> Loading required package: coda
> Loading required package: spam
> Package 'spam' is loaded. Spam version 0.20-3 (2010-01-13).
> Type demo( spam) for some demos, help( Spam) for an overview
> of this package.
> Help for individual functions is optained by adding the
> suffix '.spam' to the function name, e.g. 'help(chol.spam)'.
>
> Attaching package: 'spam'
>
>
> The following object(s) are masked from package:Matrix :
>
> norm
>
>
> The following object(s) are masked from package:base :
>
> backsolve,
> forwardsolve
>
>
> Attaching package: 'spdep'
>
>
> The following object(s) are masked from package:ade4 :
>
> mstree
>
>
> Choose a connection network:
> Delaunay triangulation (type 1)
> Gabriel graph (type 2)
> Relative neighbours (type 3)
> Minimum spanning tree (type 4)
> Neighbourhood by distance (type 5)
> K nearest neighbours (type 6)
> Inverse distances (type 7)
> Answer: 1
>
> Keep this graph (y/n)? y
> Error in spdep::lag.listw(listw, x, TRUE) : object lengths differ
> In addition: Warning message:
> In spca(mygenind) :
> NAs in data are automatically replaced (to mean allele frequency)
> >
> > myspca<-spca(mygenind)
>
> Choose a connection network:
> Delaunay triangulation (type 1)
> Gabriel graph (type 2)
> Relative neighbours (type 3)
> Minimum spanning tree (type 4)
> Neighbourhood by distance (type 5)
> K nearest neighbours (type 6)
> Inverse distances (type 7)
> Answer: 2
> Error in gabrielneigh(xy) :
> number of neighbours overrun - increase nnmult
>
>
> there are no On 4/05/2010 5:39 AM, Jombart, Thibaut wrote:
>
>> Dear Nevil,
>>
>> thanks for joining your RData, but I can't guess what is wrong if I don't have your R command. Besides, and as you suggest, did you check if there are NAs in your spatial coordinates?
>>
>> Best
>>
>> Thibaut
>>
>>
>>
>> ________________________________________
>> 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: 03 May 2010 11:06
>> To: adegenet-forum at lists.r-forge.r-project.org
>> Subject: [adegenet-forum] Error in spdep::lag.listw(listw, x, TRUE) : object lengths differ
>>
>> I am receiving the below error message presumably because one of my data
>> fileds contians a missing value or something similar?
>>
>> Any indications of how to trace it back would be appreciated. I have
>> attached the workspace if that is permissible.
>>
>> Choose a connection network:
>> Delaunay triangulation (type 1)
>> Gabriel graph (type 2)
>> Relative neighbours (type 3)
>> Minimum spanning tree (type 4)
>> Neighbourhood by distance (type 5)
>> K nearest neighbours (type 6)
>> Inverse distances (type 7)
>> Answer: 1
>>
>> Keep this graph (y/n)? y
>> Error in spdep::lag.listw(listw, x, TRUE) : object lengths differ
>>
>>
>
More information about the adegenet-forum
mailing list