## ----setup, include=FALSE----------------------------------------------------- library(SSIMmap) library(sf) library(terra) library(ggplot2) library(patchwork) knitr::opts_chunk$set(message = FALSE, warning = FALSE, collapse = TRUE) ## ----example-data------------------------------------------------------------- data("Toronto_SSIM") data("fwi_0816_bc") data("fwi_0818_bc") data("fwi_1111_bc") aug16 <- terra::unwrap(fwi_0816_bc) aug18 <- terra::unwrap(fwi_0818_bc) nov11 <- terra::unwrap(fwi_1111_bc) nrow(Toronto_SSIM) terra::compareGeom(aug16, aug18, nov11) ## ----bandwidth, fig.width=9, fig.height=4------------------------------------- S1 <- ssim_bandwidth(Toronto_SSIM, "CIMD", "PP", max_bandwidth = 200, transform = "percentile", option = "midpoint") S2 <- ssim_bandwidth(Toronto_SSIM, "CIMD", "Commute", max_bandwidth = 200, transform = "percentile", option = "midpoint") c(deprivation = S1$bandwidth, commuting = S2$bandwidth, square_root = ceiling(sqrt(nrow(Toronto_SSIM)))) p1 <- S1$plot + labs(tag = "a)") + theme(plot.tag = element_text(face = "plain")) p2 <- S2$plot + labs(tag = "b)") + theme(plot.tag = element_text(face = "plain")) (p1 + p2) + plot_layout(guides = "collect") ## ----polygon-local, fig.width=6, fig.height=4--------------------------------- local1 <- ssim_polygon(Toronto_SSIM, "CIMD", "PP", global = FALSE, bandwidth = S1$bandwidth, transform = "percentile", do_test = FALSE) ggplot(local1) + geom_sf(aes(fill = SSIM), colour = NA) + scale_fill_distiller(palette = "PRGn", limits = c(-1, 1)) + theme_void() ## ----polygon-inference, eval=FALSE-------------------------------------------- # global1 <- ssim_polygon(Toronto_SSIM, "CIMD", "PP", global = TRUE, # bandwidth = S1$bandwidth, transform = "percentile", # do_test = TRUE, R = 1000, seed = 1) # global1$p_global # local1_test <- ssim_polygon(Toronto_SSIM, "CIMD", "PP", global = FALSE, # bandwidth = S1$bandwidth, transform = "percentile", # do_test = TRUE, R = 1000, fdr = TRUE, seed = 1) # head(local1_test[, c("SSIM", "SSIM_p", "SSIM_q", "SSIM_sig", # "SIM_p", "SIV_p", "SIP_p")]) ## ----raster-global------------------------------------------------------------ summer <- ssim_raster(aug16, aug18, w = 1, transform = "none") fall <- ssim_raster(aug16, nov11, w = 1, transform = "none") summer$summary fall$summary ## ----raster-local, fig.width=8, fig.height=4---------------------------------- summer_local <- ssim_raster(aug16, aug18, global = FALSE, w = 1, transform = "none") fall_local <- ssim_raster(aug16, nov11, global = FALSE, w = 1, transform = "none") par(mfrow = c(1, 2)) plot(summer_local[["SSIM"]], range = c(-1, 1), main = "16 vs 18 August") plot(fall_local[["SSIM"]], range = c(-1, 1), main = "16 August vs 11 November") ## ----raster-inference, eval=FALSE--------------------------------------------- # fall_test <- ssim_raster(aug16, nov11, global = FALSE, w = 1, # transform = "none", do_test = TRUE, # local_test = TRUE, R = 1000, fdr = TRUE, # seed = 202610281) # plot(fall_test[[c("SSIM_p", "SIM_p", "SIV_p", "SIP_p")]]) ## ----full-manuscript, eval=FALSE---------------------------------------------- # source(system.file("reproduction", "reproduce_manuscript.R", package="SSIMmap")) # reproduce_manuscript("ssim-observed", full=FALSE) # reproduce_manuscript("ssim-full", full=TRUE) ## ----reproduction-files------------------------------------------------------- list.files(system.file("reproduction", package = "SSIMmap")) .