gwr: Geographically Weighted Regression

gwrR Documentation

Geographically Weighted Regression

Description

Geographically Weighted Regression

Usage

gwr(.ref, ...)

## S3 method for class 'character'
gwr(
  .ref,
  ...,
  .tar,
  coordinates = smpds::CRU_coords,
  res = 0.5,
  xy_buffer = 1.5,
  z_buffer = NA,
  cpus = 1,
  bandwidth = 1.06,
  varid = NULL
)

## S3 method for class 'numeric'
gwr(
  .ref,
  ...,
  .tar,
  coordinates = smpds::CRU_coords,
  res = 0.5,
  xy_buffer = 1.5,
  z_buffer = NA,
  cpus = 1,
  bandwidth = 1.06
)

Arguments

.ref

Reference data from which the data will be interpolated (see the details section).

...

arguments to be passed to other functions

.tar

Table with geographical target data, including: latitude, longitude and elevation.

coordinates

Reference data set with columns for latitude, longitude and elevation. Default: CRU_coords.

res

Numeric value for the mask resolution. Default: 0.5 degrees.

xy_buffer

Numeric value to be used as the boundary for the search area in the x and y axes.

  • latitude < .tar$latitude + xy_buffer

  • latitude > .tar$latitude - xy_buffer

  • longitude < .tar$longitude + xy_buffer

  • longitude > .tar$longitude - xy_buffer

z_buffer

Numeric value to be used as the boundary for the search area in the z axis:

  • elevation <= .tar$elevation * z_buffer

  • elevation >= .tar$elevation / z_buffer

cpus

Number of CPUs to be used in parallel, default = 1.

bandwidth

bandwidth used in the weighting function, possibly calculated by gwr.sel

varid

String with the identifier of the main variable inside the NetCDF file pointed by .ref (if applicable).

Details

The input reference data can be in any of the following formats:

  • Matrix: this should be a 3-dimensional object with spatial components (latitude and longitude) and a temporal component for representing each time step to be used for the extraction of the data.

  • String: this should point to a valid path on disk where the reference NetCDF file is stored. Note that the parameter called varid should be used to indicate the identifier of the main variable inside the NetCDF file (e.g., "tmp", "pre", "cld", etc.).

Value

Table with interpolated values from the .ref data for each record/row in .tar.

Source

This function was adapted from a code developed by Yunke Peng (yunke.peng@usys.ethz.ch) - ETH Zürich: https://github.com/yunkepeng/gwr

References

Peng, Y., Bloomfield, K.J. and Prentice, I.C., 2020. A theory of plant function helps to explain leaf‐trait and productivity responses to elevation. New Phytologist, 226(5), pp.1274-1284. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/nph.16447")}

Examples

## Not run: 
`%>%` <- magrittr::`%>%`
data <- tibble::tibble(entity_name = "University of Reading",
                       latitude = 51.44140,
                       longitude = -0.9418,
                       elevation = c(61, 161, 261, 361))
smpds::gwr(.ref = "/path/to/reference-tmp.nc",
           .tar = data,
           varid = "tmp")

ncin <- ncdf4::nc_open("/path/to/reference-tmp.nc")
reference_data <- ncdf4::ncvar_get(ncin, varid)
ncdf4::nc_close(ncin)
reference_data %>%
  smpds::gwr(.tar = data)

## End(Not run)

special-uor/smpds documentation built on July 9, 2024, 5:39 p.m.