---
title: "Modeling Adsorption Isotherms with AdsorpR"
author: 
  - name: "Jajati Mandal"
    affiliation: "University of Salford, United Kingdom"
    email: "J.Mandal2@salford.ac.uk"
  - name: "Sandipan Samanta"
    affiliation: "Independent Researcher"
    email: "ssondiponsamanta@gmail.com"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Modeling Adsorption Isotherms with AdsorpR}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(AdsorpR)
library(ggplot2)
```

## 📦 Introduction

The **`AdsorpR`** package provides functions for modeling four classical adsorption isotherms:

- **Langmuir** (monolayer adsorption)
- **Freundlich** (heterogeneous surfaces)
- **BET** (multilayer adsorption)
- **Temkin** (linear decrease of adsorption energy)

These models are commonly used in environmental and chemical engineering studies to describe sorption mechanisms of contaminants onto solid adsorbents.

## 🧪 Sample Dataset

We demonstrate model usage using a simple example dataset representing equilibrium concentration (`Ce`) and the amount adsorbed (`Qe`):

```{r sample-data}
Ce <- c(1, 2, 3, 4, 5)
Qe <- c(0.8, 1.5, 2.1, 2.6, 2.9)
```

## 📐 Langmuir Isotherm

```{r langmuir}
result_l <- langmuir_model(Ce, Qe)
print(result_l[1:2])        # Qmax and KL
print(result_l$`Model Summary`)
result_l$Plot
```

## 📐 Freundlich Isotherm

```{r freundlich}
result_f <- freundlich_model(Ce, Qe)
print(result_f[1:2])        # Kf and n
print(result_f$`Model Summary`)
result_f$Plot
```

## 📐 BET Isotherm

```{r bet}
result_b <- bet_model(Ce, Qe)
print(result_b[1:2])        # Qm and Cb
print(result_b$`Model Summary`)
result_b$Plot
```

## 📐 Temkin Isotherm

```{r temkin}
result_t <- temkin_model(Ce, Qe)
print(result_t[1:2])        # A and B
print(result_t$`Model Summary`)
result_t$Plot
```


## 🔁 Non-linear Isotherm Modeling

### Non-linear Langmuir

```{r}
Ce <- c(1, 2, 4, 6, 8, 10)
Qe <- c(0.9, 1.6, 2.3, 2.7, 2.9, 3.0)
result <- nonlinear_langmuir(Ce, Qe)
print(result$`Langmuir Qmax (mg/g)`)
print(result$`Langmuir KL (L/mg)`)
print(result$AIC)
print(result$`Pseudo R2`)
print(result$Plot)
```

### Non-linear Freundlich

```{r}
Ce <- c(0.5, 1, 2, 4, 6, 8)
Qe <- c(0.3, 0.8, 1.6, 2.4, 2.9, 3.2)
result <- nonlinear_freundlich(Ce, Qe)
print(result$`Freundlich Kf`)
print(result$`Freundlich n`)
print(result$AIC)
print(result$`Pseudo R2`)
print(result$Plot)
```

### Non-linear BET

```{r}
Ce <- c(1, 2.5, 4, 5.5, 7)
Qe <- c(0.4, 1.0, 1.7, 2.3, 2.7)
result <- nonlinear_bet(Ce, Qe)
print(result$`BET Qm (mg/g)`)
print(result$`BET Cb`)
print(result$AIC)
print(result$`Pseudo R2`)
print(result$Plot)
```

### Non-linear Temkin

```{r}
Ce <- c(0.5, 1.5, 3, 4.5, 6)
Qe <- c(0.7, 1.3, 2.0, 2.4, 2.7)
result <- nonlinear_temkin(Ce, Qe)
print(result$`Temkin A`)
print(result$`Temkin B`)
print(result$AIC)
print(result$`Pseudo R2`)
print(result$Plot)
```

## 📝 Conclusion

The `AdsorpR` package offers a clean and structured way to fit adsorption isotherm models and visualize results using `ggplot2`. It is useful for:

- Environmental monitoring studies
- Sorption modeling of nutrients and pollutants in soil
- Research on water/soil remediation


