spatialstatisticsupna / bigDM

R package for scalable Bayesian disease mapping models for high-dimensional data
13 stars 4 forks source link

cartography dataset #2

Closed drjphughesjr closed 11 months ago

drjphughesjr commented 11 months ago

The Carto_SpainMUN dataset cannot be used because the latitude values are identical to the longitude values.

head(data.frame(lat = Carto_SpainMUN$lat, long = Carto_SpainMUN$long)) lat long 1 4742974 4742974 2 4765886 4765886 3 4766225 4766225 4 4775453 4775453 5 4729884 4729884 6 4752714 4752714

aritz-adin commented 11 months ago

Many thanks @drjphughesjr,

lat and long variables in the Carto_SpainMUN object were not correct.

I have deleted them to avoid confusion. I have also updated the area and perimeter variables, including their units.

Please note that you can extract the X and Y coordinates (UTM zone 30N) of the polygon centroids as:

coord <- sf::st_coordinates(sf::st_centroid(Carto_SpainMUN))
head(coord)

Best, Aritz

drjphughesjr commented 11 months ago

Thanks, Aritz.

Do you know how I can obtain the adjacency structure among the areal units?

Thanks for your consideration.

Warmly,

John

On Mon 16 Oct 2023 at 4:47 a.m., Aritz Adin @.***> wrote:

Many thanks @drjphughesjr https://github.com/drjphughesjr,

lat and long variables in the Carto_SpainMUN object were not correct.

I have deleted them to avoid confusion. I have also updated the area and perimeter variables, including their units.

Please note that you can extract the X and Y coordinates (UTM zone 30N) of the polygon centroids as:

coord <- sf::st_coordinates(sf::st_centroid(Carto_SpainMUN)) head(coord)

Best, Aritz

— Reply to this email directly, view it on GitHub https://github.com/spatialstatisticsupna/bigDM/issues/2#issuecomment-1764011695, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASMYZ6YLBPGXK2WEG3YJSE3X7TYCJANCNFSM6AAAAAA55UD2GY . You are receiving this because you were mentioned.Message ID: @.***>

aritz-adin commented 11 months ago

Dear John,

In general, you can compute the adjacency binary matrix of a sf object as

carto.nb <- spdep::poly2nb(carto)
W <- spdep::nb2listw(carto.nb, style="B")

However, you will obtain an error message if any of the polygons does not have adjacent areas (as is the case of the object Carto_SpainMUN).

To avoid this issues and always obtain a connected graph, I recommend you to use the bigDM::connect_subgraphs() function:

> library(bigDM)
> data("Carto_SpainMUN")
> str(Carto_SpainMUN,1)
Classes ‘sf’ and 'data.frame':  7907 obs. of  9 variables:
 $ ID       : chr  "01001" "01002" "01003" "01004" ...
 $ name     : chr  "Alegria-Dulantzi" "Amurrio" "Aramaio" "Artziniega" ...
 $ area     : Units: [m^2] num  19913794 96145595 73338806 27506468 10559721 ...
 $ perimeter: Units: [m] num  34372 63352 41430 22605 17847 ...
 $ obs      : int  2 28 6 3 0 2 5 2 3 2 ...
 $ exp      : num  3.024 20.846 3.753 3.209 0.482 ...
 $ SMR      : num  0.661 1.343 1.599 0.935 0 ...
 $ region   : chr  "Pais Vasco" "Pais Vasco" "Pais Vasco" "Pais Vasco" ...
 $ geometry :sfc_MULTIPOLYGON of length 7907; first list element: List of 2
  ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
 - attr(*, "sf_column")= chr "geometry"
 - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA
  ..- attr(*, "names")= chr [1:8] "ID" "name" "area" "perimeter" ...

> W <- bigDM::connect_subgraphs(Carto_SpainMUN, ID.area="ID")$W
Searching for isolated areas:
  1 region(s) with no links

Searching for disjoint connected subgraphs:
 No disjoint connected subgraphs

> dim(W)
[1] 7907 7907
drjphughesjr commented 11 months ago

Many thanks!

On Mon 16 Oct 2023 at 9:34 a.m., Aritz Adin @.***> wrote:

Dear John,

In general, you can compute the adjacency binary matrix of a sf object as

carto.nb <- spdep::poly2nb(carto) W <- spdep::nb2listw(carto.nb, style="B")

However, you will obtain an error message if any of the polygons does not have adjacent areas (as is the case of the object Carto_SpainMUN).

To avoid this issues and always obtain a connected graph, I recommend you to use the bigDM::connect_subgraphs() function:

library(bigDM) data("Carto_SpainMUN") str(Carto_SpainMUN,1) Classes ‘sf’ and 'data.frame': 7907 obs. of 9 variables: $ ID : chr "01001" "01002" "01003" "01004" ... $ name : chr "Alegria-Dulantzi" "Amurrio" "Aramaio" "Artziniega" ... $ area : Units: [m^2] num 19913794 96145595 73338806 27506468 10559721 ... $ perimeter: Units: [m] num 34372 63352 41430 22605 17847 ... $ obs : int 2 28 6 3 0 2 5 2 3 2 ... $ exp : num 3.024 20.846 3.753 3.209 0.482 ... $ SMR : num 0.661 1.343 1.599 0.935 0 ... $ region : chr "Pais Vasco" "Pais Vasco" "Pais Vasco" "Pais Vasco" ... $ geometry :sfc_MULTIPOLYGON of length 7907; first list element: List of 2 ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"

  • attr(*, "sf_column")= chr "geometry"
  • attr(, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA ..- attr(, "names")= chr [1:8] "ID" "name" "area" "perimeter" ...

W <- bigDM::connect_subgraphs(Carto_SpainMUN, ID.area="ID")$W Searching for isolated areas: 1 region(s) with no links

Searching for disjoint connected subgraphs: No disjoint connected subgraphs

dim(W) [1] 7907 7907

— Reply to this email directly, view it on GitHub https://github.com/spatialstatisticsupna/bigDM/issues/2#issuecomment-1764498184, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASMYZ6ZWXFXHALURKHWEHVLX7UZWNAVCNFSM6AAAAAA55UD2G2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRUGQ4TQMJYGQ . You are receiving this because you were mentioned.Message ID: @.***>