Changelog
Source:NEWS.md
mathmodels 0.0.14
Data cleaning toolkit (new)
-
Diagnostics:
na_summary()(per-column missing counts),na_mcar_test()(Little’s MCAR test, Little 1988 / SAS-style pattern-mean statistic with EM-estimated mean and covariance, followingnaniar::mcar_test()),plot_na_heatmap()andplot_na_bar()for missingness visuals. -
Imputation:
impute()for simple fills (group mean / median / mode via.byslices, row-order linear and spline interpolation reusinginterp_linear()/interp_spline(), and constants) andimpute_model(), a unified model-based framework with k-nearest-neighbors (hand-written), linear regression, and decision trees (rpart). Both return the data frame of the same shape and record every changed cell inattr(df, "changes")(model fits are also summarized inattr(df, "details")). -
Outliers:
outlier()detects outliers with IQR / z-score / Hampel-MAD bounds (per.byslice). By default the data is untouched and the detection table is returned;to = "na"sets detected values toNA(ready forimpute()),to = "cap"caps them at the fence values.
Pivot table (new)
-
pivot_table(): aggregates values by the cross ofindexandcolumns(.by-style tidy evaluation) and spreads them into a wide tibble; naming is built withnames_glueso the value-column prefix is always present (e.g.sales_2023,v_c1), controlled bynames_sep. -
Dependencies (new):
rpart(ships with R).
Multiple imputation toolkit (new)
-
impute_multiple(): FCS (fully conditional specification, chained-equations) multiple imputation —pmm/normmethods for numeric columns andlogreg/polyregfor categorical ones; validated againstmicein cross-validation tests. -
rubin_pool(): pools scalar estimates across imputations with Rubin’s rules, including the Barnard-Rubin small-sample degrees-of-freedom adjustment. -
pool_fit(): poolslm/glmfits (coefficients, SEs, t/p-values, pooled residual df) with automatic Barnard-Rubin edf.
Statistical inference toolkit (new)
-
Hypothesis tests (
stat_infer.R): tidy data frames in, tidy tibbles out (one row per test,stat_inferclass with a labelled print).-
stat_t_test()/stat_wilcox_test(): one-sample, two-sample (Welch or pooled), and paired tests with Cohen’s d / rank-biserial effects; Wilcoxon signed-rank and Mann-Whitney U as the nonparametric counterparts. -
stat_anova()(multi-factor with interactions, partial eta-squared),stat_kruskal()(epsilon-squared),stat_ancova()(with an optional parallel-slopes check),stat_cor()(Pearson/Spearman/Kendall with p-adjustment),stat_chisq()(Cramer’s V, low-expected-frequency warning, Fisher exact option),stat_normality()(Shapiro-Wilk plus skewness/kurtosis),stat_hov_test()(Levene/Bartlett/F). - All tests support
.byslice grouping (repeat the test within each slice) and multi-column loops withp_adjust. -
stat_describe(): grouped descriptive statistics.
-
-
Generic frameworks:
stat_bootstrap()built onboot::boot()/boot::boot.ci()(BCa / percentile / basic CIs, parallel support) andstat_perm_test()(label / sign-flip / shuffle permutations with +1 corrected p-values; customfunction(data, indices)statistics). -
export_table(): three-line (booktabs) table export to Word (flextable) and LaTeX from descriptive statistics,stat_*results, andreg_*()regression results. -
Dependencies (new):
boot,flextable.
mathmodels 0.0.13
Breaking changes
-
Renamed the weighting functions to a
weight_*prefix:critic_weight()→weight_critic(),cv_weight()→weight_cv(),entropy_weight()→weight_entropy(),pca_weight()→weight_pca(). New:weight_fa()— factor-analysis-based objective weighting (stats::factanalloadings combined with per-factor variance shares; counterpart ofweight_pca()). -
Renamed the membership functions to an
mf_*prefix:tri_mf()→mf_tri(),trap_mf()→mf_trap(),gauss_mf()→mf_gauss(),gbell_mf()→mf_gbell(),gauss2mf()→mf_gauss2(),sigmoid_mf()→mf_sigmoid(),dsigmoid_mf()→mf_dsigmoid(),psigmoid_mf()→mf_psigmoid(),z_mf()→mf_z(),pi_mf()→mf_pi(),s_mf()→mf_s().
mathmodels 0.0.12
Breaking changes
-
Renamed the differential equation model functions from
model_*()toode_*()for a consistent prefix withode_solver():model_malthus()→ode_malthus(),model_logistic()→ode_logistic(),model_si()→ode_si(),model_sis()→ode_sis(),model_sir()→ode_sir(),model_seir()→ode_seir(),model_lv()→ode_lv(). -
Removed the redundant
methodargument ofplot_Rt_estimate()(the two methods were numerically identical);R_t = beta * S / (gamma * N)is now always used andNis inferred from the known compartments (S, E, I, R) only.
Bug fixes
-
pred_reg: fixed the Hosmer-Lemeshow statistic (wrong column reference and missing variance term — previously reported absurd chi-squares); fixed the factor-response coding in
reg_logistic()(events were mapped to -1/0); logistic prediction CIs now use the link scale (previous CIs were far too narrow);.predict_lm()returns bothconfidence_intervalandprediction_interval(the prediction interval was mislabeled);reg_predict()accepts anewdataargument and returns the data used; rank-deficient models no longer break the coefficient table;shapiro.test()is guarded for n > 5000. -
eval_algorithms:
topsis()validatesindexandwand rejects all-zero columns; sample names default toSample1..n;rank_sum_ratio()rejects unknownmethod;grey_corr()guards the degenerate all-equal case and validatesw. -
eval_dea:
super_SBM()now implements Tone (2002) super-efficiency (efficient DMUs get rho >= 1 instead of NA); SBM undesirable-output weights follow Tone (2004) (1/s1, 1/s2);basic_DEA(ud_outputs=)now actually treats undesirable outputs as inputs (Hailu-Veeman) instead of silently ignoring them;malmquist(type1 = "seq")implements sequential reference sets (was identical to “cont”); character periods sort numerically; strictly positive inputs/outputs are enforced; SBM rejects the inapplicableorientationargument; malmquist warns on panel irregularities. -
eval_weights:
critic_weight()/entropy_weight()accept matrices again (matrix inputs previously errored element-wise); non-negative data is enforced for entropy paths;combine_weights()rejects unknowntype;game_linear()falls back to a pseudo-inverse for proportional weights;AHP()returns CI = CR = 0 for n <= 2 and rejects non-positive matrices; unknownindexvalues are rejected instead of silently treated as “already normalized”. -
eval_fuzzy:
defuzzify()rejects unknown methods and returns the first maximum on ties;fuzzy_eval()validates R in [0, 1] with no NA; membership functions validate their parameters (strict ordering / positivity). -
pred_grey / pred_ts:
combine_preds()handles identical predictions (equal weights); GM models reject non-positive/NA data and near-constant series (a ~ 0) with informative errors;GM1N()returnsC/Pas documented;ts_back_transform()applies Box-Cox bias adjustment to point forecasts (bias_adj = TRUEdefault); Ljung-Box diagnostics use ARMA-only fitdf and no longer produce NaN rows for short series;ts_transform()/ts_forecast()validate differencing depth and duplicated levels. -
diffEq:
ode_solver()validatestimes(strictly increasing) and rejects unused compartments ininit; equation parse errors name the offending variable;plot_incidence()warns on non-uniform time steps;epi_metrics()infers N from known compartments only and validates beta/gamma; thebparameter is documented as constant recruitment. -
eval_system / eval_regional / eval_preprocess / interp_fit: coupling degree validates
typeand unit-sum weights;id_colstypos are rejected;HHI()handles single values and rejects negatives; entropy / CV weight functions reject NA; preprocessing helpers guard degenerate inputs (rescale_middle,to_positive,rescale_extreme,normalize,standardize);curve_fit()/growth_fit()report AIC/BIC on the original scale (fixes NaN at n = p) with non-finite start-value fallbacks;interp_poly()validatesdegree. -
read_nbs:
range = "A1"(version-robust header read). -
DESCRIPTION:
dplyr (>= 1.1.0)now declared (reframe()requires it).
Multivariate statistics toolkit (new)
-
Dimension reduction (
mv_stats.R): -
Clustering (
mv_stats.R):-
mv_hclust(): Hierarchical clustering with tidy cluster assignments, merge heights, and the rawhclustobject for custom plots. -
mv_kmeans(): K-means clustering with assignments, centers, and within-cluster sums of squares. -
mv_cluster_metrics(): Clustering validity metrics computed in base R: per-observation silhouette widths, average silhouette, Davies-Bouldin, Calinski-Harabasz, and Dunn indices. -
plot_mv_elbow()andplot_mv_silhouette(): Elbow plot (k-means or hierarchical) and silhouette plot for both clustering types;plot_mv_dendrogram()for hierarchical dendrograms.
-
-
Discriminant analysis (
mv_stats.R):-
mv_discrim(): LDA/QDA viaMASSwith training predictions, confusion matrix, accuracy, discriminant scores (LDA), and optional classification of new data.
-
-
Other multivariate methods (
mv_stats.R):-
mv_corresp(): Simple correspondence analysis with row/column coordinates and inertia decomposition. -
mv_mds(): Metric (cmdscale) and non-metric (MASS::isoMDS) multidimensional scaling. -
mv_cancor(): Canonical correlation analysis with Wilks’ lambda significance tests, coefficients, and structure correlations. -
mv_pcor(): Partial correlation matrix with t-tests.
-
-
Visualization:
plot_mv_scree()andplot_mv_scores()for PCA/EFA scree and score plots,plot_mv_corresp()andplot_mv_mds()for CA/MDS configuration maps. -
Dependencies: unchanged. Tidy-select column interfaces are implemented through the existing
dplyrdependency. - All functions follow a tidy interface: tidy-select columns in, tibble components out, and
print()methods for compact summaries.
mathmodels 0.0.11
-
New function
ts_arimax(): Fits ARIMA models with exogenous regressors (ARIMAX). Supports both automatic order selection (forecast::auto.arima()) and manual specification (forecast::Arima()), consistent with the existingts_sarima()interface. -
Updated
ts_forecast(): Addednewxregparameter for forecasting ARIMAX models with future exogenous regressor values. -
Improved
compute_mf()/compute_mf_funs(): Added.builderparameter supporting Gaussian ("gauss") and sigmoid ("sigmoid") membership functions in addition to the default triangular/trapezoidal ("tri"). Custom builder functions are also accepted. Renamedthresholdsparameter toknotsfor clarity. Fixeddefuzzify()floating-point comparison inmax_membershipmethod.
Interpolation & curve fitting toolkit (new)
-
Interpolation (
interp_fit.R):-
interp_linear(): Piecewise linear interpolation. -
interp_spline(): Cubic spline interpolation with optional smoothing viaspar. -
interp_poly(): Polynomial interpolation of specified degree. -
interp_hermite(): Shape-preserving piecewise cubic Hermite interpolation.
-
-
Curve fitting (
interp_fit.R):-
poly_fit(): Polynomial regression. -
curve_fit(): Unified interface for linearizable curves via variable transformation (exponential, power-law, logarithmic, hyperbolic). -
growth_fit(): Nonlinear growth curve fitting viaminpack.lm::nlsLM()with automatic starting values (Logistic, Gompertz, exponential saturation, Michaelis-Menten).
-
-
Refinements:
-
poly_fit()now returns explicit polynomial equations (e.g.,y = 3 + 2 * x - 0.5 * x^2) instead of R formula strings. - Internal
._compute_fit_stats()avoids redundant AIC/BIC computation forlmmodels (usesstats::AIC()/stats::BIC()directly; normal-approximation fallback fornls). -
curve_fit()documentation now notes log-transform back-transformation bias for"exp"and"power"types.
-
-
Dependencies (new):
minpack.lmfor Levenberg-Marquardt nonlinear least squares.
mathmodels 0.0.10
Regression prediction toolkit (new)
-
Model fitting (
pred_reg.R):-
reg_lm(): OLS multiple linear regression with optional stepwise selection (forward / backward / both), returning coefficients with CIs and fit statistics. -
reg_logistic(): Binary logistic regression (glm(binomial)) with stepwise selection, odds ratios, and Hosmer-Lemeshow goodness-of-fit test. -
reg_poisson(): Poisson regression for count data, with dispersion check. -
reg_negbin(): Negative binomial regression viaMASS::glm.nb()for over-dispersed counts.
-
-
Diagnostics and prediction (
pred_reg.R):-
reg_diagnostics(): Unified diagnostics — Breusch-Pagan, Durbin-Watson, Shapiro-Wilk (LM); Hosmer-Lemeshow, dispersion/deviance (GLM). -
reg_predict(): Draw new predictor data from the empirical distribution and generate fitted or predicted values with 95% confidence intervals.
-
-
Visualization (
pred_reg.R):-
plot_reg_residuals(): Residual diagnostic plots (residuals vs. fitted, normal Q-Q, density). -
plot_reg_predict(): Prediction plots with confidence bands — supports both fitted (training data) and predicted (new data) modes.
-
mathmodels 0.0.9
Time series toolkit (new)
-
Data structure and preprocessing (
pred_ts.R):-
ts_df()andas_ts_df(): Lightweight single-series time-series data frame and conversion helpers. -
complete_ts_df()andimpute_ts_df(): Gap completion and linear / spline interpolation.
-
-
Modeling and diagnostics (
pred_ts.R):-
ts_test(): Stationarity diagnostics (ADF and KPSS). -
ts_stl(): Seasonal-trend decomposition (STL). -
ts_ets(): Exponential smoothing. -
ts_sarima(): SARIMA with auto-selection or user-specified orders. -
ts_forecast(): Unified forecasting for ETS and SARIMA models. -
ts_transform()andts_back_transform(): Box-Cox / log / differencing workflows and inverse transformation for forecasts.
-
-
Visualization (
pred_ts.R): - Dependencies (new): forecast (ETS, ARIMA), tseries (ADF/KPSS tests), patchwork (multi-panel plots).
Epidemic visualization & metrics overhaul
-
Renamed
epidemic_plot.R→epi_plots.R. Consolidated from 3 files into 1. -
Removed
compute_incidence(),plot_infectious_curve(),plot_cumulative_infection(). -
Merged
epidemic_metrics()→epi_metrics(): simplified to 4 core scalars (R0, peak_infection, peak_time, attack_rate). -
Refined
plot_incidence(): now shows ΔI (daily new infections) with peak time annotation.
mathmodels 0.0.8
New features
-
Differential equation models (
diffEq_models.R):-
ode_solver(): General-purpose string-formula ODE solver powered by deSolve. -
model_malthus(),model_logistic(),model_si(),model_sis(),model_sir(),model_seir(),model_lv()— all using a unifiedinit+paramsinterface with physics-meaningful named parameters (e.g.,beta,gamma,sigma).
-
-
Epidemic visualization (
epidemic_plot.R):-
plot_compartments(): Faceted/overlaid line plot of selected compartments. -
compute_incidence(): Daily incidence from S or I differences. -
plot_incidence(),plot_infectious_curve(),plot_cumulative_infection(): Infection curve visualizations. -
plot_phase_si(): S–I phase portrait. -
plot_Rt_estimate(): Effective reproduction number trajectory.
-
-
Epidemic metrics (
epidemic_metrics.R):-
epidemic_metrics(): Comprehensive epidemic summary (R0, peak, attack rate, trajectory with Rt and growth rate).
-
-
Markov chain prediction (
markov.R):-
markov_chain(): Transition probability matrix, multi-step prediction, stationary distribution. -
GM11_markov(): Grey–Markov combined prediction with GM(1,1) and Markov correction.
-
mathmodels 0.0.7
New features
-
DEA models: New
DEA.Rmodule implementing Data Envelopment Analysis with:-
basic_DEA(): Radial models (CCR/BCC) with input/output orientation support, returning both Shephard distances and Farrell efficiencies, plus slacks, targets, and lambda weights. -
super_DEA(): Super-efficiency radial models, fully compatible with CRS/VRS settings. -
basic_SBM(): Slacks-Based Measure (non-radial) with CRS/VRS support. -
super_SBM(): Super-efficiency SBM for distinguishing efficient DMUs. -
malmquist(): Malmquist productivity index supporting contemporaneous, sequential, and global references with FGNZ and Ray-Desli decompositions.
-
- All DEA models use lpSolveAPI as the sole LP solver, with zero external DEA package dependency.
Dependencies
-
Imports (new): Added
lpSolveAPIfor linear programming in DEA models. -
Suggests (removed): Removed
deaRfrom Suggests; all DEA functionality is now provided natively.
Parameter validation
- Added input validation for all DEA functions, including checks for NA values, correct column types, and valid orientation/rts/type parameters.
Testing
- Added 30 new test cases in
test-DEA.R, covering:- Basic DEA model validation (CCR, BCC, SBM)
- Super-efficiency models
- Malmquist index with all 6 type1 × type2 combinations
- Undesirable outputs handling
- Input validation (NA detection, minimum column requirements)
- All 208 tests pass with zero errors.
Documentation
- Added
@examplessections to all five DEA functions with self-contained inline data. - Regenerated
man/DEA.Rdwithdevtools::document().
mathmodels 0.0.6
Bug fixes
-
AHP(): Extended the Random Index (RI) table from n = 11 to n = 15, and added validation for n > 15. Previously,AHP()would silently returnNAfor consistency ratios with more than 11 criteria. -
grey_corr(): Fixed incorrect default weight direction in the internal validation; weights are now correctly validated againstnrow(cmp)(number of evaluation objects) rather thanncol(cmp)(number of indicators). -
DGM21(): Fixed thelist(pred = fitted, ...)return value wherefittedwas undefined; corrected tolist(fitted = pred, ...). Also fixed the initialization valuex0from a hard-coded constant to the first element of the input seriesX[1]. -
grey_corr_topsis(): Fixed an internal transpose error in the call togrey_corr()that caused dimension mismatch in non-square matrices. -
z_mf(),pi_mf(),s_mf(): Rewrote the two-stage spline algorithm for all three membership functions. The original implementation used a single-stage approximation with logically unreachable second-phase conditions, causing values to fall outside the valid [0, 1] range for certain parameter configurations. The fix ensures proper two-stage spline behavior with exact midpoint values of 0.5.
Dependencies
-
Imports (new): Added
MASS,purrr,readxl,rlang,stats,stringr, andtibbletoDESCRIPTION/Imports. These were already used in code via@importFrominNAMESPACEbut were missing from the formal dependency declaration. -
Suggests (new): Added
deaRtoDESCRIPTION/Suggestsfor DEA model functionality.
Parameter validation
- Added input type and dimension validation (
stopifnot()checks) for all exported functions, including checks for:- Data frame / matrix type verification
- Vector length consistency
- Non-negativity / positivity of weights
- Matrix dimension bounds
- Parameter range constraints
Testing
- Added 178 test cases across 18 test files, achieving full coverage of all core modules:
| Module | Test file | Tests |
|---|---|---|
| AHP | test-AHP.R |
8 |
| Combine predictions | test-combine_preds.R |
5 |
| Combine weights | test-combine_weights.R |
7 |
| CRITIC weighting | test-critic.R |
5 |
| CV weighting | test-cv.R |
4 |
| Entropy weighting | test-entropy.R |
7 |
| Fuzzy evaluation |
test-fuzzy.R, test-fuzzy_more.R
|
25 |
| Grey analysis | test-grey.R |
10 |
| Grey models | test-grey_models.R |
16 |
| Inequality measures | test-inequality.R |
12 |
| Linear sum | test-linear_sum.R |
4 |
| Membership functions | test-membership.R |
19 |
| PCA weighting | test-pca.R |
4 |
| Preprocessing | test-preprocess.R |
21 |
| Rank sum ratio | test-rsr.R |
5 |
| System evaluation | test-system_evaluation.R |
9 |
| TOPSIS | test-topsis.R |
5 |
Documentation
- Updated function examples and documentation to reflect all parameter validation rules.
- Added pkgdown website configuration (
_pkgdown.yml). Once pushed to GitHub, the reference site will be automatically built and deployed to https://zhjx19.github.io/mathmodels/ via GitHub Actions. - Fixed a typo in the GitHub installation URL within
README.md. - Updated
README.mdversion badge from 0.0.5 to 0.0.6. - The comprehensive online manual is available at: https://zhjx19.github.io/mathmodels-book/