Title: | Spatial Functions for Heterogeneity and Climate Variability |
---|---|
Description: | A comprehensive suite of spatial functions created to analyze and assess data heterogeneity and climate variability in spatial datasets. This package is specifically designed to address the challenges associated with characterizing and understanding complex spatial patterns in environmental and climate-related data. |
Authors: | P.Joser Atauchi [aut, cre], A. Townsend Peterson [ctb] |
Maintainer: | P.Joser Atauchi <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.2.33 |
Built: | 2025-02-05 04:56:20 UTC |
Source: | https://github.com/cran/heterogen |
Transpose of a matrix based on row or column index.
bg_transpose(mat, byrow = FALSE)
bg_transpose(mat, byrow = FALSE)
mat |
A Matrix. |
byrow |
|
A matrix transposed.
Weighted Distance based on Gaussian function
distance_weighted_gauss(coord_xy, point_xy, tau)
distance_weighted_gauss(coord_xy, point_xy, tau)
coord_xy |
A Matrix with lon/lat coordinates. |
point_xy |
lon/lat coordinate. |
tau |
bandwidth. |
A vector.
Relative sum formula
float_relative(xx)
float_relative(xx)
xx |
A Matrix with lon/lat coordinates. |
A vector.
Rouding of Numbers
float_round(float_n, digits = 0L)
float_round(float_n, digits = 0L)
float_n |
A numeric vector. |
digits |
integer indicating the number of decimal places . |
A vector.
The gwpca_core
function is a core implementation of Generalized Weighted Principal Component Analysis for each iteration.
gwpca_core(xy, p_xy, env, env_trans, tau)
gwpca_core(xy, p_xy, env, env_trans, tau)
xy |
A matrix containing the coordinates of the points where environmental measurements were taken. The matrix should have two columns, representing the X and Y coordinates. |
p_xy |
A matrix containing the coordinates of the point GWPCA will be estimated. It should have two columns for X and Y coordinates. |
env |
A data matrix representing the environmental variables. Rows represent observations (points or grid cells), and columns represent environmental variables. |
env_trans |
Transpose of |
tau |
The bandwidth parameter for spatial weighting in GWPCA. It determines the extent of spatial influence on the estimation of principal components. |
A vector of eigenvalues from local PCA
gwpca_df is an R function that performs Generalized Weighted Principal Component Analysis (GWPCA) on a given dataset. This function allow to calculate the environmental heterogeneity from data.frame with spatial structure.
gwpca_df_mc( datadf, bandwidth = 0.2, tolerance = 5, nprocess = 10000, parallel = FALSE, ncores = 2, normalized = FALSE, method = "iter", dirds = "rds" )
gwpca_df_mc( datadf, bandwidth = 0.2, tolerance = 5, nprocess = 10000, parallel = FALSE, ncores = 2, normalized = FALSE, method = "iter", dirds = "rds" )
datadf |
The input data matrix for which GWPCA needs to be performed. It should contain numerical values only. Rows represent cells, and columns represent bioclimatic variables. |
bandwidth |
The bandwidth for the spatial weighting function. |
tolerance |
The tolerance for spatial weight computation. |
nprocess |
(Optional) The number of iterations for calculating the principal components. Default is set to 1000. |
parallel |
(Optional) A logical value indicating whether to run the computation in parallel. If |
ncores |
(Optional) The number of cores to be used for parallel computation. Only applicable if |
normalized |
(Optional) A logical value indicating whether the input data should be normalized before performing GWPCA. Default is |
method |
The method used for GWPCA computation. It can take one of the following values. |
dirds |
(Optional) The directory where the results will be saved in RDS format. Default is |
A matrix of eigenvalues
path_csv <- system.file("extdata","south.csv", package="heterogen") south_csv <- rio::import(path_csv) # notice: south_csv object contains x,y (lot/lat coordinates) # and environmental variables north_het <- gwpca_df_mc(as.matrix(south_csv), parallel = TRUE, ncores = 2, bandwidth = 0.1, tolerance = 10)
path_csv <- system.file("extdata","south.csv", package="heterogen") south_csv <- rio::import(path_csv) # notice: south_csv object contains x,y (lot/lat coordinates) # and environmental variables north_het <- gwpca_df_mc(as.matrix(south_csv), parallel = TRUE, ncores = 2, bandwidth = 0.1, tolerance = 10)
The heterog
function is designed to calculate environmental heterogeneity metric from a raster stack dataset.
This function aids in assessing the spatial variation and diversity of environmental variables within the raster data,
providing valuable insights into the heterogeneity of the study area.
heterog( datastack, bandwidth = 0.3, tolerance = 5, nprocess = 1000, parallel = FALSE, ncores = 2, normalized = FALSE, method = "iter", dirds = "rds" )
heterog( datastack, bandwidth = 0.3, tolerance = 5, nprocess = 1000, parallel = FALSE, ncores = 2, normalized = FALSE, method = "iter", dirds = "rds" )
datastack |
|
bandwidth |
The bandwidth for the spatial weighting function. |
tolerance |
The tolerance for spatial weight computation. |
nprocess |
(Optional) The number of iterations for calculating the principal components. Default is set to 1000. |
parallel |
(Optional) A logical value indicating whether to run the computation in parallel. If |
ncores |
(Optional) The number of cores to be used for parallel computation. Only applicable if |
normalized |
(Optional) A logical value indicating whether the input data should be normalized before performing GWPCA. Default is |
method |
The method used for GWPCA computation. It can take one of the following values. |
dirds |
(Optional) The directory where the results will be saved in RDS format. Default is |
A SpatHetero object
hetero A heterogeneity layer
matrix A Matrix of eigenvalues
rasters A complete set of heterogeneity layers for each component
# Case 01: South path <- system.file("extdata","south", package="heterogen") south_rast <- terra::rast(list.files(path, full.names = TRUE, pattern = '.tif')) south_het <- heterog(south_rast, parallel = TRUE, bandwidth = 0.1, tolerance = 10) plot(south_het) # Case 02: North path <- system.file("extdata","north", package="heterogen") north_rast <- terra::rast(list.files(path, full.names = TRUE, pattern = '.tif')) north_het <- heterog(north_rast, parallel = TRUE, bandwidth = 0.1, tolerance = 10) plot(north_het)
# Case 01: South path <- system.file("extdata","south", package="heterogen") south_rast <- terra::rast(list.files(path, full.names = TRUE, pattern = '.tif')) south_het <- heterog(south_rast, parallel = TRUE, bandwidth = 0.1, tolerance = 10) plot(south_het) # Case 02: North path <- system.file("extdata","north", package="heterogen") north_rast <- terra::rast(list.files(path, full.names = TRUE, pattern = '.tif')) north_het <- heterog(north_rast, parallel = TRUE, bandwidth = 0.1, tolerance = 10) plot(north_het)
Matrix Square
matrixcec_square(X, y)
matrixcec_square(X, y)
X |
A Matrix. |
y |
A Vector |
A matrix.
Matrix Multiplication
matrixmult(A, B)
matrixmult(A, B)
A |
A Matrix. |
B |
A Matrix |
A matrix.
Matrix Multiplication
matrixvec_plus(X, y)
matrixvec_plus(X, y)
X |
A Matrix. |
y |
A Vector |
A matrix.
Matrix Substraction
matrixvec_subs(X, y)
matrixvec_subs(X, y)
X |
A Matrix. |
y |
A Vector |
A matrix.
Plot
## S4 method for signature 'SpatHetero,ANY' plot(x, comp = NULL, ...)
## S4 method for signature 'SpatHetero,ANY' plot(x, comp = NULL, ...)
x |
SpatHetero Class |
comp |
integer. Plot specific component of the heterogeneity. |
... |
Plot parameters forwarded. |
No return value, called for side effects.
SpatHetero
hetero
A Heterogeneity Layer
matrix
SpatHetero_in data
rasters
A SpatRaster for Each Component