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.
- 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
# Install pak if needed
if (!requireNamespace("pak", quietly = TRUE)) {
install.packages("pak")
}
# Install soilquality
pak::pak("ccarbajal16/soilquality")# Install devtools if needed
if (!requireNamespace("devtools", quietly = TRUE)) {
install.packages("devtools")
}
# Install soilquality
devtools::install_github("ccarbajal16/soilquality")# Coming soon
install.packages("soilquality")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)# Use standard property set
result <- compute_sqi_properties(
data = soil_ucayali,
properties = soil_property_sets$standard
)# 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
)# 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
)# Start Shiny app for GUI-based analysis
run_sqi_app()read_soil_csv()- Import soil data from CSV filesstandardize_numeric()- Z-score standardization of numeric columnsto_numeric()- Safe type conversion
pca_select_mds()- PCA-based minimum data set selection
ahp_weights()- Calculate weights from pairwise comparison matrixcreate_ahp_matrix()- Interactive or programmatic matrix creationratio_to_saaty()- Convert importance ratios to Saaty scale
score_higher_better()- Normalize properties where higher is betterscore_lower_better()- Normalize properties where lower is betterscore_optimum()- Normalize properties with optimal rangescore_threshold()- Custom piecewise scoringscore_indicators()- Apply scoring to multiple indicators
higher_better()- Constructor for higher-is-better ruleslower_better()- Constructor for lower-is-better rulesoptimum_range()- Constructor for optimal range rulesthreshold_scoring()- Constructor for threshold-based rules
soil_property_sets- Pre-defined property collectionsstandard_scoring_rules()- Automatic rule assignment
compute_sqi()- File-based workflowcompute_sqi_df()- In-memory workflowcompute_sqi_properties()- Enhanced workflow with property selection
plot.sqi_result()- S3 plot method with multiple typesplot_sqi_report()- Multi-panel visualization report
run_sqi_app()- Launch Shiny application
Comprehensive documentation is available through:
-
Vignettes:
- Introduction to soilquality - Basic workflow and concepts
- Advanced Usage - Custom scoring and property selection
- AHP Matrices Guide - Creating and interpreting pairwise comparisons
-
Function Reference: Access help for any function with
?function_name -
Package Website: https://ccarbajal16.github.io/soilquality
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
Contributions are welcome! Please feel free to submit a Pull Request or open an Issue for:
- Bug reports
- Feature requests
- Documentation improvements
- Code contributions
Please report issues at: https://github.com/ccarbajal16/soilquality/issues
For questions and discussions, use the GitHub Discussions page.
This package is licensed under the MIT License. See the LICENSE file for details.
This package implements methodologies from soil quality assessment literature, including PCA-based MDS selection and AHP weighting approaches widely used in soil science research.