<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>RE: [adegenet-forum] Help...</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>Dear Adrien,<BR>
<BR>
this is an important question for sPCA, although not restrained to it. Input from other spatial experts are welcome (some are hiding inside this list)!<BR>
<BR>
The question is quite general: how can we model the connectivity between a set of locations, some of which are identical? I don't think a single answer can be brought here, and the best solution likely is contingent on the data.<BR>
<BR>
Adrien's data represent one tricky and interesting case.<BR>
<BR>
> xy=read.table("coord.txt",head=T)<BR>
> foo1=sunflowerplot(xy) # this figure explains the problem<BR>
<BR>
The roughest approach is to remove duplicate locations, but I would barely call it a solution. In this case it is unthinkable.<BR>
Adding some random noise to coordinates can be another option:<BR>
> xy=as.matrix(xy)<BR>
> xyrand=jitter(xy, fac=2)<BR>
> sunflowerplot(xyrand)<BR>
<BR>
Now, all locations have been disentangled, and yet the sampling designed is preserved. Here is Delaunay's triangulation:<BR>
> cn1=chooseCN(xyrand,type=1)<BR>
<BR>
However, a problem arises: Delaunay is sensitive to small changes in locations. So, another random noise added, another graph obtained:<BR>
> xyrand=jitter(xy, fac=2)<BR>
> sunflowerplot(xyrand)<BR>
> cn2=chooseCN(xyrand,type=1)<BR>
> identical(cn1,cn2) # this is usually FALSE<BR>
<BR>
How many differences are there?<BR>
> temp1=nb2mat(cn1, style="B")<BR>
> temp2=nb2mat(cn2, style="B")<BR>
<BR>
> temp= temp1 == temp2<BR>
> sum(temp) / length(temp) * 100 # I got around 99 % of similar entries<BR>
> cor(as.vector(temp1),as.vector(temp2)) # correlation of only (around) 0.5<BR>
> cor.test(as.vector(temp1),as.vector(temp2))<BR>
<BR>
Adjacency matrices are only weakly correlated, but this is due to the fact they are very sparse.<BR>
One reassuring fact is that structures of autocorrelation on these maps are fairly similar:<BR>
> library(ade4)<BR>
> s.image(xy,orthobasis.mat(temp1)[,3], kgri=10)<BR>
> s.image(xy,orthobasis.mat(temp2)[,3], kgri=10)<BR>
<BR>
So adding a small amount of random noise could do the trick, though it is not very elegant.<BR>
<BR>
Another alternative is using graphs that do not require location to be unique, like for instance connectivity based on distance:<BR>
> cn3=chooseCN(xy,type=5, d1=0,d2=.08)<BR>
<BR>
But then other problems arise, for and foremost the definition of the range at which two locations are neighbours.<BR>
<BR>
In the present case, we might think about pooling data by locations, and working with alleles frequencies observed at each unique location. But this has a strong empirical implication: it means that genetic similarities among genotypes inside a given locations are no longer investigated, and no longer part of what we call 'spatial genetic structure'. These become 'genetic similarities between locations', which is different. It also implies that 10 genotypes taken from the same location will have the same 'weight' in the analysis as one genotype taken at a unique location. So this does not only depend on the data, but also on the question being asked.<BR>
<BR>
To pool data by location, use the devel version of adegenet.<BR>
Define the pop factor as follows:<BR>
> myPop = paste(xy[,1],xy[,2])<BR>
> myPop=factor(myPop, levels=unique(myPop))<BR>
> levels(myPop)= 1:length(levels(myPop))<BR>
> plot(xy, type="n")<BR>
> text(xy,lab=myPop)<BR>
<BR>
<BR>
Put the xy coordinates in the other slot:<BR>
> myObj@other$xy = xy<BR>
and then use 'genind2genpop', specifying "process.other = TRUE, other.action = mean". This will generate a genpop object with the appropriate xy coordinates in the @other slot.<BR>
<BR>
And use the sPCA on this genpop object, using Delaunay triangulation as you wished.<BR>
<BR>
<BR>
To summarise:<BR>
- adding noise works, but this is the quick & dirty approach; might be an issue for testing procedures relying on the connection network, as not only p-values, but test statistics would change.<BR>
<BR>
- using another graph than Delaunay is always an option, but may not always be statisfying.<BR>
<BR>
- working at a 'population' level may be the best option in some cases, when patterns of interest exclude genetic similarities between genotypes taken exactly at the same place, and when the question is more about patterns among groups of genotypes.<BR>
<BR>
Best regards,<BR>
<BR>
Thibaut.<BR>
<BR>
> Hi,<BR>
> I'd like to realise a sPCA analysis with adegenet but a little bug appears during the "connection network choice" step. I'd like to know if someone could help me for that.<BR>
> I'd like to use the Delaunay triangulation type (type1) but when i choose this option, i get this error message : "Error in tri.mesh(x = coords[, 1], y = coords[, 2]) : duplicate data points". I think it's because my data game contains some samples with the same spatial coordinates. I'd like to know if it's possible to keep this samples in the analysis (i've seen that R can automatically delete all the data with repeated coords or keep only one of these samples/coord but this solution doesn't suits me fine), and if yes, how should I do ?. Thanks for your help. (The coord file is attached to this message, maybe it could help)<BR>
> Thanks a lot<BR>
> Adrien RIEUX, PhD student in Montpellier (France)<BR>
> //<BR>
> --------------------------------------------------------------------------------<BR>
><BR>
> Adrien RIEUX<BR>
><BR>
> PhD Student<BR>
><BR>
> CIRAD - Département BIOS<BR>
> UMR Biologie et Génétique des Interactions Plantes-Parasites<BR>
> TA A 54 / K - Campus International de Baillarguet - Bureau 118<BR>
> 34398 Montpellier Cedex 5<BR>
> France<BR>
><BR>
> Tel : + 33 4 99 62 41 84<BR>
> Fax : + 33 4 99 62 48 48<BR>
> Mail : adrien.rieux@cirad.fr<BR>
><BR>
><BR>
><BR>
><BR>
> _______________________________________________<BR>
> adegenet-forum mailing list<BR>
> adegenet-forum@lists.r-forge.r-project.org<BR>
> <A HREF="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/adegenet-forum">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/adegenet-forum</A><BR>
<BR>
<BR>
--<BR>
######################################<BR>
Dr Thibaut JOMBART<BR>
MRC Centre for Outbreak Analysis and Modelling<BR>
Department of Infectious Disease Epidemiology<BR>
Imperial College - Faculty of Medicine<BR>
St Mary’s Campus<BR>
Norfolk Place<BR>
London W2 1PG<BR>
United Kingdom<BR>
Tel. : 0044 (0)20 7594 3658<BR>
t.jombart@imperial.ac.uk<BR>
<A HREF="http://biomserv.univ-lyon1.fr/%7Ejombart/">http://biomserv.univ-lyon1.fr/%7Ejombart/</A><BR>
<A HREF="http://adegenet.r-forge.r-project.org/">http://adegenet.r-forge.r-project.org/</A><BR>
</FONT>
</P>
</BODY>
</HTML>