5

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.

  • I have the same exact issue, although it came through the use of another package before gdistance. It appears that the creation of a negative number instead of a positive one at some point in the algorithm creates the issue. Have you found a solution?! – Ouistiti Mar 22 '18 at 20:22
  • @Ouistiti Still waiting on a solution actually. Did you make sure that they were all in the same projection system? – Vijay Ramesh Mar 23 '18 at 19:09
  • Yes I made sure. I also tried the following: 1) replaced all the NA 2) ran on a single core (to see if there was an issue with one of the parallelizing packages). I do not have any other ideas. – Ouistiti Mar 25 '18 at 4:37
  • Could you give us the traceback? – Ouistiti Mar 27 '18 at 5:22
  • Did you find a solution?Because actually I have the same problem – Aridai Aug 28 '18 at 19:01
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.