Generating neighbors list in R

Viewed 23

I am trying to generate a neighbors list, specifically an asymmetrical site-by-edge matrix (See below for paper). However, I am having a hard time creating multiple origins and have tried multiple different ways.

**1st attempt**

>nb <- cell2nb(3,2, "queen")
>xy <- coordinates
>xy
>  no      lat      long
>1  1 30.20924 -97.49967
>2  2 30.11203 -97.32514
>3  3 29.70528 -96.53542
>4  4 29.53580 -97.88101
>5  5 29.48454 -97.44769
>6  6 28.82390 -97.03054

>edge.mat <- aem.build.binary(nb, xy)

This generates the following: enter image description here

and edges are the following: enter image description here

I want 0 (origin) to branch to both 1 and 4 separately. I also do not want 1:3 and 4:6 to cross. I want 1 to go to 2, 2 to go to 3 and then 4 to go to 5 and 5 to go to 6.

**2nd attempt**

I also tried to construct my own edges matrix and build a binary matrix that way, but 4 still does not branch from 0. edges file

>  Var1 Var2
>1    0    1
>2    1    2
>3    2    3
>4    0    4
>5    4    5
>6    5    6

>xy
>  no      lat      long
>1  1 30.20924 -97.49967
>2  2 30.11203 -97.32514
>3  3 29.70528 -96.53542
>4  4 29.53580 -97.88101
>5  5 29.48454 -97.44769
>6  6 28.82390 -97.03054

>bin.mat <- aem.build.binary(coords = xy, link = edges)
>bin.mat
>$se.mat
>      [,1] [,2] [,3] [,4] [,5]
> [1,]    0    0    0    0    0
> [2,]    0    1    0    0    0
> [3,]    0    1    1    0    0
> [4,]    0    0    0    0    0
> [5,]    0    0    0    1    0
> [6,]    0    0    0    1    1
> [7,]    1    0    0    0    0
> [8,]    0    0    0    0    0
> [9,]    0    0    0    0    0
>[10,]    0    0    0    0    0
>[11,]    0    0    0    0    0
>[12,]    0    0    0    0    0
>[13,]    0    0    0    0    0
>[14,]    0    0    0    0    0
>[15,]    0    0    0    0    0

>$edges
>  from to
>     0  7
>2    1  2
>3    2  3
>5    4  5
>6    5  6

enter image description here

Any suggestions? I would greatly appreciate it. Thanks!

Blanchet, F. G., Legendre, P., Maranger, R., Monti, D., & Pepin, P. (2011). Modelling the effect of directional spatial ecological processes at different scales. Oecologia, 166(2), 357-368.

0 Answers
Related