# SQIpro <img src="man/figures/logo.png" align="right" height="140"/>

> **Comprehensive Soil Quality Index Computation and Visualization in R**

[![CRAN status](https://www.r-pkg.org/badges/version/SQIpro)](https://CRAN.R-project.org/package=SQIpro)
[![License: GPL-3](https://img.shields.io/badge/License-GPL--3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

---

## Overview

`SQIpro` provides a complete, modular framework for computing the
**Soil Quality Index (SQI)** — a single numeric score (0–1) integrating
physical, chemical, and biological soil properties.

### Six indexing methods

| Method | Reference | Key feature |
|--------|-----------|-------------|
| **Linear Scoring** | Doran & Parkin (1994) | Simple, equal-weight additive |
| **Regression-based** | Masto et al. (2008) | Weights by regression coefficients |
| **PCA-based** | Andrews et al. (2004) | Data-driven, variance-explained weights |
| **Fuzzy Logic** | Zhu et al. (2010) | Handles uncertainty; geometric mean option |
| **Entropy Weighting** | Shannon (1948) | Objective weights from information content |
| **TOPSIS** | Hwang & Yoon (1981) | Multi-criteria ideal-solution distance |

### Four scoring function types

```
"more"  — Higher is better   ▁▃▅▇█  (e.g., organic carbon)
"less"  — Lower is better    █▇▅▃▁  (e.g., bulk density)
"opt"   — Optimum range      ▁▅█▅▁  (e.g., pH 6.0–7.0)
"trap"  — Trapezoidal        ▁▅███▅▁ (explicit boundaries)
```

---

## Installation

```r
# Install from CRAN
install.packages("SQIpro")
```

---

## Quick Start

```r
library(SQIpro)

# 1. Load data
data(soil_data)

# 2. Define variable configuration
cfg <- make_config(
  variable = c("pH",  "EC",   "BD",   "OC",   "MBC",  "Clay"),
  type     = c("opt", "less", "less", "more", "more", "opt"),
  opt_low  = c(6.0,   NA,     NA,     NA,     NA,     20),
  opt_high = c(7.0,   NA,     NA,     NA,     NA,     35)
)

# 3. Score variables (0–1 transformation)
scored <- score_all(soil_data, cfg, group_cols = c("LandUse", "Depth"))

# 4. Select Minimum Data Set
mds <- select_mds(scored, group_cols = c("LandUse", "Depth"))

# 5. Compute and compare all methods
results <- sqi_compare(scored, cfg,
                        group_cols = c("LandUse", "Depth"),
                        dep_var    = "OC", mds = mds)
print(results)
```

---

## Full Workflow

```
validate_data()  →  make_config()  →  plot_scoring_curves()
       ↓
   score_all()  →  select_mds()
       ↓
  sqi_linear()  sqi_pca()  sqi_regression()
  sqi_fuzzy()   sqi_entropy()  sqi_topsis()
       ↓
  sqi_compare()  →  sqi_anova()  →  sqi_sensitivity()
       ↓
  plot_sqi()  plot_scores()  plot_radar()  plot_sensitivity()
```

---

## References

- Doran, J.W., & Parkin, T.B. (1994). Defining and assessing soil quality. In: Doran, J.W., Coleman, D.C., Bezdicek, D.F., & Stewart, B.A. (Eds.), *Defining Soil Quality for a Sustainable Environment* (pp. 3–21). SSSA Special Publication No. 35. <doi:10.2136/sssaspecpub35.c1>

- Andrews, S.S., Karlen, D.L., & Cambardella, C.A. (2004). The soil management assessment framework: A quantitative soil quality evaluation method. *Soil Science Society of America Journal*, 68(6), 1945–1962. <doi:10.2136/sssaj2004.1945>

- Bastida, F., Zsolnay, A., Hernández, T., & García, C. (2008). Past, present and future of soil quality indices: A biological perspective. *Geoderma*, 147(3), 159–171. <doi:10.1016/j.geoderma.2008.08.007>

- Masto, R.E., Chhonkar, P.K., Purakayastha, T.J., Patra, A.K., & Singh, D. (2008). Soil quality indices for evaluation of long-term land use and soil management practices in semi-arid sub-tropical India. *Land Degradation & Development*, 19(5), 516–529. <doi:10.1002/ldr.528>

- Hwang, C.L., & Yoon, K. (1981). *Multiple Attribute Decision Making: Methods and Applications*. Springer-Verlag. <doi:10.1007/978-3-642-48318-9>

- Shannon, C.E. (1948). A mathematical theory of communication. *Bell System Technical Journal*, 27(3), 379–423. <doi:10.1002/j.1538-7305.1948.tb01338.x>

---

## Citation

```r
citation("SQIpro")
```

---

## License

GPL-3 © Sadikul Islam
