geogravity(x,longvar,latvar,alpha=1,maxd=NULL,alldata=FALSE, window=.10,outmatrix=FALSE)
The "gravity variable" that is stored in gravity is the average value for each observation:
By default, the locfit program is used to find a set of target values for calculating $ g_{ij}$. The full set of observations is used for the j index, but a smaller set of observations is used for the target values, i. The abbreviated set of $g_i$ values is then interpolated to the full set of data points using the smooth12 command. The vector of target observation numbers is stored in targetobs.
library(spdep)
cook <- readShapePoly(system.file("maps/CookCensusTracts.shp",package="McSpatial"))
cook <- cook[cook$POPULATION>0&cook$AREA>0,]
cook$lndens <- log(cook$POPULATION/cook$AREA)
lmat <- coordinates(cook)
longitude <- lmat[,1]
latitude <- lmat[,2]
fit <- geogravity(cook$lndens,longitude,latitude)
cook$gravity <- fit$gravity
Run the code above in your browser using DataLab