On Thu, 8 Aug 2019, Stuart Reece wrote:

Thanks Roger.
Happy to do as you have requested.
Which server do you suggest??

You gave the link to the map as:

https://www.samhsa.gov/data/report/2014-2016-nsduh-substate-region-shapefile leading to https://www.samhsa.gov/data/sites/default/files/cbhsq-reports/NSDUHsubstateShapeFile2016/ShapeFile2016.zip

I guess that is the input map. Produc is built into the plm package. So all we need is a script. Your data are no help; creating a reproducible example very often guides the person with the problem to a resolution even without external help. I see that your map has 300+ entities - in that case find another map that matches the setting (US with Alaska and Hawaii states, drop to 48 to match Produc).

Roger

Thanks again,
Stuart.

-----Original Message-----
From: Roger Bivand <roger.biv...@nhh.no>
Sent: Thursday, 8 August, 2019 9:35 PM
To: Stuart Reece <stuart.re...@bigpond.com>
Cc: 'Dr Stuart Reece' <asre...@bigpond.net.au>; 'Barry Rowlingson' 
<b.rowling...@gmail.com>; 'R-sig-geo Mailing List' <r-sig-geo@r-project.org>
Subject: RE: [R-sig-Geo] Adding a Few Neighbour Relationships to a nb List

On Thu, 8 Aug 2019, Stuart Reece wrote:

Thankyou for this advice Roger.
Happy to provide my work for your review but I am not sure how.
This list server has a limit of 50KB and these files are about 100MB....
Love to assist but I would need advice on how best to proceed....???

Choose a built-in data set, such as Produc, change two states to ALASKA and 
HAWAII, drop the ones you chose from the map and any other states not on your 
map, and use that data set, putting the script needed at the head of your 
example. Then create the weights, initially with no links to ALASKA and HAWAII, 
and run the model. Next, edit the neighbour object in script form, and try 
again. Then anyone with your map object (you gave a link), your script, and the 
plm and splm packages can reproduce your problem.

Do also run traceback() after errors, and post what you see.

Roger

Many thanks again,
Stuart.

-----Original Message-----
From: Roger Bivand <roger.biv...@nhh.no>
Sent: Thursday, 8 August, 2019 9:10 PM
To: Stuart Reece <stuart.re...@bigpond.com>
Cc: 'Dr Stuart Reece' <asre...@bigpond.net.au>; 'Barry Rowlingson'
<b.rowling...@gmail.com>; 'R-sig-geo Mailing List'
<r-sig-geo@r-project.org>
Subject: Re: [R-sig-Geo] Adding a Few Neighbour Relationships to a nb
List

On Thu, 8 Aug 2019, Stuart Reece wrote:

Thankyou so much Vijay and Barry.

Yes, thanks!


Yes I have found that using these techniques I can add nb
relationships nicely.

And they card() nicely too.

And when I nb2listw they transform well and when I test them
can.be.simmed(x) they pass this test also.

When I draw maps with them Like Roger Bivand showed in his examples
for poly2nb – the maps draw just perfectly.

This is flying on hope not knowledge. If the assigned values are not
within the 1:n set, there will be trouble - this is an S3 class with
no validity check. Further, there may be trouble if the length of
attr(.,
"region.id") is incorrect, but this cannot be checked unless you run
traceback() after the error in spgm(). We still need a fully reproducible 
example ...

Roger

However when I use them in the spml or spgm regressions in package
splm they fail with an error message usually about indexes being out
of bounds.

Running this code ….

summary(spgm(PC1MI ~ PC1Rx * log(mrjmon),
+              data=MIdf9dfF2, listw=MIdf9sflww,
+              lag=TRUE, moments="fullweights", method="g2sls",
+              model="random", spatial.error=TRUE))

Generates this error:

Error in x[, ii] : subscript out of bounds

I feel that I must be missing something here but am not able to put
my finger on what it is???

Thanks so much again,

Stuart.









From: Dr Stuart Reece <asre...@bigpond.net.au>
Sent: Thursday, 8 August, 2019 2:01 PM
To: 'Barry Rowlingson' <b.rowling...@gmail.com>; 'Stuart Reece'
<stuart.re...@bigpond.com>
Cc: 'Vijay Lulla' <vijaylu...@gmail.com>; 'R-sig-geo Mailing List'
<r-sig-geo@r-project.org>
Subject: RE: [R-sig-Geo] Adding a Few Neighbour Relationships to a nb
List
Importance: High



Thanks Barry.

That is so perfect and so super helpful!!!

And if I want to add three areas to an area – say I want to add 6,7 and 8 to 
the area 10??

Please may I have the syntax for that to avoid the integer error??

Is this also the root of the error about not being the correct index??

Many thanks again,

Stuart.



From: Barry Rowlingson [mailto:b.rowling...@gmail.com]
Sent: Thursday, 8 August 2019 8:51 AM
To: Stuart Reece
Cc: Vijay Lulla; R-sig-geo Mailing List; Stuart Reece
Subject: Re: [R-sig-Geo] Adding a Few Neighbour Relationships to a nb
List



I recently answered a similar question on Stack Overflow where someone needed 
to add detached polygons to their connected network by connecting them to their 
nearest neighbour:



https://stackoverflow.com/questions/57269254/how-to-impute-missing-ne
i
ghbours-of-a-spatial-weight-matrix-queen-contiguity/57378930?noredire
c
t=1#comment101246065_57378930



in short, you can treat a `nb` object like a list of vectors: nb[[i]]
is a vector of indexes of objects connected to object `i`



BUT you have to make sure you store integers:



Here's a `nb` object from that question which in summary has this 
manyneighbours for each region:



card(nb)
[1] 2 3 4 3 2 0 0



lets set the 6th feature to be a neighbour of the first:



nb[[6]] = 1



then uh-oh...



card(nb)
Error in card(nb) :
 INTEGER() can only be applied to a 'integer', not a 'double'



same again only `as.integer`:



nb[[6]] = as.integer(1)



and its happy:



card(nb)
[1] 2 3 4 3 2 1 0



if you want to set the nighbours of 6 to several features:



nb[[6]] = as.integer(c(1,2,3))
card(nb)
[1] 2 3 4 3 2 3 0



Barry






        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


--
Roger Bivand
Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 
Bergen, Norway.
voice: +47 55 95 93 55; e-mail: roger.biv...@nhh.no
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en



--
Roger Bivand
Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 
Bergen, Norway.
voice: +47 55 95 93 55; e-mail: roger.biv...@nhh.no
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en



--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: roger.biv...@nhh.no
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to