thekingofkings / chicago-crime

Crime correlation anaysis
MIT License
11 stars 3 forks source link

spatial matrix calculation in R #3

Closed thekingofkings closed 8 years ago

thekingofkings commented 8 years ago

The contiguous spatial matrix calculation is wrong

In the R/pvalue-evaluation.R script, the following function calculates the spatial matrix.

spatialWeight <- function( ca, leaveOneOut = -1 ) {
    if (leaveOneOut > -1) {
        ca <- ca[ ! ca$AREA_NUMBE == as.character(leaveOneOut), ]
    }

    ids <- as.numeric(as.vector(ca$AREA_NUMBE))
    w1 <- nb2mat(poly2nb(ca, row.names=ids), zero.policy=TRUE)
    ids.name <- as.character(ids)
    rownames(w1) <- ids.name
    colnames(w1) <- ids.name
    w1[ids.name,ids.name] <- w1
    return(w1)
}

Notice that the ids is not sorted in ascending order, therefore the line

w1[ids.name, ids.name] <- w1

does nothing here.

thekingofkings commented 8 years ago

fixed