[R] spdep

2003-07-11 Thread Mark Piorecky
Hi everyone,

The Spatial Dependence (spdep) library, has a function called 'dnearneigh', which 
identifies neighbours of region points by Euclidean distance between lower (greater 
than) and upper (less than or equal to) bounds.  The function returns a list of 
integer vectors giving the region id numbers for neighbours satisfying the distance 
criteria.

I have used this to identify the euclidean distance of all points falling within 
0-2000m of each of my surveys locations.  Once distances are converted to inverse 
euclidean distances, the list looks something like this:

[[1]]
[1] 15.617376  0.535176  0.569497

[[2]]
[1] 15.6173762  0.5415378  0.5773159

[[3]]
[1] NA
 
etc.

For each of these points I also have presence/absence data for a particular owl 
species (all the location, PA, etc. is kept in a single data frame).  Is there a way 
of creating a similar list to the one above, identifying the Presence or Absence of an 
owl at each of the points that fall with in 0-2000m of the interested site??

I am attempting to determine the following equation for each site, at a number of 
spatial lags, i.e. 0-2000, 0-4000, etc
   
Autocovariatei =  Sum wij  yj / Sum wij  

 

Variables: Autocovariate for stop i   

yj = Presence (1) or Absence (0) at stop j

wij = the inverse Euclidean distance between stops i 
and j 

Any help would be greatly appreciated.

Mark
[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] spdep question

2004-05-04 Thread Christian Hennig
Dear list,

(also sent to Roger Bivand, but perhaps somebody of you can help me also)

I am trying to use package spdep for fitting an SAR model with errorsarlm.
However, I am not sure how to make a valid nb object out of my
neighborhood. As far as I have seen, there is no documentation for
nb.object.

I have done the following:

class(pschmid$nb) <- "nb"
# pschmid is a prab object as generated from function prabinit, package
# prabclus, and the neighborhood looks as follows:
> unclass(pschmid$nb)
[[1]]
 [1]  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

[[2]]
 [1]  1  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

[[3]]
 [1]  1  2  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

(...and so on, a list of 65 integer vectors, up to...)

[[65]]
 [1] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
60 61
[26] 62 63 64

# This looks more or less like the example (cal.gol.nb), apart from some
# attribs which I do not understand, and it is exactly
# how an nb object is described in help(read.gal). But...

> summary(pschmid$nb)
Neighbour list object:
Number of regions: 65 
Number of nonzero links: 0 
Percentage nonzero weights: 0 
Average number of links: 0 
65 regions with no links:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
54 55 56 57 58 59 60 61 62 63 64 65
Link number distribution:

 0 
65 

# Why are there no links? Do I understand properly what a link is?
# 1 is a neighbor of 2 and vice versa, so I consider them linked?

Can somebody tell me how to turn my neighborhood into an object errorsarlm
and nb2listw (do I need that?) can handle!

Best,
Christian

***
Christian Hennig
Fachbereich Mathematik-SPST/ZMS, Universitaet Hamburg
[EMAIL PROTECTED], http://www.math.uni-hamburg.de/home/hennig/
###
ich empfehle www.boag-online.de

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] spdep error message

2003-08-14 Thread rnaidoo
Hello,

I have been using the package "spdep" to run spatial regressions on a data set 
with about 2500 observations.  It has performed well up until now, but the 
following code resulted in an error:

> load("Panel.90s.ok.R")
> attach(Panel.90s.ok)
> neighs<-dnearneigh(cbind(x,y),0,5)
> help(nbdists)
> dists<-nbdists(neighs,cbind(x,y))
> Weights<-nb2listw(neighs,zero.policy=T,glist=dists)
> 
error.model.rprice<-errorsarlm(log(wells+1)~log(year)+log(area)+log(lag.rprice
)+log(marketable+1)+log(prov.rds+1)+log(ind.rds+1)+log(seismic+1)+log(pipeline
s+1)+log(min.year)+log(max.year)+log(avg.year),listw=Weights,zero.policy=T)
Error in eigen(w, only.values = TRUE) : error code 2311 from Lapack routine 
dgeev

The problem seems to be with the inclusion of the Euclidean distances 
("dists") 
in the spatial weights matrix, as regressions using weights matrices without a 
glist worked fine.  I tried switching the method used in errorsarlm to 
"eigenw" 
but this also resulted in an error:

Error in switch(method, eigen = if (!quiet) cat("neighbourhood matrix 
eigenvalues\n"),  :
...

Unknown method

Similarly, switching methods to "sparse" also resulted in an error:

Error in spwdet(sparseweights, rho = rho, debug = debug) :
Suspicious allocation of memory in sparse functions
...bailing out! Save workspace and quit R!

Any help on how to incorporate distance measures into the spatial weights 
matrix for the errorsarlm/lagsarlm spatial regression commands would be 
greatly 
appreciated!  Hopefully I haven't overlooked something very obvious.

Regards,

Robin Naidoo
Department of Rural Economy
University of Alberta
Canada

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] spdep question

2004-05-04 Thread Roger Bivand
On Tue, 4 May 2004, Christian Hennig wrote:

> Dear list,
> 
> (also sent to Roger Bivand, but perhaps somebody of you can help me also)
> 
> I am trying to use package spdep for fitting an SAR model with errorsarlm.
> However, I am not sure how to make a valid nb object out of my
> neighborhood. As far as I have seen, there is no documentation for
> nb.object.
> 

Well, there is always the code ... if you look at tri2nb(), there may be 
some ideas you can use to construct an "nb" object that is recognised as 
such. If you attach me a saved copy of your object, I'll take a look. What 
does str(pschmid$nb) say? Does that look the same as the examples in 
spdep? 

> I have done the following:
> 
> class(pschmid$nb) <- "nb"
> # pschmid is a prab object as generated from function prabinit, package
> # prabclus, and the neighborhood looks as follows:
> > unclass(pschmid$nb)
> [[1]]
>  [1]  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
> 
> [[2]]
>  [1]  1  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
> 
> [[3]]
>  [1]  1  2  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
> 
> (...and so on, a list of 65 integer vectors, up to...)
> 
> [[65]]
>  [1] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
> 60 61
> [26] 62 63 64
> 
> # This looks more or less like the example (cal.gol.nb), apart from some
> # attribs which I do not understand, and it is exactly
> # how an nb object is described in help(read.gal). But...
> 
> > summary(pschmid$nb)
> Neighbour list object:
> Number of regions: 65 
> Number of nonzero links: 0 
> Percentage nonzero weights: 0 
> Average number of links: 0 
> 65 regions with no links:
> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
> 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
> 54 55 56 57 58 59 60 61 62 63 64 65
> Link number distribution:
> 
>  0 
> 65 
> 
> # Why are there no links? Do I understand properly what a link is?
> # 1 is a neighbor of 2 and vice versa, so I consider them linked?
> 
> Can somebody tell me how to turn my neighborhood into an object errorsarlm
> and nb2listw (do I need that?) can handle!
> 
> Best,
> Christian
> 
> ***
> Christian Hennig
> Fachbereich Mathematik-SPST/ZMS, Universitaet Hamburg
> [EMAIL PROTECTED], http://www.math.uni-hamburg.de/home/hennig/
> ###
> ich empfehle www.boag-online.de
> 
> __
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: [EMAIL PROTECTED]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html