On Fri, 25 Apr 2008, Franck Nadaud wrote:
Hello all, Allin & Jack !
You really saved my day ! Let me sum up the situation.
I tested both scripts, they run perfectly !
Just for the record, let me post a version of the script that puts
together Allin's version and mine.
<script>
function sq_distance(scalar from, series xcoord, series ycoord)
scalar x = xcoord[from]
scalar y = ycoord[from]
matrix ret = (xcoord - x)^2 + (ycoord - y)^2
return matrix ret
end function
open centroides_amazonas.txt
scalar m = 4
scalar n = $nobs
matrix nnlist = zeros(n, m)
matrix idx = seq(1,n)'
loop for i=1..n -q
a = sq_distance(i, X_COORD, Y_COORD)
xind = msortby(idx ~ a, 2)
nnlist[i,] = (xind[2:m+1,1])'
end loop
print nnlist
</script>
In fact the msortby command is not documented yet, this is why i had
trouble
to translate the find_nn command of James Lesage.
Isn't it? Which version of gretl are you using? With the current
version, it is in the reference manual and in the on-line help for functions.
Now I can compute the right neighborhood matrices from a whole sample
and
subsamples of interest. This is really neat because once they are created we
can compute spatial autocorrelation coefficients directly using matrix
commands or via regression with bootstrap of p-values :the moran scatterplots
of Luc Anselin, which have the interest of providing real confidence
intervals.
My tests show small differences in results from GEODA and the GRETL scripts I
use now. This is all good news and I will rest on your input to propose a few
scripts and/or functions to compute tests for spatial autocorrelation I will
submit to the community. I hope to write a short note and propose my scripts
soon so that users can grasp the basics of those tests.
This would be great. Spatial models have become a very hot topic in the
past few years, and the more we can do in gretl in this direction the better.
Returning to the matter of neighbors, and programming, there are far
smarter
algorithms than the brute force hack I work on, but think it better to propose
the simple scripts first before turning on the real smart ones which consist
in exploring the neighborhood graph with special functions and pointers. More
of this when the work will be more advanced.
First i will propose the Moran spatial autocorrelation test as a function
using two types of neighborhood structures: contiguity (common border) and
nearest neighbors with choice in the number of neighbors on two kind of grids
too: either square (checkboard) or hexagonal.
Well, thanx very much Allin and Jack !
more about that soon !
Looking forward to it!
Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche
r.lucchetti(a)univpm.it
http://www.econ.univpm.it/lucchetti