Package 'heterogen'

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

Help Index


bg_transpose

Description

Transpose of a matrix based on row or column index.

Usage

bg_transpose(mat, byrow = FALSE)

Arguments

mat

A Matrix.

byrow

FALSE computes based on row index. TRUE computes based on column index.

Value

A matrix transposed.


distance_weighted_gauss

Description

Weighted Distance based on Gaussian function

Usage

distance_weighted_gauss(coord_xy, point_xy, tau)

Arguments

coord_xy

A Matrix with lon/lat coordinates.

point_xy

lon/lat coordinate.

tau

bandwidth.

Value

A vector.


float_relative

Description

Relative sum formula

Usage

float_relative(xx)

Arguments

xx

A Matrix with lon/lat coordinates.

Value

A vector.


float_round

Description

Rouding of Numbers

Usage

float_round(float_n, digits = 0L)

Arguments

float_n

A numeric vector.

digits

integer indicating the number of decimal places .

Value

A vector.


Core Function of GWPCA

Description

The gwpca_core function is a core implementation of Generalized Weighted Principal Component Analysis for each iteration.

Usage

gwpca_core(xy, p_xy, env, env_trans, tau)

Arguments

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 env matrix.

tau

The bandwidth parameter for spatial weighting in GWPCA. It determines the extent of spatial influence on the estimation of principal components.

Value

A vector of eigenvalues from local PCA


Perform GWPCA from data.frame with spatial structure.

Description

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.

Usage

gwpca_df_mc(
  datadf,
  bandwidth = 0.2,
  tolerance = 5,
  nprocess = 10000,
  parallel = FALSE,
  ncores = 2,
  normalized = FALSE,
  method = "iter",
  dirds = "rds"
)

Arguments

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 TRUE, multiple cores will be used for processing. Default is FALSE.

ncores

(Optional) The number of cores to be used for parallel computation. Only applicable if parallel is set to TRUE. Default is 4.

normalized

(Optional) A logical value indicating whether the input data should be normalized before performing GWPCA. Default is FALSE, meaning the data will not be normalized. Take in account that core function performs correlation analysis in order to normalize the input variables.

method

The method used for GWPCA computation. It can take one of the following values. local Performs GWPCA locally and will save each iteration on .rds files. Recommended for large-scale data sets. inter Uses RAM memory to . Default is inter.

dirds

(Optional) The directory where the results will be saved in RDS format. Default is rds.

Value

A matrix of eigenvalues

Examples

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)

Heterogeneity (rasters)

Description

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.

Usage

heterog(
  datastack,
  bandwidth = 0.3,
  tolerance = 5,
  nprocess = 1000,
  parallel = FALSE,
  ncores = 2,
  normalized = FALSE,
  method = "iter",
  dirds = "rds"
)

Arguments

datastack

SpatRaster class. The input raster stack representing environmental variables. Each layer in the stack corresponds to a different environmental variable, and the function calculates heterogeneity based on the variability across these layers.

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 TRUE, multiple cores will be used for processing. Default is FALSE.

ncores

(Optional) The number of cores to be used for parallel computation. Only applicable if parallel is set to TRUE. Default is 4.

normalized

(Optional) A logical value indicating whether the input data should be normalized before performing GWPCA. Default is FALSE, meaning the data will not be normalized. Take in account that core function performs correlation analysis in order to normalize the input variables.

method

The method used for GWPCA computation. It can take one of the following values. local Performs GWPCA locally and will save each iteration on .rds files. Recommended for large-scale data sets. inter Uses RAM memory to . Default is inter.

dirds

(Optional) The directory where the results will be saved in RDS format. Default is rds.

Value

A SpatHetero object

  • hetero A heterogeneity layer

  • matrix A Matrix of eigenvalues

  • rasters A complete set of heterogeneity layers for each component

Examples

# 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)

matrixcec_square

Description

Matrix Square

Usage

matrixcec_square(X, y)

Arguments

X

A Matrix.

y

A Vector

Value

A matrix.


matrixmult

Description

Matrix Multiplication

Usage

matrixmult(A, B)

Arguments

A

A Matrix.

B

A Matrix

Value

A matrix.


matrixvec_plus

Description

Matrix Multiplication

Usage

matrixvec_plus(X, y)

Arguments

X

A Matrix.

y

A Vector

Value

A matrix.


matrixvec_subs

Description

Matrix Substraction

Usage

matrixvec_subs(X, y)

Arguments

X

A Matrix.

y

A Vector

Value

A matrix.


Plot Heterogeneity Layer

Description

Plot

Usage

## S4 method for signature 'SpatHetero,ANY'
plot(x, comp = NULL, ...)

Arguments

x

SpatHetero Class

comp

integer. Plot specific component of the heterogeneity.

...

Plot parameters forwarded.

Value

No return value, called for side effects.


SpatHetero

Description

SpatHetero

Slots

hetero

A Heterogeneity Layer

matrix

SpatHetero_in data

rasters

A SpatRaster for Each Component