[adegenet-forum] Error in spdep::lag.listw(listw, x, TRUE) : object lengths differ
Nevil Amos
nevil.amos at gmail.com
Wed May 5 15:08:59 CEST 2010
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
>>
>>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mydata.csv
Type: application/vnd.ms-excel
Size: 9231 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20100505/007c67e7/attachment-0001.xls>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: spcaerror1.RData
Type: application/octet-stream
Size: 7494 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20100505/007c67e7/attachment-0001.obj>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: spcafromcsv.r
URL: <http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20100505/007c67e7/attachment-0001.txt>
More information about the adegenet-forum
mailing list