| Title: | Random Forest Regression with Modified Topp-Leone Error Model |
|---|---|
| Description: | Implements Random Forest regression under the Modified Topp-Leone (MTL) distribution error model. Provides core distribution functions (density, cumulative distribution, exact closed-form quantile, random generation, hazard, and survival), parameter estimation via closed-form Expectation-Maximization/Maximum Likelihood (EM/MLE) and Bayesian Markov Chain Monte Carlo (MCMC), non-parametric bootstrap confidence intervals (at 90%, 95%, and 99% levels), Highest Posterior Density (HPD) intervals, Heidelberger and Welch MCMC convergence diagnostics, model evaluation metrics (estimated values, bias, mean squared error, risk value), homoscedastic prediction intervals, and goodness-of-fit diagnostic tests (Kolmogorov-Smirnov and Anderson-Darling tests, Akaike Information Criterion, and Bayesian Information Criterion). References: Breiman (2001) <doi:10.1023/A:1010933404324>; Singh, Tyagi, Singh, and Tyagi (2025) <https://statassoc.or.th>; Topp and Leone (1955) <doi:10.1080/01621459.1955.10501259>; Wright and Ziegler (2017) <doi:10.18637/jss.v077.i01>; Plummer, Best, Cowles, and Vines (2006) <https://CRAN.R-project.org/package=coda>; Heidelberger and Welch (1983) <doi:10.1287/opre.31.6.1109>. |
| Authors: | Shikhar Tyagi [aut, cre] (ORCID: <https://orcid.org/0000-0003-1606-0844>), Aruna Rajballie [aut], Vrijesh Tripathi [aut] |
| Maintainer: | Shikhar Tyagi <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.0 |
| Built: | 2026-09-21 09:41:13 UTC |
| Source: | https://github.com/cran/MTLRF |
Estimates the Modified Topp-Leone (MTL) parameter alpha using Markov Chain Monte Carlo (MCMC) sampling, evaluates Highest Posterior Density (HPD) intervals at 90
mcmc_mtl( r, n_iter = 5000, burn_in = 1000, thin = 2, init_alpha = NULL, seed = NULL )mcmc_mtl( r, n_iter = 5000, burn_in = 1000, thin = 2, init_alpha = NULL, seed = NULL )
r |
Vector of absolute residuals. |
n_iter |
Total number of MCMC iterations (default |
burn_in |
Number of initial burn-in iterations to discard (default |
thin |
Thinning interval for posterior chain (default |
init_alpha |
Initial value for |
seed |
Optional random seed. |
MCMC sampling is performed using an adaptive Metropolis-Hastings algorithm on the log-scale of () to ensure positivity and numerical stability.
A weakly informative Gamma(0.001, 0.001) prior is placed on .
The posterior chain is analyzed using HPDinterval to extract HPD intervals at 90
Convergence is assessed via the Heidelberger and Welch diagnostic (heidel.diag), evaluating stationarity and halfwidth adequacy.
A list containing:
Posterior mean estimate of .
Posterior median estimate of .
Posterior standard deviation of .
Highest Posterior Density interval at 90% level.
Highest Posterior Density interval at 95% level.
Highest Posterior Density interval at 99% level.
MCMC acceptance rate (convergence probability).
Heidelberger and Welch's convergence diagnostic summary.
Estimated convergence probability.
mcmc object of posterior samples.
set.seed(123) r_sample <- rmtl(50, alpha = 2.0) mcmc_fit <- mcmc_mtl(r_sample, n_iter = 2000, burn_in = 500) print(mcmc_fit$posterior_mean) print(mcmc_fit$hpd_95)set.seed(123) r_sample <- rmtl(50, alpha = 2.0) mcmc_fit <- mcmc_mtl(r_sample, n_iter = 2000, burn_in = 500) print(mcmc_fit$posterior_mean) print(mcmc_fit$hpd_95)
Computes the exact closed-form Maximum Likelihood Estimator (MLE) for the Modified Topp-Leone (MTL) parameter alpha, and evaluates non-parametric bootstrap confidence intervals at 90
mtl_mle(r) mtl_loglik(alpha, r) mtl_fisher(alpha, n) bootstrap_ci( y, X, n_boot = 100, conf_levels = c(0.9, 0.95, 0.99), num.trees = 100, seed = NULL )mtl_mle(r) mtl_loglik(alpha, r) mtl_fisher(alpha, n) bootstrap_ci( y, X, n_boot = 100, conf_levels = c(0.9, 0.95, 0.99), num.trees = 100, seed = NULL )
r |
Vector of absolute residuals. |
alpha |
Shape parameter |
n |
Number of observations. |
y |
Numeric vector of response values. |
X |
Data frame of predictor variables. |
n_boot |
Number of bootstrap iterations (default |
conf_levels |
Confidence levels for intervals (default |
num.trees |
Number of trees for bootstrap forest fits (default |
seed |
Optional integer seed for reproducibility. |
For independent absolute residuals , the log-likelihood function of the MTL distribution is:
Setting the score function yields the exact closed-form MLE:
Under the EM/MLE estimation method, because asymptotic distribution may be impacted by Stage 1 non-parametric Random Forest estimation, non-parametric bootstrap resampling is utilized to compute empirical confidence intervals at 90
mtl_mle returns the scalar MLE .
mtl_loglik returns the log-likelihood value.
mtl_fisher returns the expected Fisher information.
bootstrap_ci returns a list containing bootstrap distributions and confidence intervals at 90%, 95%, and 99% levels for alpha, bias, mse, and risk.
set.seed(123) r <- rmtl(50, alpha = 2.5) hat_alpha <- mtl_mle(r) print(hat_alpha)set.seed(123) r <- rmtl(50, alpha = 2.5) hat_alpha <- mtl_mle(r) print(hat_alpha)
Density, distribution function, quantile function, random generation, hazard function, and survival function for the Modified Topp-Leone (MTL) distribution with shape parameter alpha.
dmtl(x, alpha, log = FALSE) pmtl(q, alpha, lower.tail = TRUE, log.p = FALSE) qmtl(p, alpha, lower.tail = TRUE, log.p = FALSE) rmtl(n, alpha) smtl(x, alpha, log = FALSE) hmtl(x, alpha, log = FALSE)dmtl(x, alpha, log = FALSE) pmtl(q, alpha, lower.tail = TRUE, log.p = FALSE) qmtl(p, alpha, lower.tail = TRUE, log.p = FALSE) rmtl(n, alpha) smtl(x, alpha, log = FALSE) hmtl(x, alpha, log = FALSE)
x, q
|
Vector of quantiles. |
alpha |
Shape parameter ( |
log, log.p
|
Logical or character string indicating boolean evaluation ( |
lower.tail |
Logical or character string indicating boolean evaluation. If |
p |
Vector of probabilities. |
n |
Number of observations. If |
The Modified Topp-Leone (MTL) distribution is a continuous probability distribution defined on with shape parameter .
Its probability density function (PDF) is given by:
Its cumulative distribution function (CDF) is given by:
Its survival function (SF) is:
Its hazard rate function (HRF) is:
Its exact closed-form quantile function (QF) for probability is:
In log-stable computation, .
Random generation is performed by direct inversion sampling using runif.
dmtl gives the density, pmtl gives the distribution function, qmtl gives the exact quantile function, rmtl generates random deviates, hmtl gives the hazard function, and smtl gives the survival function.
# Evaluate PDF and CDF at x = 1, alpha = 2 dmtl(1, alpha = 2) pmtl(1, alpha = 2) # Quantile function qmtl(0.95, alpha = 2) # Survival and hazard functions smtl(1, alpha = 2) hmtl(1, alpha = 2) # Generate random samples set.seed(123) r_samples <- rmtl(10, alpha = 2) print(r_samples)# Evaluate PDF and CDF at x = 1, alpha = 2 dmtl(1, alpha = 2) pmtl(1, alpha = 2) # Quantile function qmtl(0.95, alpha = 2) # Survival and hazard functions smtl(1, alpha = 2) hmtl(1, alpha = 2) # Generate random samples set.seed(123) r_samples <- rmtl(10, alpha = 2) print(r_samples)
Performs goodness-of-fit hypothesis testing (Kolmogorov-Smirnov and Anderson-Darling tests) and evaluates information-theoretic criteria (AIC and BIC) for a fitted RF-MTL model.
mtl_diagnostics(object, ...)mtl_diagnostics(object, ...)
object |
A fitted object of class |
... |
Additional arguments (currently unused). |
Goodness-of-fit evaluates whether absolute residuals follow the Modified Topp-Leone distribution with estimated parameter .
Information criteria are defined as:
where (single shape parameter) and is the maximized MTL log-likelihood.
An S3 object of class "mtl_diagnostics", containing:
Kolmogorov-Smirnov test statistic .
Asymptotic p-value for the KS test.
Anderson-Darling test statistic .
p-value for the AD test via ad.test.
Maximized log-likelihood value.
Akaike Information Criterion.
Bayesian Information Criterion.
Estimated shape parameter .
Number of training observations.
set.seed(123) df <- data.frame(y = 5 + 2 * rnorm(50), x1 = rnorm(50), x2 = runif(50)) fit <- rf_mtl(y ~ x1 + x2, data = df, method = "em", num.trees = 50, n_boot = 20) diag_res <- mtl_diagnostics(fit) print(diag_res)set.seed(123) df <- data.frame(y = 5 + 2 * rnorm(50), x1 = rnorm(50), x2 = runif(50)) fit <- rf_mtl(y ~ x1 + x2, data = df, method = "em", num.trees = 50, n_boot = 20) diag_res <- mtl_diagnostics(fit) print(diag_res)
Generates point predictions and exact closed-form prediction intervals for new observations using a fitted "rf_mtl" object.
## S3 method for class 'rf_mtl' predict( object, newdata = NULL, level = 0.95, interval = c("none", "prediction"), ... )## S3 method for class 'rf_mtl' predict( object, newdata = NULL, level = 0.95, interval = c("none", "prediction"), ... )
object |
A fitted object of class |
newdata |
Data frame of new predictor observations. If omitted, fitted training values are returned. |
level |
Confidence level for prediction intervals (default |
interval |
Type of interval calculation: |
... |
Additional arguments passed to |
Point predictions are generated by ensembled Random Forest regression trees.
Prediction intervals at confidence level level (e.g. 0.95) are calculated via the exact closed-form Modified Topp-Leone quantile function:
where and .
If interval = "none", a numeric vector of point predictions is returned.
If interval = "prediction", a data frame containing columns fit (point prediction), lwr (lower prediction bound), and upr (upper prediction bound) is returned.
set.seed(123) df <- data.frame(y = 5 + 2 * rnorm(50), x1 = rnorm(50), x2 = runif(50)) fit <- rf_mtl(y ~ x1 + x2, data = df, method = "em", num.trees = 50, n_boot = 20) preds <- predict(fit, newdata = df[1:5, ], interval = "prediction", level = 0.95) print(preds)set.seed(123) df <- data.frame(y = 5 + 2 * rnorm(50), x1 = rnorm(50), x2 = runif(50)) fit <- rf_mtl(y ~ x1 + x2, data = df, method = "em", num.trees = 50, n_boot = 20) preds <- predict(fit, newdata = df[1:5, ], interval = "prediction", level = 0.95) print(preds)
Fits a Random Forest regression model combined with a Modified Topp-Leone (MTL) distribution error model. Supports parameter estimation via closed-form EM/MLE algorithm (with non-parametric bootstrap confidence intervals at 90
rf_mtl( formula, data, method = c("em", "mcmc"), num.trees = 500, n_boot = 100, n_iter = 5000, burn_in = 1000, conf_levels = c(0.9, 0.95, 0.99), na.action = stats::na.omit, seed = NULL, ... )rf_mtl( formula, data, method = c("em", "mcmc"), num.trees = 500, n_boot = 100, n_iter = 5000, burn_in = 1000, conf_levels = c(0.9, 0.95, 0.99), na.action = stats::na.omit, seed = NULL, ... )
formula |
Object of class |
data |
Data frame containing the variables in the model. |
method |
Estimation method: |
num.trees |
Number of trees in the Random Forest ensemble (default |
n_boot |
Number of bootstrap iterations for EM confidence intervals (default |
n_iter |
Number of MCMC iterations for Bayesian estimation (default |
burn_in |
Number of burn-in MCMC iterations (default |
conf_levels |
Confidence levels for intervals (default |
na.action |
Function specifying action for missing values (default |
seed |
Optional integer seed for reproducibility. |
... |
Additional arguments passed to |
The RF-MTL regression model assumes:
where is non-parametrically estimated by a Random Forest predictor, and absolute errors follow the Modified Topp-Leone distribution with shape parameter .
In Stage 1, Random Forest regression is fitted using ranger under the mean squared error criterion to predict point estimates .
In Stage 2, absolute residuals are modeled using the MTL error distribution.
Parameter estimation can be performed via:
EM / MLE Algorithm (method = "em"): Computes exact analytical closed-form MLE and uses non-parametric bootstrap resampling to evaluate confidence intervals at 90
Bayesian MCMC (method = "mcmc"): Draws MCMC posterior samples for via adaptive Metropolis-Hastings, computes Highest Posterior Density (HPD) intervals at 90
Missing values are processed according to the specified na.action. Logical parameters accept both standard R boolean flags (TRUE/FALSE) and character representations ("TRUE"/"FALSE").
An S3 object of class "rf_mtl", containing:
The fitted ranger Random Forest object.
Estimated Modified Topp-Leone shape parameter .
Estimation method used ("em" or "mcmc").
Fitted point predictions .
Raw residuals .
Absolute residuals .
Estimated model bias.
Mean squared error.
Root mean squared error.
Mean absolute error.
Model risk value (empirical squared loss).
Bootstrap confidence intervals (for EM) or HPD intervals (for MCMC) at 90%, 95%, and 99% levels.
Heidelberger and Welch convergence diagnostic summary (if method = "mcmc").
MCMC convergence probability / acceptance rate (if method = "mcmc").
Detailed bootstrap outputs if method = "em".
Detailed MCMC sampler outputs if method = "mcmc".
Model formula.
Processed training data frame.
Name of response variable.
Vector of predictor variable names.
# Fit RF-MTL model on synthetic regression data set.seed(123) df <- data.frame( y = 5 + 2 * rnorm(50), x1 = rnorm(50), x2 = runif(50) ) fit_em <- rf_mtl(y ~ x1 + x2, data = df, method = "em", num.trees = 50, n_boot = 30, seed = 123) print(fit_em)# Fit RF-MTL model on synthetic regression data set.seed(123) df <- data.frame( y = 5 + 2 * rnorm(50), x1 = rnorm(50), x2 = runif(50) ) fit_em <- rf_mtl(y ~ x1 + x2, data = df, method = "em", num.trees = 50, n_boot = 30, seed = 123) print(fit_em)
Print, summary, and plot methods for fitted "rf_mtl" objects.
## S3 method for class 'rf_mtl' print(x, ...) ## S3 method for class 'rf_mtl' summary(object, ...) ## S3 method for class 'summary_rf_mtl' print(x, ...) ## S3 method for class 'rf_mtl' plot(x, which = 1:3, ...)## S3 method for class 'rf_mtl' print(x, ...) ## S3 method for class 'rf_mtl' summary(object, ...) ## S3 method for class 'summary_rf_mtl' print(x, ...) ## S3 method for class 'rf_mtl' plot(x, which = 1:3, ...)
x, object
|
A fitted object of class |
which |
Vector of plot types to produce: |
... |
Additional arguments passed to generic print or plot functions. |
print.rf_mtl and print.summary_rf_mtl return the input object invisibly.
summary.rf_mtl returns a list of summary statistics.
plot.rf_mtl returns NULL invisibly and displays diagnostic graphics.
set.seed(123) df <- data.frame(y = 5 + 2 * rnorm(50), x1 = rnorm(50), x2 = runif(50)) fit <- rf_mtl(y ~ x1 + x2, data = df, method = "em", num.trees = 50, n_boot = 20) print(fit) summary(fit)set.seed(123) df <- data.frame(y = 5 + 2 * rnorm(50), x1 = rnorm(50), x2 = runif(50)) fit <- rf_mtl(y ~ x1 + x2, data = df, method = "em", num.trees = 50, n_boot = 20) print(fit) summary(fit)