Moran Calculation I with 4000 entries

I have 4,000 volume records on tree plantations. I need to calculate Moran I for the entire plantation. I use the ape library because spdep is considered slower. My code is:

# Modified from http://www.ats.ucla.edu/stat/r/faq/morans_i.htm require(ape) df <- data.frame( x = 1:2000, y = 1:2000, v = rnorm(4000, mean=4) ) df.dists <- as.matrix(dist(cbind(df$x, df$y))) df.dists.inv <- 1/df.dists diag(df.dists.inv) <- 0 Moran.I(df$v, df.dists.inv) 

When I run the code, I get overflow errors.

 *Error in if (obs <= ei) 2 * pv else 2 * (1 - pv) : missing value where TRUE/FALSE needed* 

Using ff library

 require(ape) require(ff) ffdf <- as.ffdf(df) ffdf.dists <- as.matrix(dist(cbind(ffdf$x, ffdf$y))) ffdf.dists.inv <- 1/df.dists diag(ffdf.dists.inv) <- 0 Moran.I(ffdf$v, ffdf.dists.inv) 

Additional error messages:

 *Error in x - m : non-numeric argument to binary operator In addition: Warning message: In mean.default(x) : argument is not numeric or logical: returning NA* 
  • How can I get calculation on the whole plantation?

  • Use sdep instead of ape .

  • How does the parallel library solve this problem?

Thanks in advance Juan

+8
parallel-processing r ape-phylo spdep
source share
1 answer

You have infinite values ​​in your matrix. This should work in 2 cases (with and without the ff package)

 df.dists.inv[is.infinite(df.dists.inv)] <- 0 

Applying this with a small example:

 require(ape) set.seed(1) df <- data.frame( x = 1:10, y = 1:10, v = rnorm(20, mean=4) ) ..... df.dists.inv[is.infinite(df.dists.inv)] <- 0 Moran.I(df$v, df.dists.inv) $observed [1] -0.02246154 $expected [1] -0.05263158 $sd [1] 0.05399303 $p.value [1] 0.5763143 
+8
source share

All Articles