Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified man/figures/cisp/plot_g1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/cisp/plot_g2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
204 changes: 57 additions & 147 deletions vignettes/cisp.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,166 +21,76 @@ library(cisp)

## Spatial pattern correlation

Using the same data as [the gdverse idsa vignette](https://stscl.github.io/gdverse/articles/idsa.html):
Using the same data as [the gdverse opgd vignette](https://stscl.github.io/gdverse/articles/opgd.html). Since the `spc` function in CISP requires all input variables to be continuous, only continuous variables are retained in the data:


``` r
depression = system.file('extdata/Depression.csv',package = 'gdverse') |>
readr::read_csv() |>
sf::st_as_sf(coords = c('X','Y'), crs = 4326)
## Rows: 1072 Columns: 13
## ── Column specification ───────────────────────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (13): X, Y, Depression_prevelence, PopulationDensity, Population65, NoHealthInsurance, Neig...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
depression
## Simple feature collection with 1072 features and 11 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -83.1795 ymin: 32.11464 xmax: -78.6023 ymax: 35.17354
## Geodetic CRS: WGS 84
## # A tibble: 1,072 × 12
## Depression_prevelence PopulationDensity Population65 NoHealthInsurance Neighbor_Disadvantage
## * <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 23.1 61.5 22.5 7.98 -0.0525
## 2 22.8 58.3 16.8 11.0 -0.254
## 3 23.2 35.9 24.5 9.31 -0.0540
## 4 21.8 76.1 21.8 13.2 0.0731
## 5 20.7 47.3 22.0 11 0.763
## 6 21.3 32.5 19.2 13.0 0.422
## 7 22 36.9 19.2 10.8 0.113
## 8 21.2 61.5 15.9 8.57 -0.154
## 9 22.7 67.2 15.7 17.8 -0.320
## 10 20.6 254. 11.3 12.7 0.457
## # ℹ 1,062 more rows
## # ℹ 7 more variables: Beer <dbl>, MentalHealthPati <dbl>, NatureParks <dbl>, Casinos <dbl>,
## # DrinkingPlaces <dbl>, X.HouseRent <dbl>, geometry <POINT [°]>
ndvi = gdverse::ndvi
ndvi
## # A tibble: 713 × 7
## NDVIchange Climatezone Mining Tempchange Precipitation GDP Popdensity
## <dbl> <chr> <fct> <dbl> <dbl> <dbl> <dbl>
## 1 0.116 Bwk low 0.256 237. 12.6 1.45
## 2 0.0178 Bwk low 0.273 214. 2.69 0.801
## 3 0.138 Bsk low 0.302 449. 20.1 11.5
## 4 0.00439 Bwk low 0.383 213. 0 0.0462
## 5 0.00316 Bwk low 0.357 205. 0 0.0748
## 6 0.00838 Bwk low 0.338 201. 0 0.549
## 7 0.0335 Bwk low 0.296 210. 11.9 1.63
## 8 0.0387 Bwk low 0.230 236. 30.2 4.99
## 9 0.0882 Bsk low 0.214 342. 241 20.0
## 10 0.0690 Bsk low 0.245 379. 42.0 7.50
## # ℹ 703 more rows
ndvi = dplyr::select(ndvi,-c(Climatezone,Mining))
ndvi
## # A tibble: 713 × 5
## NDVIchange Tempchange Precipitation GDP Popdensity
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 0.116 0.256 237. 12.6 1.45
## 2 0.0178 0.273 214. 2.69 0.801
## 3 0.138 0.302 449. 20.1 11.5
## 4 0.00439 0.383 213. 0 0.0462
## 5 0.00316 0.357 205. 0 0.0748
## 6 0.00838 0.338 201. 0 0.549
## 7 0.0335 0.296 210. 11.9 1.63
## 8 0.0387 0.230 236. 30.2 4.99
## 9 0.0882 0.214 342. 241 20.0
## 10 0.0690 0.245 379. 42.0 7.50
## # ℹ 703 more rows
```


``` r
system.time({
g = cisp::spc(depression,cores = 12)
g = cisp::spc(ndvi,cores = 6)
})
## user system elapsed
## 6.07 0.86 2018.65
## 1.14 0.30 23.16
g
## *** Spatial Pattern Correlation
##
## | xv | yv | correlation |
## |:---------------------:|:---------------------:|:-----------:|
## | PopulationDensity | Depression_prevelence | 0.04614 |
## | Population65 | Depression_prevelence | 0.04150 |
## | Neighbor_Disadvantage | Depression_prevelence | 0.03924 |
## | DrinkingPlaces | Depression_prevelence | 0.01485 |
## | NoHealthInsurance | Depression_prevelence | 0.01384 |
## | NatureParks | Depression_prevelence | 0.01239 |
## | MentalHealthPati | Depression_prevelence | 0.01042 |
## | X.HouseRent | Depression_prevelence | 0.00777 |
## | Beer | Depression_prevelence | 0.00191 |
## | Casinos | Depression_prevelence | -0.00708 |
## | X.HouseRent | PopulationDensity | 0.07832 |
## | MentalHealthPati | PopulationDensity | 0.01587 |
## | DrinkingPlaces | PopulationDensity | 0.01484 |
## | Population65 | PopulationDensity | 0.01037 |
## | NoHealthInsurance | PopulationDensity | 0.00619 |
## | NatureParks | PopulationDensity | 0.00528 |
## | Beer | PopulationDensity | 0.00115 |
## | Casinos | PopulationDensity | 0.00108 |
## | Neighbor_Disadvantage | PopulationDensity | -0.00529 |
## | Depression_prevelence | PopulationDensity | -0.07737 |
## | X.HouseRent | Population65 | 0.08942 |
## | Neighbor_Disadvantage | Population65 | 0.04196 |
## | PopulationDensity | Population65 | 0.02396 |
## | Depression_prevelence | Population65 | 0.02231 |
## | MentalHealthPati | Population65 | 0.00562 |
## | DrinkingPlaces | Population65 | 0.00349 |
## | NoHealthInsurance | Population65 | 0.00346 |
## | Beer | Population65 | -0.00529 |
## | NatureParks | Population65 | -0.00766 |
## | Casinos | Population65 | -0.00976 |
## | Neighbor_Disadvantage | NoHealthInsurance | 0.11050 |
## | X.HouseRent | NoHealthInsurance | 0.06270 |
## | Population65 | NoHealthInsurance | 0.02928 |
## | PopulationDensity | NoHealthInsurance | 0.02298 |
## | DrinkingPlaces | NoHealthInsurance | 0.01302 |
## | Casinos | NoHealthInsurance | 0.00775 |
## | MentalHealthPati | NoHealthInsurance | 0.00657 |
## | Beer | NoHealthInsurance | 0.00434 |
## | NatureParks | NoHealthInsurance | 0.00197 |
## | Depression_prevelence | NoHealthInsurance | -0.00779 |
## | DrinkingPlaces | Neighbor_Disadvantage | 0.09369 |
## | NoHealthInsurance | Neighbor_Disadvantage | 0.06840 |
## | X.HouseRent | Neighbor_Disadvantage | 0.06004 |
## | NatureParks | Neighbor_Disadvantage | 0.01924 |
## | Population65 | Neighbor_Disadvantage | 0.01867 |
## | MentalHealthPati | Neighbor_Disadvantage | 0.01157 |
## | Casinos | Neighbor_Disadvantage | 0.00541 |
## | PopulationDensity | Neighbor_Disadvantage | -0.00357 |
## | Depression_prevelence | Neighbor_Disadvantage | -0.00665 |
## | Beer | Neighbor_Disadvantage | -0.00989 |
## | Casinos | Beer | 0.04989 |
## | Population65 | Beer | 0.01780 |
## | DrinkingPlaces | Beer | 0.01469 |
## | NatureParks | Beer | 0.01295 |
## | Neighbor_Disadvantage | Beer | 0.00331 |
## | PopulationDensity | Beer | 0.00211 |
## | MentalHealthPati | Beer | 0.00161 |
## | X.HouseRent | Beer | -0.00016 |
## | NoHealthInsurance | Beer | -0.00306 |
## | Depression_prevelence | Beer | -0.03499 |
## | DrinkingPlaces | MentalHealthPati | 0.07590 |
## | PopulationDensity | MentalHealthPati | 0.03785 |
## | NatureParks | MentalHealthPati | 0.03208 |
## | Neighbor_Disadvantage | MentalHealthPati | 0.02471 |
## | Casinos | MentalHealthPati | 0.02460 |
## | Beer | MentalHealthPati | 0.01057 |
## | Population65 | MentalHealthPati | 0.00982 |
## | X.HouseRent | MentalHealthPati | 0.00799 |
## | Depression_prevelence | MentalHealthPati | -0.01049 |
## | NoHealthInsurance | MentalHealthPati | -0.01681 |
## | DrinkingPlaces | NatureParks | 0.07349 |
## | MentalHealthPati | NatureParks | 0.03486 |
## | X.HouseRent | NatureParks | 0.02807 |
## | Neighbor_Disadvantage | NatureParks | 0.02704 |
## | PopulationDensity | NatureParks | 0.01846 |
## | NoHealthInsurance | NatureParks | 0.01689 |
## | Beer | NatureParks | 0.01029 |
## | Casinos | NatureParks | 0.00842 |
## | Population65 | NatureParks | -0.01961 |
## | Depression_prevelence | NatureParks | -0.06237 |
## | DrinkingPlaces | Casinos | 0.05319 |
## | Population65 | Casinos | 0.03494 |
## | Beer | Casinos | 0.02488 |
## | NatureParks | Casinos | 0.01989 |
## | MentalHealthPati | Casinos | 0.01854 |
## | Neighbor_Disadvantage | Casinos | 0.00293 |
## | NoHealthInsurance | Casinos | 0.00009 |
## | PopulationDensity | Casinos | -0.00207 |
## | X.HouseRent | Casinos | -0.00864 |
## | Depression_prevelence | Casinos | -0.01344 |
## | NatureParks | DrinkingPlaces | 0.10000 |
## | MentalHealthPati | DrinkingPlaces | 0.04482 |
## | PopulationDensity | DrinkingPlaces | 0.03366 |
## | Casinos | DrinkingPlaces | 0.02222 |
## | Beer | DrinkingPlaces | 0.01330 |
## | NoHealthInsurance | DrinkingPlaces | 0.00258 |
## | X.HouseRent | DrinkingPlaces | 0.00185 |
## | Neighbor_Disadvantage | DrinkingPlaces | -0.00400 |
## | Depression_prevelence | DrinkingPlaces | -0.01162 |
## | Population65 | DrinkingPlaces | -0.03072 |
## | PopulationDensity | X.HouseRent | 0.12494 |
## | Neighbor_Disadvantage | X.HouseRent | 0.08995 |
## | Population65 | X.HouseRent | 0.04227 |
## | NoHealthInsurance | X.HouseRent | 0.01481 |
## | DrinkingPlaces | X.HouseRent | 0.00667 |
## | MentalHealthPati | X.HouseRent | -0.00175 |
## | Casinos | X.HouseRent | -0.00581 |
## | Depression_prevelence | X.HouseRent | -0.00587 |
## | Beer | X.HouseRent | -0.00692 |
## | NatureParks | X.HouseRent | -0.01047 |
## | xv | yv | correlation |
## |:-------------:|:-------------:|:-----------:|
## | Precipitation | NDVIchange | 0.39517 |
## | Tempchange | NDVIchange | 0.01905 |
## | Popdensity | NDVIchange | 0.00483 |
## | GDP | NDVIchange | -0.02158 |
## | Precipitation | Tempchange | 0.07679 |
## | NDVIchange | Tempchange | 0.04977 |
## | Popdensity | Tempchange | 0.01516 |
## | GDP | Tempchange | -0.01466 |
## | NDVIchange | Precipitation | 0.35303 |
## | Popdensity | Precipitation | 0.01140 |
## | Tempchange | Precipitation | -0.00265 |
## | GDP | Precipitation | -0.02745 |
## | Popdensity | GDP | 0.29824 |
## | Tempchange | GDP | 0.09282 |
## | NDVIchange | GDP | 0.08061 |
## | Precipitation | GDP | 0.04213 |
## | GDP | Popdensity | 0.15481 |
## | Tempchange | Popdensity | 0.04483 |
## | NDVIchange | Popdensity | 0.00442 |
## | Precipitation | Popdensity | -0.07190 |
```

The results are visualized in a default network graph style:
Expand Down
18 changes: 9 additions & 9 deletions vignettes/cisp.rmd.orig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ vignette: >
knitr::opts_chunk$set(
collapse = TRUE,
fig.path = "man/figures/cisp/",
fig.dpi = 150
fig.dpi = 100
)
```

Expand All @@ -27,30 +27,30 @@ library(cisp)

## Spatial pattern correlation

Using the same data as [the gdverse idsa vignette](https://stscl.github.io/gdverse/articles/idsa.html):
Using the same data as [the gdverse opgd vignette](https://stscl.github.io/gdverse/articles/opgd.html). Since the `spc` function in CISP requires all input variables to be continuous, only continuous variables are retained in the data:

```{r load_data}
depression = system.file('extdata/Depression.csv',package = 'gdverse') |>
readr::read_csv() |>
sf::st_as_sf(coords = c('X','Y'), crs = 4326)
depression
ndvi = gdverse::ndvi
ndvi
ndvi = dplyr::select(ndvi,-c(Climatezone,Mining))
ndvi
```

```{r run_g}
system.time({
g = cisp::spc(depression,cores = 12)
g = cisp::spc(ndvi,cores = 6)
})
g
```

The results are visualized in a default network graph style:

```{r plot_g1,fig.width=8.05,fig.height=4.05,fig.cap=knitr::asis_output("**Figure 1**. Spatial Pattern Correlation Network Visualization Results")}
```{r plot_g1,fig.width=5,fig.height=3.55,fig.cap=knitr::asis_output("**Figure 1**. Spatial Pattern Correlation Network Visualization Results")}
plot(g)
```

But the results can also be plotted using the classic correlation coefficient matrix visualization style:

```{r plot_g2,fig.width=8.05,fig.height=7.55,fig.cap=knitr::asis_output("**Figure 2**. Spatial Pattern Correlation Matrix Visualization Results")}
```{r plot_g2,fig.width=5,fig.height=3.55,fig.cap=knitr::asis_output("**Figure 2**. Spatial Pattern Correlation Matrix Visualization Results")}
plot(g,style = "matrix")
```
Loading