adeverse / adespatial

Multivariate Multiscale Spatial Analysis
http://adeverse.github.io/adespatial/
34 stars 7 forks source link

Glist formatting for resistance weighted db MEM #14

Closed frederikvand closed 3 years ago

frederikvand commented 3 years ago

Dear adespatial admins,

Thank you for the great package! I would like to perform a distance based Moran's Eigenvector Map (db-MEM) for further use in RDA to detect local adapations. Following the guidelines for spatial weighting I truncated the distance matrix based on the minimum spanning tree (graph-based MEM) and want to weight my neighbours based on (highly accurate) cumulative landscape resistance values. However, I am unable to get my landscape resistances in the right formatting for weighting.

Neighbour list object: Number of regions: 29 Number of nonzero links: 164 Percentage nonzero weights: 19.50059 Average number of links: 5.655172

mem.gab<- scores.listw(listw_NN, wt = resistance_weights)), MEM.autocor = c("positive"))

Error in bicenter.wt(w, row.wt = wt, col.wt = wt) : length of row.wt must equal the number of rows in x

I can directly integrate the resistance matrix with the mat2listw but then I can't truncate the matrix as I understand is advised.

Characteristics of weights list object: Neighbour list object: Number of regions: 29 Number of nonzero links: 812 Percentage nonzero weights: 96.55172 Average number of links: 28

Weights style: M Weights constants summary: n nn S0 S1 S2 M 29 841 13149.41 902809.7 33894518

Would you have any advise on how to format the resistance matrix for weighting?

Thanks a lot! With kind regards, Frederik Van Daele

sdray commented 3 years ago

Hi your question is more related to spdep than adespatial(nb2listw is in spdep). If you look at the example in the documentation page of the function, something like that should work (mat.res is a n-by-n matrix that contains the resistance values and neighbours is the nb object created before):

glist <- vector(mode="list", length=length(neighbours))
for (i in seq(along=neighbours))
       glist[[i]] <- res.mat[i, neighbours[[i]]]

listw <- nb2listw(neighbours, glist=glist, style="B")
frederikvand commented 3 years ago

That worked! Thanks a lot!!

I can now use the result from adespatial in my RDA!

Orthobasis with 29 rows and 12 columns Only 6 rows and 4 columns are shown MEM1 MEM2 MEM3 MEM4 C1 -3.51156355 -0.2073968 0.22740323 -0.2127958 C2 -2.45095813 -0.1044268 0.14130762 -0.0742931 C3 -2.65179897 -0.1149683 0.04818542 -0.1050231 C4 -0.35640907 0.1862754 -0.31014670 0.3420734 C5 0.08987924 0.1952541 -0.48939434 0.2779218 C6 0.13201571 0.1733465 -0.63459111 0.1946082

sdray commented 3 years ago

Excellent ! Happy spatial analysis ;-)