I would like to calculate the S1 term for the variance of Moran's I. The following is the formula to calculate the S1
where w_{ij} is an element in the spatial weights matrix.
My spatial weights matrix is as following:-
structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0.111111111111111, 0.1, 0.1, 0.166666666666667,
0, 0.1, 0.111111111111111, 0.125, 0.166666666666667, 0, 0, 0.1,
0.111111111111111, 0, 0, 0.166666666666667, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0.0909090909090909,
0, 0, 0.1, 0.1, 0.166666666666667, 0, 0.1, 0.111111111111111,
0.125, 0.166666666666667, 0, 0, 0.1, 0, 0, 0, 0, 0, 0, 0.0909090909090909,
0, 0.111111111111111, 0, 0.1, 0, 0, 0.1, 0.111111111111111, 0.125,
0.166666666666667, 0, 0, 0.1, 0.111111111111111, 0, 0, 0.166666666666667,
0, 0, 0.0909090909090909, 0, 0.111111111111111, 0.1, 0, 0, 0.333333333333333,
0.1, 0.111111111111111, 0.125, 0, 0, 0, 0.1, 0.111111111111111,
0, 0, 0.166666666666667, 0, 0, 0.0909090909090909, 0, 0.111111111111111,
0, 0, 0, 0, 0.1, 0.111111111111111, 0, 0.166666666666667, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0.111111111111111, 0, 0, 0.166666666666667, 0, 0, 0.0909090909090909,
0, 0.111111111111111, 0.1, 0.1, 0.166666666666667, 0, 0, 0.111111111111111,
0.125, 0.166666666666667, 0, 0, 0.1, 0.111111111111111, 0, 0,
0, 0, 0, 0.0909090909090909, 0, 0.111111111111111, 0.1, 0.1,
0.166666666666667, 0, 0.1, 0, 0.125, 0, 0, 0, 0.1, 0.111111111111111,
0, 0, 0, 0, 0, 0.0909090909090909, 0, 0.111111111111111, 0.1,
0.1, 0, 0, 0.1, 0.111111111111111, 0, 0, 0, 0, 0.1, 0.111111111111111,
0, 0, 0, 0, 0, 0.0909090909090909, 0, 0.111111111111111, 0.1,
0, 0.166666666666667, 0, 0.1, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0.0909090909090909, 0, 0.111111111111111, 0.1, 0.1, 0, 0, 0.1,
0.111111111111111, 0.125, 0.166666666666667, 0, 0, 0, 0.111111111111111,
0, 0, 0.166666666666667, 0, 0, 0.0909090909090909, 0, 0, 0.1,
0.1, 0, 0.333333333333333, 0.1, 0.111111111111111, 0.125, 0,
0, 0, 0.1, 0, 0, 0, 0.166666666666667, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.166666666666667,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0909090909090909,
0, 0, 0.1, 0.1, 0, 0.333333333333333, 0, 0, 0, 0, 0, 0, 0.1,
0.111111111111111, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim = c(20L, 20L), .Dimnames = list(
c("AUS", "BEL", "CAN", "CHE", "DEU", "DNK", "ESP", "FIN",
"FRA", "GBR", "IRL", "ITA", "JPN", "KOR", "NLD", "NOR", "NZL",
"PRT", "SWE", "USA"), c("AUS", "BEL", "CAN", "CHE", "DEU",
"DNK", "ESP", "FIN", "FRA", "GBR", "IRL", "ITA", "JPN", "KOR",
"NLD", "NOR", "NZL", "PRT", "SWE", "USA")))
I can do this by using a for loop within a for loop, but I am thinking that there might be a more efficient way to do this. Maybe using lapply or something else.
Thanks in advance.
