Type: | Package |
Title: | Cross-Validation Methods for Adsorption Isotherm Models |
Version: | 0.1.0 |
Author: | Paul Angelo C. Manlapaz
|
Maintainer: | Paul Angelo C. Manlapaz <pacmanlapaz@gmail.com> |
Description: | Provides cross-validation tools for adsorption isotherm models, supporting both linear and non-linear forms. Current methods cover commonly used isotherms including the Freundlich, Langmuir, and Temkin models. This package implements K-fold and leave-one-out cross-validation (LOOCV) with optional clustering-based fold assignment to preserve underlying data structures during validation. Model predictive performance is assessed using mean squared error (MSE), with optional graphical visualization of fold-wise MSEs to support intuitive evaluation of model accuracy. This package is intended to facilitate rigorous model validation in adsorption studies and aid researchers in selecting robust isotherm models. For more details, see Montgomery et al. (2012) <isbn: 978-0-470-54281-1>, Lumumba et al. (2024) <doi:10.11648/j.ajtas.20241305.13>, and Yates et al. (2022) <doi:10.1002/ecm.1557>. |
License: | GPL-3 |
Encoding: | UTF-8 |
Imports: | stats, nls2, graphics |
Suggests: | testthat |
Config/testthat/edition: | 3 |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-05-31 13:34:55 UTC; PTRI |
Repository: | CRAN |
Date/Publication: | 2025-06-03 13:00:06 UTC |
Cross-Validation for Freundlich Isotherm Linear Model with Clustering-based Fold Assignment
Description
Performs K-fold or leave-one-out cross-validation (LOOCV) on the linearized Freundlich isotherm model: log(Qe) = log(KF) + (1/n) * log(Ce) Evaluates predictive performance using Mean Squared Error (MSE). Optionally displays a barplot of fold-wise MSEs. Optionally uses clustering-based fold assignment to preserve data structure.
Arguments
Ce |
Numeric vector of equilibrium concentrations (Ce). Must be positive. |
Qe |
Numeric vector of amounts adsorbed (Qe). Must be positive and same length as Ce. |
K |
Integer. Number of folds to use in K-fold CV (default is 10). Ignored if loocv = TRUE. |
seed |
Integer. Random seed for reproducibility (default is 123). |
loocv |
Logical. If TRUE, performs leave-one-out cross-validation (overrides K). |
plot |
Logical. If TRUE, displays a barplot of fold MSEs (default is FALSE). |
use_clustering |
Logical. If TRUE, assigns folds using k-means clustering on the data (default FALSE). |
Value
A list with the following components:
- mean_mse
The average mean squared error across all folds.
- fold_mse
A numeric vector of MSEs for each fold.
Author(s)
Paul Angelo C. Manlapaz
References
Montgomery, D.C., Peck, E.A., & Vining, G.G. (2012). Introduction to Linear Regression Analysis, 5th ed. Wiley.
Examples
Ce <- c(0.01353, 0.04648, 0.13239, 0.27714, 0.41600, 0.63607, 0.80435, 1.10327, 1.58223)
Qe <- c(0.03409, 0.06025, 0.10622, 0.12842, 0.15299, 0.15379, 0.15735, 0.15735, 0.16607)
cv_freundlichLM(Ce, Qe, K = 5, seed = 123, plot = TRUE, use_clustering = TRUE)
cv_freundlichLM(Ce, Qe, loocv = TRUE, plot = TRUE)
Cross-Validation for Freundlich Isotherm Non-Linear Model with Clustering-based Fold Assignment
Description
Performs K-fold or leave-one-out cross-validation (LOOCV) on the non-linear Freundlich isotherm model: Qe = KF * Ce^(1/n) Fits a non-linear model of Qe versus Ce using non-linear least squares (nls2). Evaluates predictive performance using Mean Squared Error (MSE). Optionally displays a barplot of fold-wise MSEs. Optionally uses clustering-based fold assignment to preserve data structure.
Arguments
Ce |
Numeric vector of equilibrium concentrations (Ce). Must be positive. |
Qe |
Numeric vector of amounts adsorbed (Qe). Must be positive and same length as Ce. |
K |
Integer. Number of folds to use in K-fold CV (default is 10). Ignored if loocv = TRUE. |
seed |
Integer. Random seed for reproducibility (default is 123). |
loocv |
Logical. If TRUE, performs leave-one-out cross-validation (overrides K). |
plot |
Logical. If TRUE, displays a barplot of fold MSEs (default is FALSE). |
use_clustering |
Logical. If TRUE, assigns folds using k-means clustering on the data (default FALSE). |
Value
A list with the following components:
- mean_mse
The average mean squared error across all folds.
- fold_mse
A numeric vector of MSEs for each fold.
Author(s)
Paul Angelo C. Manlapaz
References
Montgomery, D.C., Peck, E.A., & Vining, G.G. (2012). Introduction to Linear Regression Analysis, 5th ed. Wiley.
Examples
Ce <- c(0.01353, 0.04648, 0.13239, 0.27714, 0.41600, 0.63607, 0.80435, 1.10327, 1.58223)
Qe <- c(0.03409, 0.06025, 0.10622, 0.12842, 0.15299, 0.15379, 0.15735, 0.15735, 0.16607)
cv_freundlichNLM(Ce, Qe, K = 5, seed = 123, plot = TRUE, use_clustering = TRUE)
cv_freundlichNLM(Ce, Qe, loocv = TRUE, plot = TRUE)
Cross-Validation for Langmuir Isotherm First Linear Model with Clustering-based Fold Assignment
Description
Performs K-fold or leave-one-out cross-validation (LOOCV) on the linearized Langmuir isotherm model (Form 1): Ce / Qe = 1 / (Qmax * b) + Ce / Qmax This corresponds to a linear regression of Ce / Qe versus Ce. Evaluates predictive performance using Mean Squared Error (MSE). Optionally displays a barplot of fold-wise MSEs. Optionally uses clustering-based fold assignment to preserve data structure.
Arguments
Ce |
Numeric vector of equilibrium concentrations (Ce). Must be positive. |
Qe |
Numeric vector of amounts adsorbed (Qe). Must be positive and same length as Ce. |
K |
Integer. Number of folds to use in K-fold CV (default is 10). Ignored if loocv = TRUE. |
seed |
Integer. Random seed for reproducibility (default is 123). |
loocv |
Logical. If TRUE, performs leave-one-out cross-validation (overrides K). |
plot |
Logical. If TRUE, displays a barplot of fold MSEs (default is FALSE). |
use_clustering |
Logical. If TRUE, assigns folds using k-means clustering on the data (default FALSE). |
Value
A list with the following components:
- mean_mse
The average mean squared error across all folds.
- fold_mse
A numeric vector of MSEs for each fold.
Author(s)
Paul Angelo C. Manlapaz
References
Montgomery, D.C., Peck, E.A., & Vining, G.G. (2012). Introduction to Linear Regression Analysis, 5th ed. Wiley.
Examples
Ce <- c(0.01353, 0.04648, 0.13239, 0.27714, 0.41600, 0.63607, 0.80435, 1.10327, 1.58223)
Qe <- c(0.03409, 0.06025, 0.10622, 0.12842, 0.15299, 0.15379, 0.15735, 0.15735, 0.16607)
cv_langmuirLM1(Ce, Qe, K = 5, seed = 123, plot = TRUE, use_clustering = TRUE)
cv_langmuirLM1(Ce, Qe, loocv = TRUE, plot = TRUE)
Cross-Validation for Langmuir Isotherm Second Linear Model with Clustering-based Fold Assignment
Description
Performs K-fold or leave-one-out cross-validation (LOOCV) on the linearized Langmuir isotherm model (Form 2): 1 / Qe = (1 / (Qmax * b)) * (1 / Ce) + 1 / Qmax This corresponds to a linear regression of 1 / Qe versus 1 / Ce. Evaluates predictive performance using Mean Squared Error (MSE). Optionally displays a barplot of fold-wise MSEs. Optionally uses clustering-based fold assignment to preserve data structure.
Arguments
Ce |
Numeric vector of equilibrium concentrations (Ce). Must be positive. |
Qe |
Numeric vector of amounts adsorbed (Qe). Must be positive and same length as Ce. |
K |
Integer. Number of folds to use in K-fold CV (default is 10). Ignored if loocv = TRUE. |
seed |
Integer. Random seed for reproducibility (default is 123). |
loocv |
Logical. If TRUE, performs leave-one-out cross-validation (overrides K). |
plot |
Logical. If TRUE, displays a barplot of fold MSEs (default is FALSE). |
use_clustering |
Logical. If TRUE, assigns folds using k-means clustering on the data (default FALSE). |
Value
A list with the following components:
- mean_mse
The average mean squared error across all folds.
- fold_mse
A numeric vector of MSEs for each fold.
Author(s)
Paul Angelo C. Manlapaz
References
Montgomery, D.C., Peck, E.A., & Vining, G.G. (2012). Introduction to Linear Regression Analysis, 5th ed. Wiley.
Examples
Ce <- c(0.01353, 0.04648, 0.13239, 0.27714, 0.41600, 0.63607, 0.80435, 1.10327, 1.58223)
Qe <- c(0.03409, 0.06025, 0.10622, 0.12842, 0.15299, 0.15379, 0.15735, 0.15735, 0.16607)
cv_langmuirLM2(Ce, Qe, K = 5, seed = 123, plot = TRUE, use_clustering = TRUE)
cv_langmuirLM2(Ce, Qe, loocv = TRUE, plot = TRUE)
Cross-Validation for Langmuir Isotherm Third Linear Model with Clustering-based Fold Assignment
Description
Performs K-fold or leave-one-out cross-validation (LOOCV) on the linearized Langmuir isotherm model (Form 3): Qe = Qmax - (1 / b) * (Qe / Ce) This corresponds to a linear regression of Qe versus Qe / Ce. Evaluates predictive performance using Mean Squared Error (MSE). Optionally displays a barplot of fold-wise MSEs. Optionally uses clustering-based fold assignment to preserve data structure.
Arguments
Ce |
Numeric vector of equilibrium concentrations (Ce). Must be positive. |
Qe |
Numeric vector of amounts adsorbed (Qe). Must be positive and same length as Ce. |
K |
Integer. Number of folds to use in K-fold CV (default is 10). Ignored if loocv = TRUE. |
seed |
Integer. Random seed for reproducibility (default is 123). |
loocv |
Logical. If TRUE, performs leave-one-out cross-validation (overrides K). |
plot |
Logical. If TRUE, displays a barplot of fold MSEs (default is FALSE). |
use_clustering |
Logical. If TRUE, assigns folds using k-means clustering on the data (default FALSE). |
Value
A list with the following components:
- mean_mse
The average mean squared error across all folds.
- fold_mse
A numeric vector of MSEs for each fold.
Author(s)
Paul Angelo C. Manlapaz
References
Montgomery, D.C., Peck, E.A., & Vining, G.G. (2012). Introduction to Linear Regression Analysis, 5th ed. Wiley.
Examples
Ce <- c(0.01353, 0.04648, 0.13239, 0.27714, 0.41600, 0.63607, 0.80435, 1.10327, 1.58223)
Qe <- c(0.03409, 0.06025, 0.10622, 0.12842, 0.15299, 0.15379, 0.15735, 0.15735, 0.16607)
cv_langmuirLM3(Ce, Qe, K = 5, seed = 123, plot = TRUE, use_clustering = TRUE)
cv_langmuirLM3(Ce, Qe, loocv = TRUE, plot = TRUE)
Cross-Validation for Langmuir Isotherm Fourth Linear Model with Clustering-based Fold Assignment
Description
Performs K-fold or leave-one-out cross-validation (LOOCV) on the linearized Langmuir isotherm model (Form 4): Qe / Ce = b * Qmax - b * Qe This corresponds to a linear regression of Qe / Ce versus Qe. Evaluates predictive performance using Mean Squared Error (MSE). Optionally displays a barplot of fold-wise MSEs. Optionally uses clustering-based fold assignment to preserve data structure.
Arguments
Ce |
Numeric vector of equilibrium concentrations (Ce). Must be positive. |
Qe |
Numeric vector of amounts adsorbed (Qe). Must be positive and same length as Ce. |
K |
Integer. Number of folds to use in K-fold CV (default is 10). Ignored if loocv = TRUE. |
seed |
Integer. Random seed for reproducibility (default is 123). |
loocv |
Logical. If TRUE, performs leave-one-out cross-validation (overrides K). |
plot |
Logical. If TRUE, displays a barplot of fold MSEs (default is FALSE). |
use_clustering |
Logical. If TRUE, assigns folds using k-means clustering on the data (default FALSE). |
Value
A list with the following components:
- mean_mse
The average mean squared error across all folds.
- fold_mse
A numeric vector of MSEs for each fold.
Author(s)
Paul Angelo C. Manlapaz
References
Montgomery, D.C., Peck, E.A., & Vining, G.G. (2012). Introduction to Linear Regression Analysis, 5th ed. Wiley.
Examples
Ce <- c(0.01353, 0.04648, 0.13239, 0.27714, 0.41600, 0.63607, 0.80435, 1.10327, 1.58223)
Qe <- c(0.03409, 0.06025, 0.10622, 0.12842, 0.15299, 0.15379, 0.15735, 0.15735, 0.16607)
cv_langmuirLM4(Ce, Qe, K = 5, seed = 123, plot = TRUE, use_clustering = TRUE)
cv_langmuirLM4(Ce, Qe, loocv = TRUE, plot = TRUE)
Cross-Validation Analysis for Langmuir Isotherm Non-linear Model with Clustering-based Fold Assignment
Description
Performs K-fold or leave-one-out cross-validation (LOOCV) on the Langmuir isotherm non-linear model: Qe = (Qmax * Ce) / (b + Ce) where Qmax is the maximum adsorption capacity and b is the Langmuir constant. Supports optional clustering-based fold assignment and visualization of fold MSEs.
Arguments
Ce |
Numeric vector of equilibrium concentrations (Ce). Must be positive. |
Qe |
Numeric vector of amounts adsorbed (Qe). Must be positive and same length as Ce. |
K |
Integer. Number of folds to use in K-fold CV (default is 10). Ignored if loocv = TRUE. |
seed |
Integer. Random seed for reproducibility (default is 123). |
loocv |
Logical. If TRUE, performs leave-one-out cross-validation (overrides K). |
plot |
Logical. If TRUE, displays a barplot of fold MSEs (default is FALSE). |
use_clustering |
Logical. If TRUE, assigns folds using k-means clustering on the data (default FALSE). |
Value
A list with the following components:
- mean_mse
The average mean squared error across all folds.
- fold_mse
A numeric vector of MSEs for each fold.
Author(s)
Paul Angelo C. Manlapaz
References
Montgomery, D.C., Peck, E.A., & Vining, G.G. (2012). Introduction to Linear Regression Analysis, 5th ed. Wiley.
Examples
Ce <- c(0.01353, 0.04648, 0.13239, 0.27714, 0.41600, 0.63607, 0.80435, 1.10327, 1.58223)
Qe <- c(0.03409, 0.06025, 0.10622, 0.12842, 0.15299, 0.15379, 0.15735, 0.15735, 0.16607)
cv_langmuirNLM(Ce, Qe, K = 5, seed = 123, plot = TRUE, use_clustering = TRUE)
cv_langmuirNLM(Ce, Qe, loocv = TRUE, plot = TRUE)
Cross-Validation for Temkin Isotherm Linear Model with Clustering-based Fold Assignment
Description
Performs K-fold or leave-one-out cross-validation (LOOCV) on the Temkin isotherm linear model: Qe = B * log(A) + B * log(Ce) This corresponds to a linear regression of Qe versus log(Ce). Evaluates predictive performance using Mean Squared Error (MSE). Optionally displays a barplot of fold-wise MSEs. Optionally uses clustering-based fold assignment to preserve data structure.
Arguments
Ce |
Numeric vector of equilibrium concentrations (Ce). Must be positive. |
Qe |
Numeric vector of amounts adsorbed (Qe). Must be positive and same length as Ce. |
K |
Integer. Number of folds to use in K-fold CV (default is 10). Ignored if loocv = TRUE. |
seed |
Integer. Random seed for reproducibility (default is 123). |
loocv |
Logical. If TRUE, performs leave-one-out cross-validation (overrides K). |
plot |
Logical. If TRUE, displays a barplot of fold MSEs (default is FALSE). |
use_clustering |
Logical. If TRUE, assigns folds using k-means clustering on the data (default FALSE). |
Value
A list with the following components:
- mean_mse
The average mean squared error across all folds.
- fold_mse
A numeric vector of MSEs for each fold.
Author(s)
Paul Angelo C. Manlapaz
References
Montgomery, D.C., Peck, E.A., & Vining, G.G. (2012). Introduction to Linear Regression Analysis, 5th ed. Wiley.
Examples
Ce <- c(0.01353, 0.04648, 0.13239, 0.27714, 0.41600, 0.63607, 0.80435, 1.10327, 1.58223)
Qe <- c(0.03409, 0.06025, 0.10622, 0.12842, 0.15299, 0.15379, 0.15735, 0.15735, 0.16607)
cv_temkinLM(Ce, Qe, K = 5, seed = 123, plot = TRUE, use_clustering = TRUE)
cv_temkinLM(Ce, Qe, loocv = TRUE, plot = TRUE)
Cross-Validation for Temkin Isotherm Non-Linear Model with Clustering-based Fold Assignment
Description
Performs K-fold or leave-one-out cross-validation (LOOCV) on the non-linear Temkin isotherm model: Qe = (RT / bT) * log(AT * Ce) Fits a non-linear model of Qe versus Ce using non-linear least squares (nls2). Evaluates predictive performance using Mean Squared Error (MSE). Optionally displays a barplot of fold-wise MSEs. Optionally uses clustering-based fold assignment to preserve data structure.
Arguments
Ce |
Numeric vector of equilibrium concentrations (Ce). Must be positive. |
Qe |
Numeric vector of amounts adsorbed (Qe). Must be positive and same length as Ce. |
Temp |
Numeric scalar. Temperature in Kelvin. Must be positive. |
K |
Integer. Number of folds to use in K-fold CV (default is 10). Ignored if loocv = TRUE. |
seed |
Integer. Random seed for reproducibility (default is 123). |
loocv |
Logical. If TRUE, performs leave-one-out cross-validation (overrides K). |
plot |
Logical. If TRUE, displays a barplot of fold MSEs (default is FALSE). |
use_clustering |
Logical. If TRUE, assigns folds using k-means clustering on the data (default FALSE). |
Value
A list with the following components:
- mean_mse
The average mean squared error across all folds.
- fold_mse
A numeric vector of MSEs for each fold.
Author(s)
Paul Angelo C. Manlapaz
References
Montgomery, D.C., Peck, E.A., & Vining, G.G. (2012). Introduction to Linear Regression Analysis, 5th ed. Wiley.
Examples
Ce <- c(0.01353, 0.04648, 0.13239, 0.27714, 0.41600, 0.63607, 0.80435, 1.10327, 1.58223)
Qe <- c(0.03409, 0.06025, 0.10622, 0.12842, 0.15299, 0.15379, 0.15735, 0.15735, 0.16607)
cv_temkinNLM(Ce, Qe, Temp = 298, K = 5, seed = 123, plot = TRUE, use_clustering = TRUE)
cv_temkinNLM(Ce, Qe, Temp = 298, loocv = TRUE, plot = TRUE)