An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100716/ae61e75a/attachment.pl>
error in errorsarlm
9 messages · elaine kuo, Danlin Yu, Roger Bivand
Elaine: Based on the error message (cannot allocate vector of size 121.8 Mb), it is very possibly you have way too many cases in your data set. A potential solution would be randomly sample your dataset to get a representative sample set and run the spatial regression, or you can always try a computer with more physic memory, or try memory.limit() to manually allocate more memories. See ?memory.limit for more details. Hope this helps. Cheers, Dr. Danlin Yu elaine kuo ??:
Dear List, I encountered an error message when trying to use Chebyshev as method for SAR. Please kindly help and thanks. package spdep was updated on 07162010 system: windows vista home 32-bit R version 2.10.0 (20091026) Elaine Code
library(ncf)
library(spdep)
# Define coordinates, neighbours, and spatial weights
coords<-cbind(datam$lat,datam$lon)
coords<-as.matrix(coords)
#Define neighbourhood (here distance 1.5)
nb10<-dnearneigh(coords,0,9)
nb10.w<-nb2listw(nb10, glist=NULL, style="W", zero.policy=FALSE)
sem.nb10.w <-
errorsarlm(datam$WinterM_ratio~datam$topo_mean+datam$coast+datam$prec_max +datam$temp_min+datam$evi_min, listw=nb10.w, method="Chebyshev",tol.solve=1.0e-17) error: cannot allocate vector of size 121.8 Mb
sem.nb10.w <-
errorsarlm(datam$WinterM_ratio~datam$topo_mean+datam$coast+datam$prec_max
+datam$temp_min+datam$evi_min, listw=nb10.w,
method="Chebyshev",zero.policy=TRUE,tol.solve=1.0e-17)
error in switch(Generic, `+` = , `-` = { :
Cholmod error 'out of memory' at file:../Core/cholmod_memory.c, line 148
[[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
___________________________________________ Danlin Yu, Ph.D. Associate Professor of GIS and Urban Geography Department of Earth & Environmental Studies Montclair State University Montclair, NJ, 07043 Tel: 973-655-4313 Fax: 973-655-4072 email: yud at mail.montclair.edu webpage: csam.montclair.edu/~yu
On Fri, 16 Jul 2010, elaine kuo wrote:
Dear List, I encountered an error message when trying to use Chebyshev as method for SAR. Please kindly help and thanks.
Beyond what Danlin said, I am very unsure where to start. Please provide adequate information about your input data, specifically the number of observations, and the number of links in the neighbour list length(nb10) sum(card(nb10)) In addition, the implicit discription of nb10 looks confusing (is the distance threshold 1.5, 9, or 10?). The ordering of lat and lon looks wrong. You are not using Great Circle distances (and probably should?). So memory issues in errorsarlm are the least of your problems. My guess is that with dnearneigh() and a threshold of 9 degrees, you are including most of a large data set in the neighbour list, and if n is large, this will give a very large almost dense set of spatial weights, which was not what you intended. Get the weights correct first, and the rest will likely follow. Roger
package spdep was updated on 07162010 system: windows vista home 32-bit R version 2.10.0 (20091026) Elaine Code
library(ncf) library(spdep) # Define coordinates, neighbours, and spatial weights coords<-cbind(datam$lat,datam$lon) coords<-as.matrix(coords) #Define neighbourhood (here distance 1.5) nb10<-dnearneigh(coords,0,9) nb10.w<-nb2listw(nb10, glist=NULL, style="W", zero.policy=FALSE) sem.nb10.w <-
errorsarlm(datam$WinterM_ratio~datam$topo_mean+datam$coast+datam$prec_max +datam$temp_min+datam$evi_min, listw=nb10.w, method="Chebyshev",tol.solve=1.0e-17) error: cannot allocate vector of size 121.8 Mb
sem.nb10.w <-
errorsarlm(datam$WinterM_ratio~datam$topo_mean+datam$coast+datam$prec_max
+datam$temp_min+datam$evi_min, listw=nb10.w,
method="Chebyshev",zero.policy=TRUE,tol.solve=1.0e-17)
error in switch(Generic, `+` = , `-` = { :
Cholmod error 'out of memory' at file:../Core/cholmod_memory.c, line 148
[[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
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100717/db5a1d93/attachment.pl>
On Sat, 17 Jul 2010, elaine kuo wrote:
Dear, Thank you for the help. 1. distance threshold It is 9. (Roger, you are right and sorry to confuse you)
But 9 what, metres, degrees? Should your code be: cbind(datam$lat,datam$lon), as the normal ordering is eastings then northings, not the opposite?
9 is the cutting point for avoiding empty neighbour sets. (If the distance threshold is 8, there will be empty ones.)
This is not a good reason, as graph neighbours can be sparse and link over longer distances.
2. dataset length(nb10)=4873. sum(card(nb10)=885478)
This gives an average of 181.7 neighbours per observation, and is the root of the problem. The Chebyshev method uses a set of low powers of the weights, which fill in quickly for large average numbers of neighbours. Did you try the Matrix method (your error message suggests that you may have done, but the code does not)?
3. memory size the memory limit is 1535 Mb, which is much larger than 121.8 Mb.
Windows (your OS?) memory handling is very poor for larger objects, and the 121Mb is extra memory needed. However, the main problem is your design of weights, which are far too dense to make sense. Choose an alternative weights definition and try again. Roger
Elaine Code
library(ncf) library(spdep) # Define coordinates, neighbours, and spatial weights coords<-cbind(datam$lat,datam$lon) coords<-as.matrix(coords) #Define neighbourhood (here distance 1.5) nb10<-dnearneigh(coords,0,9) nb10.w<-nb2listw(nb10, glist=NULL, style="W", zero.policy=FALSE) sem.nb10.w <-
errorsarlm(datam$WinterM_ratio~datam$topo_mean+datam$coast+datam$prec_max +datam$temp_min+datam$evi_min, listw=nb10.w, method="Chebyshev",tol.solve=1.0e-17) error: cannot allocate vector of size 121.8 Mb sem.nb10.w <-
errorsarlm(datam$WinterM_ratio~datam$topo_mean+datam$coast+datam$prec_max
+datam$temp_min+datam$evi_min, listw=nb10.w,
method="Chebyshev",zero.policy=TRUE,tol.solve=1.0e-17)
error in switch(Generic, `+` = , `-` = { :
Cholmod error 'out of memory' at file:../Core/cholmod_memory.c, line 148
On Sat, Jul 17, 2010 at 3:52 AM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
On Fri, 16 Jul 2010, elaine kuo wrote: Dear List,
I encountered an error message when trying to use Chebyshev as method for SAR. Please kindly help and thanks.
Beyond what Danlin said, I am very unsure where to start. Please provide adequate information about your input data, specifically the number of observations, and the number of links in the neighbour list length(nb10) sum(card(nb10)) In addition, the implicit discription of nb10 looks confusing (is the distance threshold 1.5, 9, or 10?). The ordering of lat and lon looks wrong. You are not using Great Circle distances (and probably should?). So memory issues in errorsarlm are the least of your problems. My guess is that with dnearneigh() and a threshold of 9 degrees, you are including most of a large data set in the neighbour list, and if n is large, this will give a very large almost dense set of spatial weights, which was not what you intended. Get the weights correct first, and the rest will likely follow. Roger
package spdep was updated on 07162010 system: windows vista home 32-bit R version 2.10.0 (20091026) Elaine Code
library(ncf) library(spdep) # Define coordinates, neighbours, and spatial weights coords<-cbind(datam$lat,datam$lon) coords<-as.matrix(coords) #Define neighbourhood (here distance 1.5) nb10<-dnearneigh(coords,0,9) nb10.w<-nb2listw(nb10, glist=NULL, style="W", zero.policy=FALSE) sem.nb10.w <-
errorsarlm(datam$WinterM_ratio~datam$topo_mean+datam$coast+datam$prec_max +datam$temp_min+datam$evi_min, listw=nb10.w, method="Chebyshev",tol.solve=1.0e-17) error: cannot allocate vector of size 121.8 Mb sem.nb10.w <-
errorsarlm(datam$WinterM_ratio~datam$topo_mean+datam$coast+datam$prec_max
+datam$temp_min+datam$evi_min, listw=nb10.w,
method="Chebyshev",zero.policy=TRUE,tol.solve=1.0e-17)
error in switch(Generic, `+` = , `-` = { :
Cholmod error 'out of memory' at file:../Core/cholmod_memory.c, line 148
[[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
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
2 days later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100720/280ce175/attachment.pl>
On Tue, 20 Jul 2010, elaine kuo wrote:
Hello, Thanks for the always concerns. answering the previous questions first.
1. distance threshold
But 9 what, metres, degrees? Should your code be: cbind(datam$lat,datam$lon), as the normal ordering is eastings then northings, not the opposite?
=> unit is degree, and the lat/lon is revised (thanks)
9 is the cutting point for avoiding empty neighbour sets
This is not a good reason, as graph neighbours can be sparse and link over longer distances.
=> according to previous message with similar questions,
it is mentioned that including empty neighbor sets could be
meaningless...
so, if empty neighbor sets are accepted here,
could there be anything needed to be cautious upon ?
Just do not use distance as a criterion when the observations are very irregularly spaced! Use perhaps a symmetricised k-nearest neighbour definition. And make sure that you do use Great Circle distances - you are not doing so now. With 200 neighbours, you have no viable spatial process, really. You can accept no-neighbour observations when there is no good reason to suppose that they could interact, but then have to attend to your zero.policy settings. It all depends on what processes are thought to be causing the observations to influence each other.
2. dataset length(nb10)=4873. sum(card(nb10)=885478)
This gives an average of 181.7 neighbours per observation, and is the root of the problem. The Chebyshev method uses a set of low powers of the weights, which fill in quickly for large average numbers of neighbours. Did you try the Matrix method (your error message suggests that you may have done, but the code does not)? => "Matrix" tried but failed. The warning and code as below..
1. change method to Matrix Error in solve.default(-(mat), tol.solve = tol.solve) : System calculation is specific, the condition is =5.14146e-17 (translated from Chinese) Warning messages:
Warning not a problem, but the error suggests scaling problems in the covariance matrix of the coefficients. The X variables are most likely measured in inappropriate metrics (some coefficients of size 1000, others of size 0.0001, for example). Please find local help to resolve the underlying problems, related to why you want these weights, and why you are trying to fit this kind of model (that is: is your research question sensible and what authority (literature) do you have for your choices?). Solve all of the problems first on a small subset of your data, and scale up afterwards. Roger
1: In determinant(x, TRUE) : This version of the Matrix package returns |determinant(L)| instead of determinant(A), i.e., a *DIFFERENT* value. If still necessary, do change your code, following http://matrix.r-forge.r-project.org 2: In powerWeights(W = W, rho = lambda, order = con$pWOrder, X = B, : not converged within order iterations 3: In powerWeights(W = t(W), rho = lambda, order = con$pWOrder, X = C, : not converged within order iterations code rm(list=ls()) datam <-read.csv("c:/migration/M_R_2090707_winterM.csv",header=T, row.names=1) dim(datam) datam[1,] library(ncf) library(spdep) # Define coordinates, neighbours, and spatial weights coords<-cbind(datam$lon,datam$lat) coords<-as.matrix(coords) #Define neighbourhood (here distance 9) nb9<-dnearneigh(coords,0,9) length(nb9) sum(card(nb9)) #Spatial weights, illustrated with coding style "W" (row standardized) nb9.w<-nb2listw(nb9, glist=NULL, style="W", zero.policy=FALSE) # Spatial SAR error model sem.nb9.w <- errorsarlm(datam$WinterM_ratio~datam$topo_mean+datam$coast+datam$prec_max +datam$temp_min+datam$evi_min, data=datam, listw=nb9.w, na.action=na.omit, method="Matrix", zero.policy=TRUE,,tol.solve=1.0e-17)
3. memory size
the memory limit is 1535 Mb, which is much larger than 121.8 Mb.
Windows (your OS?) memory handling is very poor for larger objects, and the 121Mb is extra memory needed.
=> OS : Vista HOME
However, the main problem is your design of weights, which are far too dense to make sense. Choose an alternative weights definition and try again.
=> 2. decrease the neighbor distance from 9 to 5
Warning messages:
1: In powerWeights(W = W, rho = lambda, order = con$pWOrder, X = B, :
not converged within order iterations
2: In powerWeights(W = t(W), rho = lambda, order = con$pWOrder, X = C, :
not converged within order iterations
code
rm(list=ls())
datam <-read.csv("c:/migration/M_R_20100707_winterM.csv",header=T,
row.names=1)
dim(datam)
datam[1,]
library(ncf)
library(spdep)
# Define coordinates, neighbours, and spatial weights
coords<-cbind(datam$lon,datam$lat)
coords<-as.matrix(coords)
#Define neighbourhood (here distance 5)
nb5<-dnearneigh(coords,0,5)
#Spatial weights, illustrated with coding style "W" (row standardized)
nb5.w<-nb2listw(nb5, glist=NULL, style="W", zero.policy=TRUE)
# Spatial SAR error model
sem.nb5.w <-
errorsarlm(datam$WinterM_ratio~datam$topo_mean+datam$coast+datam$prec_max
+datam$temp_min+datam$evi_min, data=datam, listw=nb5.w, na.action=na.omit,
method="Chebyshev", zero.policy=TRUE,,tol.solve=1.0e-17)
Elaine
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
2 days later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100723/2dd83acc/attachment.pl>
7 days later
On Fri, 23 Jul 2010, elaine kuo wrote:
1. change method to Matrix
System calculation is specific, the condition is =5.14146e-17 (translated from Chinese) Warning messages:
Warning not a problem, but the error suggests scaling problems in the covariance matrix of the coefficients. The X variables are most likely measured in inappropriate metrics (some coefficients of size 1000, others of size 0.0001, for example). ==> using standardized regression, the warning disappeared as you advised.
However, another set of warning appears: Warning messages: 1: In determinant(x, TRUE) : This version of the Matrix package returns |determinant(L)| instead of determinant(A), i.e., a *DIFFERENT* value. If still necessary, do change your code, following http://matrix.r-forge.r-project.org 2: In powerWeights(W = W, rho = lambda, order = con$pWOrder, X = B, : not converged within order iterations 3: In powerWeights(W = t(W), rho = lambda, order = con$pWOrder, X = C, : not converged within order iterations Please kindly advise how to modify the code below from determinant L to determinant A and why ?
The warning is irrelevant. The error is caused by your weights.
2. great distance circle
And make sure that you do use Great Circle distances - you are not doing so
now.
With 200 neighbours, you have no viable spatial process, really.
=> 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?
Also, does "no viable spatial process" mean no spatial interaction within the range should be taken into consideration ?
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.
Thank you
Elaine
code
datam <-read.csv("c:/migration/M_R_SummerM20100722.csv",header=T,
row.names=1)
# std method scale
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$SummerM_ratio~datam.std$coast+datam.std$topo_mean+datam.std$prec_mean+datam.std$temp_ran+datam.std$evi_ran,data=datam.std)
summary(mig.std)
#SAR
library(ncf)
library(spdep)
# Define coordinates, neighbours, and spatial weights
coords<-cbind(datam$lon,datam$lat)
coords<-as.matrix(coords)
#Define neighbourhood (here distance 5)
nb5<-dnearneigh(coords,0,5,longlat=TRUE)
#Spatial weights, illustrated with coding style "W" (row standardized)
nb5.w<-nb2listw(nb5, glist=NULL, style="W", zero.policy=TRUE)
+++error in nb2listw(nb5, glist = NULL, style = "W", zero.policy = TRUE)
:
No valid observations +++
(then modified as nb5<-dnearneigh(coords,0,5) and Matrix went on
smoothly )
# Spatial SAR error model
sem.nb5.w <-
errorsarlm(datam.std$SummerM_ratio~datam.std$coast+datam.std$topo_mean+datam.std$prec_mean+datam.std$temp_ran+datam.std$evi_ran,data=datam.std,
listw=nb5.w, na.action=na.omit, method="Matrix", zero.policy=TRUE)
+++warning
1: In determinant(x, TRUE) : This version of the Matrix package returns |determinant(L)| instead of determinant(A), i.e., a *DIFFERENT* value. If still necessary, do change your code, following http://matrix.r-forge.r-project.org 2: In powerWeights(W = W, rho = lambda, order = con$pWOrder, X = B, : not converged within order iterations 3: In powerWeights(W = t(W), rho = lambda, order = con$pWOrder, X = C, : not converged within order iterations ++++
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