---
title: "Drying Kinetic Model Analysis with dryingkineticmodels"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Drying Kinetic Model Analysis with dryingkineticmodels}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

## Introduction

The `dryingkineticmodels` package fits 20 thin-layer drying kinetic models
to experimental moisture ratio (MR) data, ranks them by statistical
criteria, identifies the best model, performs residual diagnostics, and
exports a formatted report to a Word document.

## Input Data Format

The input must be an Excel file (`.xlsx`) or a data frame with at least
two numeric columns:

- **First numeric column** — Drying time
- **Second numeric column** — Moisture ratio (MR), typically between 0 and 1

Example layout:

| Time (min) | MR   |
|------------|------|
| 0          | 1.00 |
| 30         | 0.74 |
| 60         | 0.51 |
| 90         | 0.32 |
| 120        | 0.18 |

> **Note:** Ensure the columns are in the correct order before running
> the function. No column renaming is required.

## Basic Usage

```{r, eval=FALSE}
library(dryingkineticmodels)

# From an Excel file
result <- dryingkineticmodels("drying_data.xlsx")

# From a data frame
df <- data.frame(
  time = c(0, 30, 60, 90, 120),
  MR   = c(1.00, 0.74, 0.51, 0.32, 0.18)
)
result <- dryingkineticmodels(df)
```

## What the Function Does

When called, `dryingkineticmodels()` automatically:

1. Reads and validates the input data
2. Fits all 20 thin-layer drying models using nonlinear least squares
3. Computes R², RMSE, MAE, χ², and RSS for each model
4. Ranks models by a composite score and prints the comparison table
5. Identifies the best model and reports its coefficients and fit statistics
6. Runs hypothesis tests on model parameters
7. Computes an ANOVA table for the best model
8. Performs four residual diagnostic tests
9. Generates diagnostic plots and a drying curve
10. Exports everything to a Word document

## Output

The function returns an invisible list with three elements:

- `comparison_table` — all model statistics, ranked
- `best_model` — result list for the best-fitting model
- `anova_table` — ANOVA table for the best model

```{r, eval=FALSE}
# Access results programmatically
result$comparison_table
result$anova_table
```

## The 20 Models

| Model | Equation |
|-------|----------|
| Lewis | MR = exp(-k·t) |
| Page | MR = exp(-k·t^n) |
| Modified Page | MR = exp(-(k·t)^n) |
| Henderson & Pabis | MR = a·exp(-k·t) |
| Logarithmic | MR = a·exp(-k·t) + c |
| Two-Term | MR = a·exp(-k₀·t) + b·exp(-k₁·t) |
| Two-Term Exponential | MR = a·exp(-k·t) + (1-a)·exp(-(k·a·t)) |
| Diffusion Approximation | MR = a·exp(-k·t) + (1-a)·exp(-(k·b·t)) |
| Wang & Singh | MR = 1 + a·t + b·t² |
| Midilli-Kucuk | MR = a·exp(-k·t^n) + b·t |
| Modified Henderson & Pabis | MR = a·exp(-k·t) + b·exp(-g·t) + c·exp(-h·t) |
| Verma | MR = a·exp(-k·t) + (1-a)·exp(-g·t) |
| Weibull | MR = exp(-(t/α)^β) |
| Aghbashlo et al. | MR = exp(-k₁·t / (1 + k₂·t)) |
| Jena & Das | MR = a·exp(-k·t^n) + b·t + c |
| Hii et al. | MR = a·exp(-k·t^n) + b·exp(-g·t^m) |
| Parabolic | MR = a + b·t + c·t² |
| Thompson | MR = exp((-a + √(a²+4b·t)) / 2b) |
| Demir et al. | MR = a·exp(-k·t^n) + b |
| Thin-Layer Exp-Linear | MR = a·exp(-k·t) + b·t + c |

## References

Goyal, R. K., Kingsly, A. R. P., Manikantan, M. R., & Ilyas, S. M. (2007).
Mathematical modelling of thin layer drying kinetics of plum in a tunnel
dryer. *Journal of Food Engineering*, 79(1), 176–180.
