knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 10,
  fig.height = 8,
  message = FALSE,
  warning = FALSE
)

Libraries

library(regionaldrivers)
library(magrittr)
library(raster)

Data loading

SSCT_data is loaded with the package. Here is what 10 random rows of it looks like:

SSCT_data %>% dplyr::sample_n(10) %>%
    knitr::kable(digits = 3, format = "html", caption = "SSCT_data") %>% 
    kableExtra::kable_styling(bootstrap_options = c("hover", "condensed")) %>% 
    kableExtra::scroll_box(width = "7in", height = "5in")   

Data transformation

We extract some geology data from CA_geology and SSCT_data.

SSCT_labelled_points <- sp::SpatialPoints(
    cbind(SSCT_data$POINT_X, SSCT_data$POINT_Y), 
    proj4string = sp::CRS('+proj=longlat +datum=WGS84')
)
SSCT_labelled_points <- sp::spTransform(SSCT_labelled_points, crs(CA_geology))
SSCT_data <- SSCT_data %>% dplyr::mutate(
    geology = (SSCT_labelled_points %over% CA_geology) %>% dplyr::pull(GENERAL)
    )
head(SSCT_data)

Bootstrapping

We perform the bootstrapping using bootstrap_freq(). We use set.seed() to ensure reproducibility of the random process.

set.seed(1789)
l_boot <- bootstrap_freq(SSCT_data %>% dplyr::select(c("ward", "geology")) %>% na.omit())
plotly::ggplotly(
    plot_bootstrap_pvalue(l_boot),
    tooltip = c("channel_type", "geology", "p.value")
)   
plotly::ggplotly(
    plot_bootstrap_probability(l_boot),
    tooltip = c("channel_type", "number_groupings", "probability")
)   


hrvg/regionaldrivers documentation built on June 20, 2021, 7:50 a.m.