TransWikia.com

commuteDistance in gdistance package in R giving error

Geographic Information Systems Asked by Vijay Ramesh on June 24, 2021

I am currently trying to run a function that "calculates the expected random-walk commute time between nodes in a graph. It is defined as the effective distance (resistance distance) between the selected nodes multiplied by the volume of the graph, which is the sum of the conductance weights of all the edges in the graph (Chandra et al. 1997). The result represents the average number of steps that is needed to commute between the nodes during a random walk"

To run commuteDistance from the gDistance package, I need to create a transition object.

Step 1: I loaded my rasterlayer

> jul <- EVIrec[[6]]
> jul
class       : RasterLayer 
dimensions  : 642, 382, 245244  (nrow, ncol, ncell)
resolution  : 1000, 1000  (x, y)
extent      : 461951, 843951, 892583.3, 1534583  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=43 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : in memory
names       : Jul 
values      : 1, 3  (min, max)

Step 2: I created a ‘transition object’ as mentioned here

> tr <- transition(jul, mean, directions = 8)
> tr
 class       : TransitionLayer 
 dimensions  : 642, 382, 245244  (nrow, ncol, ncell)
 resolution  : 1000, 1000  (x, y)
 extent      : 461951, 843951, 892583.3, 1534583  (xmin, xmax, ymin, ymax)
 coord. ref. : +proj=utm +zone=43 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
 values      : conductance 
 matrix class: dsCMatrix 

Step 3: I used a geographic correction approach on the transition layer. Details here

> julcorr <- geoCorrection(tr, type = "r", multpl=F)
> julcorr
 class       : TransitionLayer 
 dimensions  : 642, 382, 245244  (nrow, ncol, ncell)
 resolution  : 1000, 1000  (x, y)
 extent      : 461951, 843951, 892583.3, 1534583  (xmin, xmax, ymin, ymax)
 coord. ref. : +proj=utm +zone=43 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
values      : conductance 
matrix class: dsCMatrix

I then used the commuteDistance function as mentioned here and I get this error as shown below.

> jul_comm <- commuteDistance(julcorr, centroids_jul)
Error in LU.dgC(a) : cs_lu(A) failed: near-singular A (or out of memory)
In addition: Warning message:
In .rD(x, coords) :
  46 out of 47 locations were found in the fully connected transition matrix. NAs introduced.

Ultimately, I would like to run a function that does an operation similar to CIRCUITSCAPE, but within R and then use these results for further analyses.

One Answer

I've had this error pop up before and it turned out that one of my sample locations did not overlap with the raster I provided. Go back and double check that all points fall within the raster cells. Even if the points are within the raster extent, they may be falling on NA cells.

Answered by Matt Combs on June 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP