Learn R Programming

SpatPCA: Regularized Principal Component Analysis for Spatial Data

Description

SpatPCA is an R package designed for efficient regularized principal component analysis, providing the following features:

  • Identify dominant spatial patterns (eigenfunctions) with both smooth and localized characteristics.
  • Conduct spatial prediction (Kriging) at new locations.
  • Adapt to regularly or irregularly spaced data, spanning 1D, 2D, and 3D datasets.
  • Implement using the alternating direction method of multipliers (ADMM) algorithm.

Installation

You can install SpatPCA using either of the following methods:

Install from CRAN

install.packages("SpatPCA")

Install the Development Version from GitHub

remotes::install_github("egpivo/SpatPCA")

Compilation Requirements

To compile C++ code with the required RcppArmadillo package, follow these instructions based on your operating system:

For Windows users

Install Rtools

For Mac users

  1. Install Xcode Command Line Tools
  2. Install the gfortran library. You can achieve this by running the following commands in the terminal:
brew update
brew install gcc

For a detailed solution, refer to this link, or download and install the library gfortran to resolve the error ld: library not found for -lgfortran.

Usage

To use SpatPCA, first load the package:

library(SpatPCA)

Then, apply the spatpca function with the following syntax:

spatpca(position, realizations)
  • Input: Realizations with the corresponding positions.
  • Output: Return the most dominant eigenfunctions automatically.

For more details, refer to the Demo.

Development

To submit package checks to R-hub v2, source tools/run_rhub_checks.R and use

submission <- run_rhub_checks(confirmation = TRUE)
summarise_rhub_jobs(submission)

Adjust include_os, platforms, or email as needed. summarise_rhub_jobs() prints the submission id plus GitHub URLs where each builder’s logs appear.

Authors

Maintainer

Wen-Ting Wang (GitHub)

Reference

Wang, W.-T. and Huang, H.-C. (2017). Regularized principal component analysis for spatial data. Journal of Computational and Graphical Statistics, 26, 14-25.

License

GPL (>= 2)

Citation

  • To cite package ‘SpatPCA’ in publications use:
  Wang W, Huang H (2023). SpatPCA: Regularized Principal Component Analysis for
  Spatial Data_. R package version 1.3.5,
  <https://CRAN.R-project.org/package=SpatPCA>.
  • A BibTeX entry for LaTeX users is
  @Manual{,
    title = {SpatPCA: Regularized Principal Component Analysis for Spatial Data},
    author = {Wen-Ting Wang and Hsin-Cheng Huang},
    year = {2023},
    note = {R package version 1.3.5},
    url = {https://CRAN.R-project.org/package=SpatPCA},
  }

Copy Link

Version

Install

install.packages('SpatPCA')

Monthly Downloads

318

Version

1.3.8

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Wen-Ting Wang

Last Published

September 28th, 2025

Functions in SpatPCA (1.3.8)

eigenFunction

Interpolated Eigen-function
spatpca

Regularized PCA for spatial data
spatialPrediction

Internal function: Spatial prediction
spatpcaCV

Internal function: M-fold Cross-validation
fetchUpperBoundNumberEigenfunctions

Internal function: Fetch the upper bound of the number of eigenfunctions
spatpcaCVWithSelectedK

Internal function: M-fold CV of SpatPCA with selected K
scaleLocation

Internal function: Scale one-dimension locations
predict

Spatial predictions on new locations
predictEigenfunction

Spatial dominant patterns on new locations
SpatPCA-package

Regularized Principal Component Analysis for Spatial Data
plot.spatpca

Display the cross-validation results
thinPlateSplineMatrix

Thin-plane spline matrix
detrend

Internal function: Detrend Y by column-wise centering
checkInputData

Internal function: Validate input data for a spatpca object
setNumberEigenfunctions

Internal function: Set the number of eigenfunctions for a spatpca object
setL2

Internal function: Set tuning parameter - l2
setTau1

Internal function: Set tuning parameter - tau1
setCores

Internal helper: validate requested core count
setTau2

Internal function: Set tuning parameter - tau2
setGamma

Internal function: Set tuning parameter - gamma
checkNewLocationsForSpatpcaObject

Internal function: Validate new locations for a spatpca object