Skip to contents

Overview

The soilquality R package provides comprehensive tools for calculating Soil Quality Index (SQI) using scientifically validated methods. The package implements Principal Component Analysis (PCA) for Minimum Data Set (MDS) selection and Analytic Hierarchy Process (AHP) for expert-based weighting, transforming complex soil property data into standardized quality metrics.

Key Features

  • Automated MDS Selection: PCA-based dimensionality reduction to identify key soil indicators
  • Expert Weighting System: AHP methodology with consistency ratio validation
  • Flexible Scoring Functions: Multiple normalization methods for different soil properties
    • Higher-is-better (e.g., organic matter, nutrients)
    • Lower-is-better (e.g., bulk density, electrical conductivity)
    • Optimal range (e.g., pH)
    • Custom threshold-based scoring
  • Pre-defined Property Sets: Standard collections for common soil analyses (basic, standard, comprehensive, physical, chemical, fertility)
  • Standard Scoring Rules: Automatic rule assignment based on property patterns
  • Comprehensive Visualization: Multiple plot types for results interpretation
  • Interactive Shiny Application: GUI for non-programmers
  • Complete Documentation: Vignettes, examples, and function references

Installation

From GitHub (Development Version)

# Install pak if needed
if (!requireNamespace("pak", quietly = TRUE)) {
  install.packages("pak")
}

# Install soilquality
pak::pak("ccarbajal16/soilquality")

Using devtools

# Install devtools if needed
if (!requireNamespace("devtools", quietly = TRUE)) {
  install.packages("devtools")
}

# Install soilquality
devtools::install_github("ccarbajal16/soilquality")

From CRAN (Stable Release)

# Coming soon
install.packages("soilquality")

Quick Start

Basic Workflow

library(soilquality)

# Load example data
data(soil_ucayali)

# Compute SQI with automatic property detection
result <- compute_sqi_properties(
  data = soil_ucayali,
  properties = c("Sand", "Silt", "Clay", "pH", "OM", "P", "K")
)

# View results summary
print(result)

# Visualize SQI distribution
plot(result, type = "distribution")

# Create comprehensive report
plot_sqi_report(result)

Using Pre-defined Property Sets

# Use standard property set
result <- compute_sqi_properties(
  data = soil_ucayali,
  properties = soil_property_sets$standard
)

Custom Scoring Rules

# Define custom scoring for specific properties
custom_rules <- list(
  pH = optimum_range(optimal = 6.5, tolerance = 1),
  OM = higher_better(),
  BD = lower_better(),
  P = threshold_scoring(
    thresholds = c(0, 10, 20, 50),
    scores = c(0, 0.5, 0.8, 1.0)
  )
)

result <- compute_sqi_properties(
  data = soil_ucayali,
  properties = c("pH", "OM", "BD", "P"),
  scoring_rules = custom_rules
)

Interactive AHP Matrix Creation

# Create AHP matrix interactively
indicators <- c("pH", "OM", "P", "K")
ahp_matrix <- create_ahp_matrix(indicators, mode = "interactive")

# Use computed AHP weights in SQI calculation
result <- compute_sqi_properties(
  data = soil_ucayali,
  properties = ahp_matrix$indicators,
  pairwise_matrix = ahp_matrix$weights
)

Launch Interactive Application

# Start Shiny app for GUI-based analysis
run_sqi_app()

Main Functions

Data Handling

PCA and MDS Selection

AHP Weighting

Scoring Functions

Scoring Constructors

Property Sets and Standard Rules

SQI Computation

Visualization

Interactive Tools

Documentation

Comprehensive documentation is available through:

Citation

If you use this package in your research, please cite it as:

citation("soilquality")

Or use:

Carbajal, Carlos (2025). soilquality: Soil Quality Index Calculation with PCA and AHP. R package version 1.0.0. https://github.com/ccarbajal16/soilquality

Contributing

Contributions are welcome! Please feel free to submit a Pull Request or open an Issue for:

  • Bug reports
  • Feature requests
  • Documentation improvements
  • Code contributions

Issues and Support

Please report issues at: https://github.com/ccarbajal16/soilquality/issues

For questions and discussions, use the GitHub Discussions page.

License

This package is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

This package implements methodologies from soil quality assessment literature, including PCA-based MDS selection and AHP weighting approaches widely used in soil science research.