stgam

Space Time GAMs: Spatially and Temporally Varying Coefficient Models Using GAMs

https://github.com/lexcomber/stgam

Science Score: 39.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 6 DOI reference(s) in README
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.3%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Space Time GAMs: Spatially and Temporally Varying Coefficient Models Using GAMs

Basic Info
  • Host: GitHub
  • Owner: lexcomber
  • License: other
  • Language: R
  • Default Branch: master
  • Size: 2.37 MB
Statistics
  • Stars: 3
  • Watchers: 1
  • Forks: 3
  • Open Issues: 2
  • Releases: 0
Created about 2 years ago · Last pushed 11 months ago
Metadata Files
Readme Changelog License

README.md

stgam: Spatially and Temporally Varying Coefficient Models Using Generalized Additive Models (GAMs)

R-CMD-check <!-- badges: end -->

This package provides a framework for specifying spatially, temporally and spatially-and-temporally varying coefficient models using Generalized Additive Models (GAMs) with smooths. It builds on GAM functionality from the mgcv package. The smooths are parameterised with location, time and predictor variables. The framework supports the investigation of the presence and nature of any space-time dependencies in the data by evaluating multiple model forms (specifications) using a Generalized Cross-Validation (GCV) score. The workflow sequence is to i) Prepare the data (data.frame, tibble or sf object) by lengthening it to have a single location and time variables for each observation. ii) Evaluate all possible spatial and/or temporal models in which each predictor is specified in different ways. iii) Evaluate the models via their GCV score and to pick the best model (the one with the lowest GCV). iv) Create the final model. v) Calculate the varying coefficient estimates to quantify how the relationships between the target and predictor variables vary over space, time or space-time. vi) Create maps, time series plots etc. For more details see: Comber et al (2023) [https://doi.org/10.4230/LIPIcs.GIScience.2023.22], Comber et al (2024) [https://doi.org/10.1080/13658816.2023.2270285] and Comber et al (2004) [https://doi.org/10.3390/ijgi13120459].

Installation

You can install the CRAN version of stgam : r install.packages("stgam") Or the development version: ``` r

just the package

remotes::install_github("lexcomber/stgam")

with the vignettes - takes a bit longer

remotes::installgithub("lexcomber/stgam", buildvignettes = TRUE, force = T) ```

Example

This code below loads the package and undertakes the proposed workflow for a spatially varying coefficient model using GAMs with spatial smooths:

``` r

a spatially varying coefficient model example

library(stgam) library(dplyr) library(ggplot2) library(cols4all)

define input data

data("hpdata") inputdata <- hp_data |> # create Intercept as an addressable term mutate(Intercept = 1)

evaluate different model forms

svcmods <- evaluatemodels( inputdata = inputdata, targetvar = "priceper", vars = c("pef", "beds"), coordsx = "X", coordsy = "Y", VCtype = "SVC", time_var = NULL, ncores = 2 )

rank the models

modcomp <- gammodelrank(svcmods)

have a look

mod_comp |> select(-f)

select best model

f = as.formula(mod_comp$f[1])

put into a mgcv GAM model

gam.m = gam(f, data = input_data)

calculate the Varying Coefficients

terms = c("Intercept", "pef") vcs = calculatevcs(inputdata, gam.m, terms) vcs |> select(priceper, yot, X, Y, startswith(c("b", "se_")), yhat)

map them

data(lb) tit <-expression(paste(""beta[pef]"")) ggplot() + geomsf(data = lb, col = "lightgrey") + geompoint(data = vcs, aes(x = X, y = Y, col = bpef)) + scalecolourcontinuousc4adiv("brewer.rdylbu", name = tit) + themebw() + coord_sf() + xlab("") + ylab("")

```

Owner

  • Name: Lex Comber
  • Login: lexcomber
  • Kind: user
  • Location: 52.9682879, -1.158318 (approx)
  • Company: University of Leeds

GitHub Events

Total
  • Issues event: 3
  • Watch event: 3
  • Delete event: 2
  • Issue comment event: 2
  • Push event: 37
  • Pull request event: 2
  • Create event: 2
Last Year
  • Issues event: 3
  • Watch event: 3
  • Delete event: 2
  • Issue comment event: 2
  • Push event: 37
  • Pull request event: 2
  • Create event: 2

Packages

  • Total packages: 1
  • Total downloads:
    • cran 205 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 7
  • Total maintainers: 1
cran.r-project.org: stgam

Spatially and Temporally Varying Coefficient Models Using Generalized Additive Models

  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 205 Last month
Rankings
Dependent packages count: 28.7%
Dependent repos count: 35.3%
Average: 50.2%
Downloads: 86.5%
Maintainers (1)
Last synced: 10 months ago

Dependencies

.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v4 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
DESCRIPTION cran
  • R >= 2.10 depends
  • cols4all * imports
  • cowplot * imports
  • doParallel * imports
  • dplyr * imports
  • ggplot2 * imports
  • glue * imports
  • metR * imports
  • mgcv * imports
  • purrr * imports
  • sf * imports
  • tidyr * imports
  • knitr * suggests
  • rmarkdown * suggests
  • testthat >= 3.0.0 suggests