[adegenet-forum] Specifying Maximum Distance in a Connection network

Jombart, Thibaut t.jombart at imperial.ac.uk
Thu Jun 18 10:53:55 CEST 2015


Hi David, 

yes you can do that, though it is not directly implemented in chooseCN. The idea is to get the adjacency matrix, put '0's where needed, and convert it back to a nb object.

Here's an example:
## load data
 > library(adegenet)
> data(nancycats)

## Delaunay triangulation
> cn1 <- chooseCN(nancycats at other$xy,ask=FALSE,type=1)

## that's the adj. matrix
> neig2mat(nb2neig(cn1))
   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
1  0 0 0 0 1 0 0 0 1  0  0  1  0  0  0  1  1
2  0 0 0 0 1 0 0 1 1  1  0  0  0  0  0  0  0
3  0 0 0 0 0 1 0 0 0  0  1  0  0  1  0  1  1
4  0 0 0 0 0 0 0 0 0  1  0  1  1  0  1  1  0
5  1 1 0 0 0 1 1 0 1  0  0  0  0  0  0  0  1
6  0 0 1 0 1 0 1 0 0  0  0  0  0  1  0  0  1
7  0 0 0 0 1 1 0 0 0  0  1  0  0  1  0  0  0
8  0 1 0 0 0 0 0 0 1  1  0  1  0  0  0  0  0
9  1 1 0 0 1 0 0 1 0  0  0  1  0  0  0  0  0
10 0 1 0 1 0 0 0 1 0  0  0  1  0  0  0  0  0
11 0 0 1 0 0 0 1 0 0  0  0  0  1  1  1  1  0
12 1 0 0 1 0 0 0 1 1  1  0  0  0  0  0  1  0
13 0 0 0 1 0 0 0 0 0  0  1  0  0  0  1  1  0
14 0 0 1 0 0 1 1 0 0  0  1  0  0  0  0  0  0
15 0 0 0 1 0 0 0 0 0  0  1  0  1  0  0  0  0
16 1 0 1 1 0 0 0 0 0  0  1  1  1  0  0  0  1
17 1 0 1 0 1 1 0 0 0  0  0  0  0  0  0  1  0

## store it
> matConnect <- neig2mat(nb2neig(cn1))

## get geographic distances
> D <- as.matrix(dist(nancycats$other$xy))
> range(D)
[1]   0.0000 369.1358

## new adj. matrix to be pruned
> matConnect2 <- matConnect

## these are links for distances > 150m
> matConnect2[D>150]
  [1] 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
 [38] 0 0 1 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0
 [75] 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
[112] 0 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
[149] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 1 0
[186] 0 0 0 0 1

## set these to be all 0
> matConnect2[D>150] <- 0
> library(spdep)

## convert back to nb object
> cn2 <- mat2listw(matConnect2)$neighbours
> cn2
Neighbour list object:
Number of regions: 17 
Number of nonzero links: 60 
Percentage nonzero weights: 20.76125 
Average number of links: 3.529412 

## plot to check the differences
> plot(cn1, coords=nancycats$other$xy)

> plot(cn2, coords=nancycats$other$xy)

If others think it is useful, post a feature request on github:
https://github.com/thibautjombart/adegenet/issues

Cheers
Thibaut

==============================
Dr Thibaut Jombart
MRC Centre for Outbreak Analysis and Modelling
Department of Infectious Disease Epidemiology
Imperial College - School of Public Health
Norfolk Place, London W2 1PG, UK
Tel. : 0044 (0)20 7594 3658
http://sites.google.com/site/thibautjombart/
http://sites.google.com/site/therepiproject/
http://adegenet.r-forge.r-project.org/
Twitter: @thibautjombart



________________________________________
From: adegenet-forum-bounces at lists.r-forge.r-project.org [adegenet-forum-bounces at lists.r-forge.r-project.org] on behalf of Phair, D, Mnr <16187393 at sun.ac.za> [16187393 at sun.ac.za]
Sent: 18 June 2015 09:33
To: adegenet-forum at lists.r-forge.r-project.org
Subject: [adegenet-forum] Specifying Maximum Distance in a Connection network

Hi there


I am a masters Student working on spatial sorting in an invasive Bird.

I am looking at comparing patterns of spatial sorting in a species over two continents.

I am not having any issues with the running of the analysis but i wondered if it was possible to specify a maximum distance for any of the connection network methods other than the minimum spanning tree. as the connectivity in that is to high.

I.E. I would like to use something like Delunay Triangulation but limit the maximum distance so that it is the same in South Africa and Australian Dataset.


Regards


David Phair



More information about the adegenet-forum mailing list