cv_temkinLM {adsoRptionCV} | R Documentation |
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)