In the CAR class of spatial models, I’m a little confused as to how the pairwise difference was derived. In the case study, the section about deriving the pairwise difference from the matrix algebra says,

-\frac{1}{2}\big(\phi^{\top}[D-W]\phi\big) + const = -\frac{1}{2}\sum_{i\sim j} (\phi_i - \phi_j)^2\ + const

But if I simulate the math in R using a small artificial lattice (code below) I get the following result (omitting constants and negatives),

\phi^{\top}[D-W]\phi = \frac{1}{2}\sum_{i\sim j} (\phi_i - \phi_j)^2

which says that the matrix algebra result is half of what the pairwise difference computes.

```
N <- 25
B <- matrix(rbinom(N, 1, 0.5), nrow = sqrt(N))
B[upper.tri(B)] <- 0
B_lwr <- B
B <- B + t(B)
diag(B) <- 0
isSymmetric(B)
# mean vector
m <- rnorm(sqrt(N), 1, 1)
# find neighbors
E <- which(B == 1, arr.ind = TRUE)
# GMRF matrix multiply
t(m) %*% (diag(rowSums(B)) - B) %*% m
# GMRF matrix multiply simplified to pairwise difference
diff <- m[E[,1]] - m[E[,2]]
0.5 * sum(diff^2)
```

I think I’m misunderstanding something since both the case study and this paper (bottom of p3) have similar mathematical results. Any idea where I’m going wrong in my thinking?