{"id":19859467,"url":"https://github.com/spatlyu/specula","last_synced_at":"2025-06-15T02:10:00.105Z","repository":{"id":239411885,"uuid":"798531955","full_name":"SpatLyu/spEcula","owner":"SpatLyu","description":"Spatial Prediction Methods In R","archived":false,"fork":false,"pushed_at":"2024-06-28T16:14:55.000Z","size":16298,"stargazers_count":21,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-02T02:39:05.330Z","etag":null,"topics":["geoinformatics","giscience","r","spatial-analysis","spatial-predictions","spatial-statistics"],"latest_commit_sha":null,"homepage":"https://spatlyu.github.io/spEcula/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SpatLyu.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-10T01:02:48.000Z","updated_at":"2025-01-19T09:24:51.000Z","dependencies_parsed_at":"2024-05-30T06:28:21.854Z","dependency_job_id":null,"html_url":"https://github.com/SpatLyu/spEcula","commit_stats":null,"previous_names":["spatlyu/specula"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SpatLyu/spEcula","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpatLyu%2FspEcula","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpatLyu%2FspEcula/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpatLyu%2FspEcula/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpatLyu%2FspEcula/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SpatLyu","download_url":"https://codeload.github.com/SpatLyu/spEcula/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpatLyu%2FspEcula/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259910742,"owners_count":22930713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["geoinformatics","giscience","r","spatial-analysis","spatial-predictions","spatial-statistics"],"created_at":"2024-11-12T14:27:18.102Z","updated_at":"2025-06-15T02:10:00.088Z","avatar_url":"https://github.com/SpatLyu.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"##\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\",\n  warning = FALSE,\n  message = FALSE\n)\n```\n\n# spEcula \u003cimg src=\"man/figures/logo.png\" align=\"right\" height=\"90\"/\u003e\n\n\u003c!-- badges: start --\u003e\n\n[![CRAN](https://www.r-pkg.org/badges/version/spEcula)](https://CRAN.R-project.org/package=spEcula)\n[![r-universe](https://spatlyu.r-universe.dev/badges/spEcula)](https://spatlyu.r-universe.dev/spEcula)\n\n\u003c!-- badges: end --\u003e\n\nThe goal of **spEcula** is to make it easier to use **R** for **spatial prediction** based on **various spatial relationships** (e.g. spatial dependence, spatial heterogeneity and geographical similarity).\n\n## Overview\n\nFull document of the most recent release of **spEcula** is online:\n\u003chttps://spatlyu.github.io/spEcula/\u003e\n\nCurrent models and functions provided by **spEcula** are:\n\n|   **spatial prediction method**   |   **spEcula function**   |   **support status**   |\n|-----------------------------------|--------------------------|------------------------|\n|  Geographically Optimal Similarity  |        `gos()`         |          ✔️        |\n|  Sandwich Mapping Model  |        `sandwich()`         |          ✔️        |\n\n\n## Installation\n\nYou can install the development version of *spEcula* from [*github*](https://github.com/SpatLyu/spEcula):\n\n``` r\n# install.packages(\"devtools\")\ndevtools::install_github(\"SpatLyu/spEcula\",\n                         build_vignettes = T,\n                         dep = T)\n```\n\nor install *spEcula* from [*r-universe*](https://spatlyu.r-universe.dev/spEcula):\n\n```r\ninstall.packages('spEcula',\n                 repos = c(\"https://spatlyu.r-universe.dev\",\n                           \"https://cran.rstudio.com/\"),\n                 dep = TRUE)\n```\n\n## Example\n\n### Geographically Optimal Similarity (GOS) model\n\n```{r example_gos}\nlibrary(spEcula)\ndata(zn)\ndata(grid)\n\nzn$Zn = log(zn$Zn)\ntictoc::tic()\ng1 = gos(Zn ~ Slope + Water + NDVI  + SOC + pH + Road + Mine,\n         data = zn, newdata = grid, kappa = 0.08,cores = 6)\ntictoc::toc()\ng1$pred = exp(g1$pred)\ngrid$pred = g1$pred\ngrid$uc99 = g1$`uncertainty99`\ng1\n```\n\n```{r}\nlibrary(ggplot2)\nlibrary(cowplot)\nlibrary(viridis)\n```\n\n\n```{r gos_result,fig.width=9.5,fig.height=3.5}\nf1 = ggplot(grid, aes(x = Lon, y = Lat, fill = pred)) +\n  geom_tile() +\n  scale_fill_viridis(option=\"magma\", direction = -1) + \n  coord_equal() +\n  labs(fill='Prediction') +\n  theme_bw() \nf2 = ggplot(grid, aes(x = Lon, y = Lat, fill = uc99)) +\n  geom_tile() +\n  scale_fill_viridis(option=\"mako\", direction = -1) + \n  coord_equal() +\n  labs(fill=bquote(Uncertainty~(zeta==0.99))) +\n  theme_bw() \n\nplot_grid(f1,f2,nrow = 1,label_fontfamily = 'serif',\n          labels = paste0('(',letters[1:2],')'),\n          label_fontface = 'plain',label_size = 10,\n          hjust = -1.5,align = 'hv')  -\u003e p\np\n```\n\n### Sandwich Mapping Model\n\n```{r sandwich,fig.width=5.5,fig.height=3.5}\nlibrary(sf)\nlibrary(tidyverse)\nlibrary(spEcula)\nsimpath = system.file(\"extdata\", \"sim.gpkg\", package=\"spEcula\")\nsampling = read_sf(simpath,layer = 'sim_sampling')\nssh = read_sf(simpath,layer = 'sim_ssh')\nreporting = read_sf(simpath,layer = 'sim_reporting')\n\nsampling_zone = sampling %\u003e%\n    st_join(ssh['X']) %\u003e%\n    st_drop_geometry()\n\nlibrary(ggpubr)\n\nggerrorplot(sampling_zone, x = \"X\", y = \"Value\",\n            desc_stat = \"mean_sd\", color = \"black\",\n            add = \"violin\", add.params = list(color = \"darkgray\")) +\n  geom_text(data = summarise(sampling_zone,vmean = mean(Value),.by = X), \n            aes(x = X, y = vmean, label = round(vmean,2)), \n            vjust = -0.5, hjust = -0.15, color = \"black\",size = 3) +\n  scale_x_discrete(labels = LETTERS[1:4]) +\n  theme(axis.title.x = element_blank())\n\nsim_est = sandwich(sampling = sampling,stratification = ssh,reporting = reporting,\n                   sampling_attr = 'Value',ssh_zone = 'X',reporting_id = 'Y',\n                   weight_type = 'area')\nsim_est\n```\n\n```{r sandwich_sim_est,fig.width=9.75, fig.height=3.5}\nlibrary(cowplot) \n\nf1 = ggplot(data = sim_est, aes(fill = sandwichest_mean), \n            color = \"darkgray\") +\n  geom_sf() + \n  labs(fill='mean') +\n  scale_fill_gradient(low = \"#f0bc9c\", high = \"red\",\n                      breaks = range(sim_est$sandwichest_mean)) +\n  theme_bw() +\n  theme(\n    axis.text = element_blank(),\n    axis.ticks = element_blank(),\n    axis.title = element_blank(),\n    panel.grid = element_blank(),\n    legend.position = 'right',\n    legend.background = element_rect(fill = 'transparent',color = NA)\n  )\n\nf2 = ggplot(data = sim_est, aes(fill = sandwichest_standarderror), \n            color = \"darkgray\") +\n  geom_sf() + \n  labs(fill='se') +\n  scale_fill_gradient(low = \"#b6edf0\", high = \"blue\",\n                      breaks = range(sim_est$sandwichest_standarderror)) +\n  theme_bw() +\n  theme(\n    axis.text = element_blank(),\n    axis.ticks = element_blank(),\n    axis.title = element_blank(),\n    panel.grid = element_blank(),\n    legend.position = 'right',\n    legend.background = element_rect(fill = 'transparent',color = NA)\n  )\n\nplot_grid(f1, f2, nrow = 1,label_fontfamily = 'serif',\n          labels = paste0('(',letters[1:4],')'),\n          label_fontface = 'plain',label_size = 10,\n          hjust = 0.05,align = 'hv')  -\u003e p\np\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatlyu%2Fspecula","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatlyu%2Fspecula","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatlyu%2Fspecula/lists"}