An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100801/a77b62b0/attachment.pl>
error in errorsarlm
5 messages · elaine kuo, Nikhil Kaza, Roger Bivand
example(errorsarlm) Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.list at gmail.com
On Aug 1, 2010, at 7:57 AM, elaine kuo wrote:
Dear Dr. Bivand and list Thank you for the patience. Only one question remains
2. great distance circle => longlat = TRUE returns no valid observation ... similar error messages have been researched in the archived mail but no identical case found... Please kindly suggest when longlat=TRUE, whether the unit of both longitude and latitude is degree.decimal.. (confused with the manual explanation "measured in kilometer")
The threshold is in km when longlat=TRUE, but the coordinates are in decimal degrees. Please state the representation of your coordinates - are they in decimal degrees or not?
=> Yes, mine are in decimal degrees.
No, simply that you are including too many neighbours leading to too much smoothing for many observations. Please try everything on small examples until you understand what you are doing. Best, use publically available small examples, and include complete verbatim code (or post code on a website), max. 10 lines.
=> please advise any publicly available small examples to try
errosarlm...
I have none at hand.. :P Thank you.
Elaine
[[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
On Sun, 1 Aug 2010, Nikhil Kaza wrote:
example(errorsarlm)
Right! Or any other available dataset that mirrors the application case, which seems to be ecological, but crucially has point or cell support in decimal degrees with very large differences in distances between observations. You are right that packages include lots of example data sets, and that they are the place to start. In addition, the case is large, but the example should not be, so that all the other problems can be eliminated first before trying to scale up to moderate N (about 4000 if I recall correctly). The main problem is that the spatial process is conceptualised as contagious in distance, and that the distance threshold is chosen to ensure that all observations have at least one neighbour. This doesn't seem helpful as many observations then have "too many" neighbours to make sense. If the coordinates of the observations can be projected to the plane, a graph-based neighbour scheme can be used, which represents the spatial process as contagious in contiguity (neighbouring observations are neighbours irrespective of distance). So the first step is to think through how "neighbouring" observations can influence each other in terms appropriate to the subject domain. Roger
Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.list at gmail.com On Aug 1, 2010, at 7:57 AM, elaine kuo wrote:
Dear Dr. Bivand and list Thank you for the patience. Only one question remains
2. great distance circle => longlat = TRUE returns no valid observation ... similar error messages have been researched in the archived mail but no identical case found... Please kindly suggest when longlat=TRUE, whether the unit of both longitude and latitude is degree.decimal.. (confused with the manual explanation "measured in kilometer")
The threshold is in km when longlat=TRUE, but the coordinates are in decimal degrees. Please state the representation of your coordinates - are they in decimal degrees or not?
=> Yes, mine are in decimal degrees.
No, simply that you are including too many neighbours leading to too much smoothing for many observations. Please try everything on small examples until you understand what you are doing. Best, use publically available small examples, and include complete verbatim code (or post code on a website), max. 10 lines.
=> please advise any publicly available small examples to try errosarlm... I have none at hand.. :P Thank you. Elaine [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at 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.Bivand at nhh.no
10 days later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100812/2fa22c7e/attachment.pl>
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 at 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.Bivand at nhh.no