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)
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
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo