On Thu, 12 Aug 2010, elaine kuo wrote:
Dear List,
Eventually computing lagsarlm and errorsarlm become successful,
Using the code below. (maybe knearneigh helps to solve some issue.)
(ref. An Introduction to Spatial Regression Analysis in R, Luc Anselin,
2003)
Or more recently Bivand et al. (2008) Applied Spatial Data Analysis with R
(Springer), ch. 9-10, (see www.asdar-book.org).
I am concerned that you still do not know what you are doing!
You continue to use lat as your x dimension and lon as your y dimension,
this is very confused and most likely wrong. In addition, because you do
not work on this thread regularly (gaps of days or weeks), it is difficult
to tell whether you are still working in decimal degrees, in which case
your whole analysis is compromised - you should use cbind(lon, lat) then
longlat=TRUE in all the neighbour finding steps to use Great Circle
distances.
As I said at the beiginning of the thread, your use of arguments in
functions is sloppy, and the reason why things now work is because you
have changed some arguments. Whether the changes were appropriate or not
is a very different question.
Roger
Elaine
code
rm(list=ls())
datam <-read.csv("c:/migration/Mig_ratio_20100808.csv",header=T,
row.names=1)
library(ncf)
library(spdep)
# get the upper bound
up <- knearneigh(cbind(datam$lat,datam$lon))
upknn <- knn2nb(up)
updist1 <- nbdists(upknn,cbind(datam$lat,datam$lon))
updist1
updistvec <- unlist(updist1)
updistvec
upmaxd <- max(updistvec)
upmaxd
# Define coordinates, neighbours, and spatial weights
coords<-cbind(datam$lat,datam$lon)
coords<-as.matrix(coords)
# Define neighbourhood (here distance 8)
nb8<-dnearneigh(coords,0,8.12)
summary(nb8)
#length(nb8)
#sum(card(nb8))
# Spatial weights, illustrated with coding style "W" (row standardized)
nb8.w<-nb2listw(nb8, glist=NULL, style="W")
# std model
datam.sd<-scale(datam)
datam.std<-as.data.frame(datam.sd)
summary (datam.std)
mean(datam.std)
# obtain standard deviation
sd(datam.std)
mig.std <-lm(datam.std$S ~ datam.std$coast + datam.std$topo_var
+datam.std$prec_ran, data = datam.std)
summary(mig.std)
# Spatial SAR error model
mignb8.err <- errorsarlm(datam.std$S ~ datam.std$coast +
datam.std$topo_var +datam.std$prec_ran, data = datam.std, listw=nb8.w,
na.action=na.omit, method="Matrix", zero.policy=TRUE)
summary(mignb8.err)
# Spatial SAR lag model
mignb8.lag <- lagsarlm(datam.std$S ~ datam.std$coast +
datam.std$topo_var +datam.std$prec_ran, data = datam.std, data=datam.std,
listw=nb8.w, na.action=na.omit, method="Matrix", zero.policy=TRUE)
summary(mignb8.lag)
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: roger.biv...@nhh.no
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo