adeverse / adespatial

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

aem.time doesn't contain code to calculate Moran's I #4

Closed bramstone closed 5 years ago

bramstone commented 6 years ago

Hey Stéphane,

I've been unable to return Moran's I values from the aem.time function. It looks like the code is missing from the function installed from CRAN while your code has it commented out.

EDIT: I just read in your pull requests that you've merged most of the functions from AEM to adespatial but haven't quite finished the aem.time function. I've managed to code my own workaround by downloading the AEM package separately and copying your code in (with minor modifications). I wanted to leave this issue up in case anyone else runs into the same problem.

  if (moran) {
    require(AEM, quietly=TRUE)
    nb <- spdep::cell2nb(n,1)
    links <- spdep::listw2sn(spdep::nb2listw(nb))[,1:2]
    fr.to.aem <- links[(links[,2] - links[,1]) == 1, 1:2] #remove link duplicates
    res <- AEM::moran.I.multi(E.svd$u[,1:k], link=fr.to.aem, weight=w, plot.res=plot.moran)
    Moran <- res$res.mat[,1:2]
    positive <- rep(FALSE,k)
    positive[which(Moran[,1] > res$expected)] <- TRUE
    Moran <- cbind(as.data.frame(Moran), positive)
    colnames(Moran) <- c("Moran","p.value","Positive")
    out <- list(E=E, values=E.svd$d[1:k]^2/(n-1), aem=E.svd$u[,1:k],
                Moran=Moran, expected_Moran=res$expected)
  }
sdray commented 5 years ago

This functionality is added using spdep style in e0571e2c4b16c86b14989959d1bbc98e2fd30bbb