Skip to contents

An R package providing a versatile toolkit for mathematical modeling, developed as a companion to the book Mathematical Modeling: Algorithms and Programming Implementation (China Machine Press). It focuses on implementing rigorous algorithms in a user-friendly manner.

Current Version (0.0.11) introduces an interpolation and curve fitting toolkit (interp_linear, interp_spline, interp_poly, interp_hermite, poly_fit, curve_fit, growth_fit) — on top of the regression prediction toolkit, time-series workflow, epidemic modeling, differential equation models, grey prediction, Markov chain models, and a rich suite of evaluation methods (AHP, Entropy, CRITIC, PCA, TOPSIS, Fuzzy, RSR, DEA).

Key Features

Installation

Once released on CRAN, install mathmodels with:

install.packages("mathmodels")

You can install the latest development version directly from GitHub:

remotes::install_github("zhjx19/mathmodels")

Getting Started

library(mathmodels)

# --- AHP (Analytic Hierarchy Process) ---
A = matrix(c(1,   1/2, 4, 3,   3,
             2,   1,   7, 5,   5,
             1/4, 1/7, 1, 1/2, 1/3,
             1/3, 1/5, 2, 1,   1,
             1/3, 1/5, 3, 1,   1), byrow = TRUE, nrow = 5)
AHP(A)

# --- Epidemic compartment modeling ---
result = model_sir(
  init   = c(S = 990, I = 10, R = 0),
  params = c(beta = 0.15, gamma = 0.1),  # R0 = 1.5
  times  = seq(0, 100, by = 0.5))

# Visualize
plot_compartments(result, compartments = c("S", "I", "R"))

# Compute epidemic metrics
metrics = epi_metrics(result, beta = 0.15, gamma = 0.1, N = 1000)
metrics$R0         # basic reproduction number

# --- Time series ---
x = as_ts_df(log(AirPassengers))
fit = ts_sarima(x)
fc  = ts_forecast(fit, h = 12)
plot_ts_forecast(x, fc)           # forecast with CIs

Learning More

For detailed documentation, tutorials, and in-depth examples on using the mathmodels package, please refer to the comprehensive online manual:

📘 mathmodels Package Manual - Simplifying Mathematical Modeling (Online Book, In Chinese)

This online book is the definitive guide to the package’s functionalities. Currently implemented modules include: