| Title: | Parameter Estimation for Stable Distributions and Their Mixtures |
|---|---|
| Description: | Provides various functions for parameter estimation of one-dimensional stable distributions and their mixtures. It implements a diverse set of estimation methods, including quantile-based approaches, regression methods based on the empirical characteristic function (empirical, kernel, and recursive), and maximum likelihood estimation. For mixture models, it provides stochastic expectation–maximization (SEM) algorithms and Bayesian estimation methods using sampling and importance sampling to overcome the long burn-in period of Markov Chain Monte Carlo (MCMC) strategies. The package also includes tools and statistical tests for analyzing whether a dataset follows a stable distribution. Some of the implemented methods are described in Hajjaji, O., Manou-Abi, S. M., and Slaoui, Y. (2024) <doi:10.1080/02664763.2024.2434627>. |
| Authors: | Solym Manou-Abi [aut, cre], Adam Najib [aut], Yousri Slaoui [aut] |
| Maintainer: | Solym Manou-Abi <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-06-01 10:17:49 UTC |
| Source: | https://github.com/cran/MixStable |
Computes the AIC value given a log-likelihood and number of parameters.
aic(log_likelihood, num_params)aic(log_likelihood, num_params)
log_likelihood |
Log-likelihood value. |
num_params |
Number of estimated parameters. |
AIC value.
Executes the full pipeline for stability analysis: normality tests, QCV computation, parameter estimation, plotting, and report export.
analyse_stable_distribution( x, filename = "interval_analysis", qcv_threshold = 1.8, fig_path = NULL, verbose = FALSE )analyse_stable_distribution( x, filename = "interval_analysis", qcv_threshold = 1.8, fig_path = NULL, verbose = FALSE )
x |
Numeric vector of data. |
filename |
Base name for output files (JSON and Excel). Written to tempdir(). |
qcv_threshold |
Threshold for QCV to consider distribution heavy-tailed. |
fig_path |
Optional path to save the plot (PNG). If NULL, uses tempdir(). |
verbose |
Logical; if TRUE, prints progress messages. Default is FALSE. |
Invisibly returns a character string containing a Markdown-formatted summary report.
Bayesian mixture model using normal components (simplified)
bayesian_mixture_model(data, draws = 1000, chains = 2)bayesian_mixture_model(data, draws = 1000, chains = 2)
data |
Numeric vector of observations. |
draws |
Number of iterations per chain. |
chains |
Number of chains to simulate. |
List containing model fit, chains, weights, means, and standard deviations.
Computes the BIC value given a log-likelihood, number of parameters, and sample size.
bic(log_likelihood, num_params, n)bic(log_likelihood, num_params, n)
log_likelihood |
Log-likelihood value. |
num_params |
Number of estimated parameters. |
n |
Sample size. |
BIC value.
Constructs nearest-neighbor interpolation functions for alpha and beta based on quantile ratios (v_alpha, v_beta) from the lookup table.
build_mcculloch_interpolators(table)build_mcculloch_interpolators(table)
table |
Lookup table generated by generate_mcculloch_table. |
List with functions interp_alpha and interp_beta.
Computes a placeholder log-likelihood value based on squared deviations from the mean. This is not a true likelihood function and is used for testing or comparison purposes.
calculate_log_likelihood(data, params)calculate_log_likelihood(data, params)
data |
Numeric vector of observations. |
params |
Vector of parameters (not used in this placeholder). |
Scalar value representing the pseudo log-likelihood.
Estimate stable distribution parameters using classical ECF regression
CDF(x, u)CDF(x, u)
x |
Numeric vector of data. |
u |
Vector of frequency values. |
A list with estimated parameters: alpha, beta, gamma, and delta.
Clip values between lower and upper bounds
clip(x, lower, upper)clip(x, lower, upper)
x |
Numeric input. |
lower |
Minimum allowed value. |
upper |
Maximum allowed value. |
Clipped numeric vector.
Compares log-likelihood and weight estimates between standard EM and EM with Gibbs sampling.
compare_em_vs_em_gibbs(data, n_runs = 20)compare_em_vs_em_gibbs(data, n_runs = 20)
data |
Numeric vector. Observed data. |
n_runs |
Integer. Number of runs for comparison. |
Data frame with log-likelihoods and weights for each method across runs.
Runs multiple simulations and compares the mean squared error (MSE) of parameter estimates from MLE, kernel ECF, and McCulloch methods.
compare_estimators_on_simulations( n_samples = 1000, n_runs = 30, interp_alpha = NULL, interp_beta = NULL )compare_estimators_on_simulations( n_samples = 1000, n_runs = 30, interp_alpha = NULL, interp_beta = NULL )
n_samples |
Integer. Number of samples per simulation. |
n_runs |
Integer. Number of simulation runs. |
interp_alpha |
Optional interpolation function for alpha (McCulloch). |
interp_beta |
Optional interpolation function for beta (McCulloch). |
Data frame of simulation results with MSE and estimated parameters.
Evaluates and compares three estimation methods (McCulloch, ECF, MLE) over a set of parameter configurations.
compare_methods_across_configs(parameter_configs, trials = 20, n = 1000)compare_methods_across_configs(parameter_configs, trials = 20, n = 1000)
parameter_configs |
Named list of parameter sets (each a list with alpha, beta, gamma, delta). |
trials |
Integer. Number of trials per configuration. |
n |
Integer. Number of samples per trial. |
A named list of results with MSE values for each method and configuration.
Visualizes and compares mixture fits from EM, ECF (kernel and empirical), and Gibbs sampling.
compare_methods_with_gibbs( data, em_params, ecf_kernel_params, ecf_empirical_params, fig_dir = tempdir() )compare_methods_with_gibbs( data, em_params, ecf_kernel_params, ecf_empirical_params, fig_dir = tempdir() )
data |
Numeric vector of observations. |
em_params |
List of EM-estimated parameters. |
ecf_kernel_params |
List of kernel ECF-estimated parameters. |
ecf_empirical_params |
List of empirical ECF-estimated parameters. |
fig_dir |
Optional path to save plots. Defaults to tempdir(). |
NULL (plots are saved to fig_dir)
Evaluates the model fit by computing the log-likelihood, AIC, and BIC for a given set of alpha-stable parameters.
compute_model_metrics(data, params)compute_model_metrics(data, params)
data |
Numeric vector of observations. |
params |
Vector of parameters: alpha, beta, gamma, delta. |
List with log_likelihood, AIC, BIC, and optional error message.
This function calculates four key ratios used in McCulloch's method for estimating stable distribution parameters: - v_alpha: shape indicator - v_beta: skewness indicator - v_gamma: scale proxy - v_delta: location proxy
compute_quantile_ratios(X)compute_quantile_ratios(X)
X |
Numeric vector of sample data. |
A list containing v_alpha, v_beta, v_gamma, and v_delta.
Calculates the serial interval from a CSV file containing date columns.
compute_serial_interval(filepath)compute_serial_interval(filepath)
filepath |
Character. Path to the CSV file. |
Numeric vector of serial intervals.
Cosine exponential function
cosine_exp_ralpha(r, x, alpha, beta, delta, omega)cosine_exp_ralpha(r, x, alpha, beta, delta, omega)
r |
Integration variable. |
x |
Observation. |
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
Numeric value of the integrand.
Cosine-log-weighted exponential with r^(-alpha) term
cosine_log_weighted_exp_ralpha(r, x, alpha, beta, delta, omega)cosine_log_weighted_exp_ralpha(r, x, alpha, beta, delta, omega)
r |
Integration variable. |
x |
Observation. |
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
Numeric value of the integrand.
A data frame containing serial interval information for transmission pairs.
data(DONNEE_with_serial_interval)data(DONNEE_with_serial_interval)
A data frame with columns:
Integer. Unique identifier.
Date. Lower bound of infector symptom onset (YYYY-MM-DD).
Date. Upper bound of infector symptom onset (YYYY-MM-DD).
Date. Infectee symptom onset (YYYY-MM-DD).
Integer. Serial interval in days.
Simulated or real data for demonstration.
Extract magnitude and phase components from ECF
ecf_components(phi_vals)ecf_components(phi_vals)
phi_vals |
Complex vector of ECF values |
A list with two numeric vectors: y_vals (log-log magnitude) and arg_vals (phase).
Compute empirical characteristic function
ecf_empirical(X, t_grid)ecf_empirical(X, t_grid)
X |
Numeric vector of data |
t_grid |
Vector of frequency values |
Complex vector of empirical characteristic function values.
Estimate all stable parameters from empirical characteristic function
ecf_estimate_all(X, t_grid = NULL, weights = NULL)ecf_estimate_all(X, t_grid = NULL, weights = NULL)
X |
Numeric vector of data. |
t_grid |
Optional vector of frequencies (default: seq(0.1, 1.0, length.out = 50)). |
weights |
Optional vector of weights. |
A list containing estimated parameters: alpha, beta,
gamma, and delta.
Empirical Characteristic Function
ecf_fn(x, u, method = "simple")ecf_fn(x, u, method = "simple")
x |
Numeric vector of data. |
u |
Numeric vector of frequencies. |
method |
Method: "simple", "kernel", or "recursive". |
List with magnitude and phase of ECF.
Estimate stable parameters using weighted ECF regression
ecf_regression(x, u)ecf_regression(x, u)
x |
Numeric vector of data. |
u |
Vector of frequency values. |
A list with estimated parameters: alpha, beta, gamma, and delta.
Estimates parameters of an alpha-stable mixture using EM with optional random initialization.
em_alpha_stable( data, n_components = 2, max_iter = 100, tol = 1e-04, random_init = TRUE, debug = TRUE )em_alpha_stable( data, n_components = 2, max_iter = 100, tol = 1e-04, random_init = TRUE, debug = TRUE )
data |
Numeric vector of observations. |
n_components |
Integer. Number of mixture components. |
max_iter |
Integer. Maximum number of EM iterations. |
tol |
Numeric. Convergence tolerance. |
random_init |
Logical. Whether to use random initialization. |
debug |
Logical. Whether to print debug information. |
List with estimated weights and parameters (alpha, beta, gamma, delta).
Performs EM estimation of a two-component alpha-stable mixture using a simplified empirical characteristic function derived from the cumulative distribution function (CDF).
em_estimate_stable_from_cdf(data, max_iter = 100, tol = 1e-04)em_estimate_stable_from_cdf(data, max_iter = 100, tol = 1e-04)
data |
Numeric vector of observations. |
max_iter |
Maximum number of EM iterations. |
tol |
Convergence tolerance on log-likelihood. |
A list with estimated component parameters (alpha, beta, gamma, delta) and mixture weight (w).
Performs EM estimation of a two-component alpha-stable mixture using a simplified empirical characteristic function derived from the cumulative distribution function (CDF), with the M-step replaced by Gibbs sampling.
em_estimate_stable_from_cdf_with_gibbs(data, max_iter = 100, tol = 1e-04)em_estimate_stable_from_cdf_with_gibbs(data, max_iter = 100, tol = 1e-04)
data |
Numeric vector of observations. |
max_iter |
Maximum number of EM iterations. |
tol |
Convergence tolerance on log-likelihood. |
A list with estimated component parameters (alpha, beta, gamma, delta) and mixture weight (w).
Performs EM estimation of a two-component alpha-stable mixture using kernel-smoothed empirical characteristic function (ECF).
em_estimate_stable_kernel_ecf(data, max_iter = 100, tol = 1e-04)em_estimate_stable_kernel_ecf(data, max_iter = 100, tol = 1e-04)
data |
Numeric vector of observations. |
max_iter |
Maximum number of EM iterations. |
tol |
Convergence tolerance on log-likelihood. |
A list with estimated component parameters (alpha, beta, gamma, delta) and mixture weight (w).
Performs EM estimation of a two-component alpha-stable mixture using kernel-smoothed empirical characteristic function (ECF), with the M-step replaced by Gibbs sampling.
em_estimate_stable_kernel_ecf_with_gibbs(data, max_iter = 100, tol = 1e-04)em_estimate_stable_kernel_ecf_with_gibbs(data, max_iter = 100, tol = 1e-04)
data |
Numeric vector of observations. |
max_iter |
Maximum number of EM iterations. |
tol |
Convergence tolerance on log-likelihood. |
A list with estimated component parameters (alpha, beta, gamma, delta) and mixture weight (w).
Performs Expectation-Maximization (EM) to estimate parameters of a two-component alpha-stable mixture model using recursive kernel smoothing on the empirical characteristic function.
em_estimate_stable_recursive_ecf(data, max_iter = 100, tol = 1e-04)em_estimate_stable_recursive_ecf(data, max_iter = 100, tol = 1e-04)
data |
Numeric vector of observations. |
max_iter |
Maximum number of EM iterations. |
tol |
Convergence tolerance on log-likelihood. |
A list with estimated component parameters (alpha, beta, gamma, delta) and mixture weight (w).
Performs EM estimation of a two-component alpha-stable mixture using recursive kernel smoothing on the empirical characteristic function (ECF), with the M-step replaced by Gibbs sampling.
em_estimate_stable_recursive_ecf_with_gibbs(data, max_iter = 100, tol = 1e-04)em_estimate_stable_recursive_ecf_with_gibbs(data, max_iter = 100, tol = 1e-04)
data |
Numeric vector of observations. |
max_iter |
Maximum number of EM iterations. |
tol |
Convergence tolerance on log-likelihood. |
A list with estimated component parameters (alpha, beta, gamma, delta) and mixture weight (w).
Performs EM estimation of a two-component alpha-stable mixture using weighted least squares regression on the ECF.
em_estimate_stable_weighted_ols(data, max_iter = 100, tol = 1e-04)em_estimate_stable_weighted_ols(data, max_iter = 100, tol = 1e-04)
data |
Numeric vector of observations. |
max_iter |
Maximum number of EM iterations. |
tol |
Convergence tolerance on log-likelihood. |
A list with estimated component parameters (alpha, beta, gamma, delta) and mixture weight (w).
Performs EM estimation of a two-component alpha-stable mixture using weighted least squares regression on the ECF, with the M-step replaced by Gibbs sampling.
em_estimate_stable_weighted_ols_with_gibbs(data, max_iter = 100, tol = 1e-04)em_estimate_stable_weighted_ols_with_gibbs(data, max_iter = 100, tol = 1e-04)
data |
Numeric vector of observations. |
max_iter |
Maximum number of EM iterations. |
tol |
Convergence tolerance on log-likelihood. |
A list with estimated component parameters (alpha, beta, gamma, delta) and mixture weight (w).
Estimates parameters of a Gaussian mixture using the EM algorithm.
em_estimation_mixture(data, max_iter = 100, tol = 1e-06)em_estimation_mixture(data, max_iter = 100, tol = 1e-06)
data |
Numeric vector of observations. |
max_iter |
Integer. Maximum number of EM iterations. |
tol |
Numeric. Convergence tolerance. |
A list containing estimated mixture parameters: pi, mu1, mu2, sigma1, sigma2.
Estimates parameters of a two-component alpha-stable mixture using MLE and EM.
em_fit_alpha_stable_mixture( data, max_iter = 200, tol = 1e-04, return_trace = FALSE )em_fit_alpha_stable_mixture( data, max_iter = 200, tol = 1e-04, return_trace = FALSE )
data |
Numeric vector of observations. |
max_iter |
Integer. Maximum number of EM iterations. |
tol |
Numeric. Convergence tolerance on log-likelihood. |
return_trace |
Logical. Whether to return trace of responsibilities and log-likelihoods. |
List with estimated parameters and optional trace.
Performs EM estimation using a user-defined parameter estimator and ECF frequencies.
em_stable_mixture(data, u, estimator_func, max_iter = 300, epsilon = 0.001)em_stable_mixture(data, u, estimator_func, max_iter = 300, epsilon = 0.001)
data |
Numeric vector of observations. |
u |
Numeric vector of frequency values for ECF. |
estimator_func |
Function to estimate stable parameters. |
max_iter |
Integer. Maximum number of EM iterations. |
epsilon |
Numeric. Convergence threshold on log-likelihood. |
List with estimated weights, parameters, and log-likelihood.
Estimates the basic reproduction number (R0) using a growth model (exponential or logistic) fitted to incidence data.
empirical_r0(incidence, serial_interval, growth_model = "exponential")empirical_r0(incidence, serial_interval, growth_model = "exponential")
incidence |
Numeric vector of incidence counts. |
serial_interval |
Mean serial interval. |
growth_model |
Type of growth model: "exponential" or "logistic". |
Estimated R0 value.
Ensure positive scale parameter
ensure_positive_scale(val, min_scale = 1e-06, max_scale = 1e+06)ensure_positive_scale(val, min_scale = 1e-06, max_scale = 1e+06)
val |
Numeric input. |
min_scale |
Minimum scale. |
max_scale |
Maximum scale. |
A finite positive scale value.
Computes the basic reproduction number (R0) using a maximum likelihood approach based on secondary cases and generation time weights.
est_r0_ml(W, N)est_r0_ml(W, N)
W |
Generation time distribution. |
N |
Secondary case counts. |
Estimated R0 value.
Estimates the basic reproduction number (R0) using maximum likelihood and a parametric model based on generation time and incidence data.
est_r0_mle(incidence, gen_time)est_r0_mle(incidence, gen_time)
incidence |
Numeric vector of incidence counts. |
gen_time |
Mean generation time. |
Estimated R0 value.
Estimate alpha and gamma from ECF modulus
estimate_alpha_gamma(t_grid, phi_vals, weights = NULL)estimate_alpha_gamma(t_grid, phi_vals, weights = NULL)
t_grid |
Vector of frequency values. |
phi_vals |
Complex vector of ECF values. |
weights |
Optional vector of weights. |
A list with elements alpha_hat and gamma_hat.
Estimate beta and delta from ECF phase
estimate_beta_delta(t_grid, phi_vals, alpha_hat, gamma_hat, weights = NULL)estimate_beta_delta(t_grid, phi_vals, alpha_hat, gamma_hat, weights = NULL)
t_grid |
Vector of frequency values. |
phi_vals |
Complex vector of ECF values. |
alpha_hat |
Estimated alpha. |
gamma_hat |
Estimated gamma. |
weights |
Optional vector of weights. |
A list with elements beta_hat and delta_hat.
Wrapper function to estimate parameters of a two-component alpha-stable mixture using MLE.
estimate_mixture_params(data)estimate_mixture_params(data)
data |
Numeric vector of observations. |
List with estimated weight and parameters for both components.
Estimate stable parameters using CDF-based ECF regression
estimate_stable_from_cdf(data, u)estimate_stable_from_cdf(data, u)
data |
Numeric vector of observations |
u |
Vector of frequency values |
A list with estimated parameters: alpha, beta, gamma, and delta.
Estimate stable parameters using kernel-based ECF method
estimate_stable_kernel_ecf(data, u)estimate_stable_kernel_ecf(data, u)
data |
Numeric vector of observations |
u |
Vector of frequency values |
A list with estimated parameters: alpha, beta, gamma, and delta.
Wrapper function to estimate stable parameters using one of three methods: "basic", "robust", or "lbfgs".
estimate_stable_params(data, method = "robust")estimate_stable_params(data, method = "robust")
data |
Numeric vector of observations. |
method |
Estimation method: "basic", "robust", or "lbfgs". |
List with estimated alpha, beta, gamma, delta.
Provides a rough estimation of alpha-stable parameters using empirical moments.
estimate_stable_r(x)estimate_stable_r(x)
x |
Numeric vector of data. |
List with estimated alpha, beta, gamma, delta.
Estimate stable parameters using recursive ECF method
estimate_stable_recursive_ecf(data, u)estimate_stable_recursive_ecf(data, u)
data |
Numeric vector of observations. |
u |
Vector of frequency values. |
A list with estimated parameters: alpha, beta, gamma, and delta.
Estimate stable parameters using weighted OLS on recursive ECF
estimate_stable_weighted_ols(data, u)estimate_stable_weighted_ols(data, u)
data |
Numeric vector of observations |
u |
Vector of frequency values |
A list with estimated parameters: alpha, beta, gamma, and delta.
General eta function
eta_func(t, alpha, gamma)eta_func(t, alpha, gamma)
t |
Frequency vector. |
alpha |
Stability parameter. |
gamma |
Scale parameter. |
Numeric vector of eta values.
Helper function for eta0 computation
eta0(u, alpha, gamma, eps = 0.05)eta0(u, alpha, gamma, eps = 0.05)
u |
Frequency vector. |
alpha |
Stability parameter. |
gamma |
Scale parameter. |
eps |
Tolerance for |
Numeric vector of eta0 values.
Computes the mean squared error (MSE) of a parameter estimation function over several trials.
evaluate_estimation_method( estimator_fn, true_params, n = 1000, trials = 20, seed = 42 )evaluate_estimation_method( estimator_fn, true_params, n = 1000, trials = 20, seed = 42 )
estimator_fn |
Function. Estimation function to evaluate. |
true_params |
List. True parameters: alpha, beta, gamma, delta. |
n |
Integer. Number of samples per trial. |
trials |
Integer. Number of trials to run. |
seed |
Integer. Random seed for reproducibility. |
Numeric value representing the average MSE across trials.
Computes RMSE and log-likelihood scores for different mixture models compared to histogram data.
evaluate_fit(data, methods, x_vals)evaluate_fit(data, methods, x_vals)
data |
Numeric vector of observations. |
methods |
Named list of parameter sets (each with two components and a weight). |
x_vals |
Numeric vector. Evaluation grid. |
Named list of scores per method (RMSE and LogLikelihood).
Saves the results of a stability analysis to a JSON file and an Excel workbook.
export_analysis_report( data, stable_params, qcv, skew_kurt, normality, verdict, filename = "stable_report" )export_analysis_report( data, stable_params, qcv, skew_kurt, normality, verdict, filename = "stable_report" )
data |
Numeric vector of data. |
stable_params |
List of estimated stable parameters. |
qcv |
QCV statistic. |
skew_kurt |
List with skewness and kurtosis. |
normality |
List of normality test results. |
verdict |
Final verdict string. |
filename |
Base name for output files. |
Invisibly returns a list containing the paths of the exported JSON and Excel files.
Performs a single iteration of the false position (regula falsi) method for root-finding. This method approximates the root of a function by using a linear interpolation between two points where the function changes sign.
false_position_update(a, b_n, f_a, f_b, objective_func)false_position_update(a, b_n, f_a, f_b, objective_func)
a |
Numeric scalar. Left bound of the interval. |
b_n |
Numeric scalar. Right bound of the interval (current step). |
f_a |
Numeric scalar. Value of the objective function evaluated at 'a'. |
f_b |
Numeric scalar. Value of the objective function evaluated at 'b_n'. |
objective_func |
Function. The objective function whose root is being sought. |
Numeric scalar. Updated estimate for the root after one iteration.
Fast numerical integration using trapezoidal rule
fast_integrate(func, a = -6, b = 6, N = 100)fast_integrate(func, a = -6, b = 6, N = 100)
func |
Function to integrate. |
a |
Lower bound. |
b |
Upper bound. |
N |
Number of points. |
Approximated integral value.
Estimates the parameters of a single alpha-stable distribution using maximum likelihood and the L-BFGS-B optimization method.
fit_alpha_stable_mle(data)fit_alpha_stable_mle(data)
data |
Numeric vector of observations. |
Numeric vector of estimated parameters: alpha, beta, gamma, delta.
Estimates parameters of a two-component alpha-stable mixture using maximum likelihood and the L-BFGS-B optimization method.
fit_mle_mixture(data)fit_mle_mixture(data)
data |
Numeric vector of observations. |
Numeric vector of estimated parameters: weight, alpha1, beta1, gamma1, delta1, alpha2, beta2, gamma2, delta2.
Estimate stable parameters using filtered and weighted ECF regression
fit_stable_ecf(data, frequencies)fit_stable_ecf(data, frequencies)
data |
Numeric vector of observations. |
frequencies |
Vector of frequency values. |
A list with estimated parameters: alpha, beta, gamma, and delta.
Simulates samples from a mixture of alpha-stable distributions using specified parameters.
generate_alpha_stable_mixture( weights, alphas, betas, gammas, deltas, size = 1000 )generate_alpha_stable_mixture( weights, alphas, betas, gammas, deltas, size = 1000 )
weights |
Numeric vector of mixture weights. |
alphas |
Numeric vector of alpha parameters. |
betas |
Numeric vector of beta parameters. |
gammas |
Numeric vector of gamma parameters. |
deltas |
Numeric vector of delta parameters. |
size |
Integer. Number of samples to generate. |
A list with:
Numeric vector of generated samples.
Integer vector indicating the component each sample came from.
Simulates alpha-stable samples across a grid of alpha and beta values, and computes quantile-based ratios used for McCulloch estimation. The result is a lookup table indexed by (alpha, beta) keys.
generate_mcculloch_table(alpha_grid, beta_grid, size = 1e+05)generate_mcculloch_table(alpha_grid, beta_grid, size = 1e+05)
alpha_grid |
Vector of alpha values to simulate. |
beta_grid |
Vector of beta values to simulate. |
size |
Number of samples per simulation. |
Named list of quantile ratios indexed by "alpha_beta".
Simulates a mixture of alpha-stable distributions with randomly sampled parameters.
generate_mixture_data(K = 2, N = 1000)generate_mixture_data(K = 2, N = 1000)
K |
Integer. Number of mixture components. |
N |
Integer. Total number of samples to generate. |
A list containing:
Numeric vector of generated samples.
List of parameters for each component (alpha, beta, gamma, delta, pi).
Creates a synthetic dataset composed of two alpha-stable distributions.
generate_synthetic_data(n = 1000)generate_synthetic_data(n = 1000)
n |
Integer. Total number of samples to generate. |
Numeric vector of shuffled synthetic data.
Performs Gibbs sampling for a two-component Gaussian mixture model. Updates latent assignments, component means, variances, and mixing proportions.
gibbs_sampler(data, iterations = 1000)gibbs_sampler(data, iterations = 1000)
data |
Numeric vector of observations. |
iterations |
Number of Gibbs iterations. |
List of sampled parameters per iteration.
Log-likelihood gradient with respect to alpha
grad_loglik_alpha(alpha, beta, delta, omega, x)grad_loglik_alpha(alpha, beta, delta, omega, x)
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
x |
Numeric vector. Observations at which the integral is computed. |
Numeric scalar: estimated gradient (or NA_real_ on invalid input).
Log-likelihood gradient with respect to beta
grad_loglik_beta(alpha, beta, delta, omega, x)grad_loglik_beta(alpha, beta, delta, omega, x)
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
x |
Numeric vector. Observations at which the integral is computed. |
Numeric scalar: estimated gradient (or NA_real_ on invalid input).
Log-likelihood gradient with respect to delta (scale)
grad_loglik_delta(alpha, beta, delta, omega, x)grad_loglik_delta(alpha, beta, delta, omega, x)
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
x |
Numeric vector. Observations at which the integral is computed. |
Numeric scalar: estimated gradient (or NA_real_ on invalid input).
Log-likelihood gradient with respect to omega (location)
grad_loglik_omega(alpha, beta, delta, omega, x)grad_loglik_omega(alpha, beta, delta, omega, x)
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
x |
Numeric vector. Observations at which the integral is computed. |
Numeric scalar: estimated gradient (or NA_real_ on invalid input).
Imaginary part of the ECF integral
Im(r, u, x, bn)Im(r, u, x, bn)
r |
Integration variable. |
u |
Frequency. |
x |
Data point. |
bn |
Bandwidth. |
Imaginary component value.
Integrate imaginary component over
Int_Im(u, x, bn)Int_Im(u, x, bn)
u |
Frequency. |
x |
Data point. |
bn |
Bandwidth. |
Integrated imaginary value.
Integrate real component over
Int_Re(u, x, bn)Int_Re(u, x, bn)
u |
Frequency. |
x |
Data point. |
bn |
Bandwidth. |
Integrated real value.
Computes the integral of the cosine exponential function for stable distributions.
integrate_cosine(x, alpha, beta, delta, omega)integrate_cosine(x, alpha, beta, delta, omega)
x |
Numeric vector. Observations at which the integral is computed. |
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
Numeric vector of integral values.
Computes the integral of the cosine-log-weighted exponential function for stable distributions.
integrate_cosine_log_weighted(x, alpha, beta, delta, omega)integrate_cosine_log_weighted(x, alpha, beta, delta, omega)
x |
Numeric vector. Observations at which the integral is computed. |
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
Numeric vector of integral values.
Applies 'safe_integrate' to a given integrand over a vector of x values.
integrate_function(f, x, alpha, beta, delta, omega, upper = 50, eps = 1e-08)integrate_function(f, x, alpha, beta, delta, omega, upper = 50, eps = 1e-08)
f |
Function. The integrand function to be evaluated. |
x |
Numeric vector. Observations at which the integral is computed. |
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
upper |
Numeric scalar. Upper limit of integration (default = 50). |
eps |
Numeric scalar. Tolerance for numerical integration (default = 1e-8). |
Numeric vector of integral values evaluated at each element of x.
Computes the integral of the sin exponential function for stable distributions.
integrate_sine(x, alpha, beta, delta, omega)integrate_sine(x, alpha, beta, delta, omega)
x |
Numeric vector. Observations at which the integral is computed. |
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
Numeric vector of integral values.
Computes the integral of the sine-log-weighted exponential function for stable distributions.
integrate_sine_log_weighted(x, alpha, beta, delta, omega)integrate_sine_log_weighted(x, alpha, beta, delta, omega)
x |
Numeric vector. Observations at which the integral is computed. |
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
Numeric vector of integral values.
Computes the integral of the sine-r-weighted exponential function for stable distributions.
integrate_sine_r_weighted(x, alpha, beta, delta, omega)integrate_sine_r_weighted(x, alpha, beta, delta, omega)
x |
Numeric vector. Observations at which the integral is computed. |
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
Numeric vector of integral values.
Integration wrappers for specific integrands
integrate_sine_weighted(x, alpha, beta, delta, omega)integrate_sine_weighted(x, alpha, beta, delta, omega)
x |
Numeric vector. Observations at which the integral is computed. |
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
Numeric vector of integral values.
KDE bandwidth selection using plugin method
kde_bandwidth_plugin(X, alpha)kde_bandwidth_plugin(X, alpha)
X |
Numeric vector of data. |
alpha |
Stability parameter. |
Bandwidth value.
Computes the negative log-likelihood of a stable distribution given parameters and data.
L_stable(param, obs)L_stable(param, obs)
param |
Numeric vector of parameters: alpha, beta, gamma, delta. |
obs |
Numeric vector of observations. |
Scalar value of negative log-likelihood.
Log-likelihood for mixture of stable distributions
log_likelihood_mixture(params, data)log_likelihood_mixture(params, data)
params |
Numeric vector of parameters. |
data |
Numeric vector of observations. |
Negative log-likelihood (for minimization).
Estimates parameters of a stable distribution using the Nelder-Mead method with penalty constraints.
Max_vrai(x)Max_vrai(x)
x |
Numeric vector of observations. |
List with estimated alpha, beta, gamma, delta.
Estimates alpha and beta using quantile ratios and interpolation functions. Gamma and delta are derived directly from quantiles.
mcculloch_lookup_estimate( X, interpolators = NULL, interp_alpha = NULL, interp_beta = NULL )mcculloch_lookup_estimate( X, interpolators = NULL, interp_alpha = NULL, interp_beta = NULL )
X |
Numeric vector of data. |
interpolators |
Optional list with interp_alpha and interp_beta functions. |
interp_alpha |
Optional function to interpolate alpha. |
interp_beta |
Optional function to interpolate beta. |
List with estimated alpha, beta, gamma, delta.
Estimates all four stable parameters using quantile ratios and mock lookup. Useful for initializing optimization algorithms.
mcculloch_quantile_init(X)mcculloch_quantile_init(X)
X |
Numeric vector of data. |
List with estimated alpha, beta, gamma, delta.
Performs Metropolis-Hastings sampling to estimate parameters of a two-component alpha-stable mixture model. Proposals are generated for each parameter and accepted based on likelihood ratios. Cluster assignments are updated at each iteration.
metropolis_hastings(fct, iterations, lok, aa = c(1, 1), proposal_std = 0.1)metropolis_hastings(fct, iterations, lok, aa = c(1, 1), proposal_std = 0.1)
fct |
Function to estimate initial parameters. |
iterations |
Number of MCMC iterations. |
lok |
Numeric vector of observations. |
aa |
Prior parameters for Dirichlet distribution. |
proposal_std |
Standard deviation for proposal distributions. |
List of sampled parameters and weights across iterations.
Mixture of two stable PDFs
mixture_stable_pdf(x, p1, p2, w)mixture_stable_pdf(x, p1, p2, w)
x |
Numeric vector. |
p1 |
List of parameters for first stable distribution. |
p2 |
List of parameters for second stable distribution. |
w |
Mixture weight (0 < w < 1). |
Numeric vector of mixture PDF values.
Estimates stable distribution parameters using Nelder-Mead optimization from default or user-provided starting values.
mle_estimate(X, x0 = NULL)mle_estimate(X, x0 = NULL)
X |
Numeric vector of observations. |
x0 |
Optional starting values. |
List with estimated alpha, beta, gamma, delta.
Performs a simplified Gibbs sampling procedure to estimate parameters of a two-component alpha-stable mixture. Samples are drawn from prior distributions and evaluated using log-likelihood. The best parameter set is selected based on likelihood.
mock_gibbs_sampling(data, n_samples = 500, verbose = FALSE)mock_gibbs_sampling(data, n_samples = 500, verbose = FALSE)
data |
Numeric vector of observations. |
n_samples |
Number of Gibbs samples to draw. |
verbose |
Logical, whether to print best log-likelihood. |
List containing best_params and all sampled parameter sets.
Provides a fallback estimation of alpha and beta from quantile ratios using simple linear approximations.
mock_lookup_alpha_beta(v_alpha, v_beta)mock_lookup_alpha_beta(v_alpha, v_beta)
v_alpha |
Quantile-based shape ratio. |
v_beta |
Quantile-based skewness ratio. |
List with estimated alpha and beta.
Epanechnikov kernel
N_epanechnikov(z)N_epanechnikov(z)
z |
Numeric input. |
Kernel value.
Gaussian kernel
N_gaussian(z)N_gaussian(z)
z |
Numeric input. |
Kernel value.
Uniform kernel
N_uniform(z)N_uniform(z)
z |
Numeric input. |
Kernel value.
Negative log-likelihood for single stable distribution
negative_log_likelihood(params, data)negative_log_likelihood(params, data)
params |
Numeric vector (alpha, beta, gamma, delta). |
data |
Numeric vector of observations. |
Negative log-likelihood.
Normalized gradient for alpha parameter Computes the normalized gradient of the log-likelihood with respect to the alpha parameter over a set of observations. This is useful for optimization routines where scale-invariant updates are preferred.
normalized_grad_alpha(alpha, beta, delta, omega, x)normalized_grad_alpha(alpha, beta, delta, omega, x)
alpha |
Stability parameter. |
beta |
Skewness parameter. |
delta |
Scale parameter. |
omega |
Location parameter. |
x |
Numeric vector of observations. |
Scalar value representing the normalized gradient.
Computes the normalized gradient of the log-likelihood with respect to the beta parameter using the latest values of alpha, delta, and omega stored in global vectors.
normalized_objective_beta(beta, X1, L_alpha, L_delta, L_omega)normalized_objective_beta(beta, X1, L_alpha, L_delta, L_omega)
beta |
Skewness parameter. |
X1 |
Numeric vector of observations. |
L_alpha |
Vector of alpha values (global memory). |
L_delta |
Vector of delta values (global memory). |
L_omega |
Vector of omega values (global memory). |
Scalar value representing the normalized gradient.
Computes the normalized gradient of the log-likelihood with respect to the delta parameter using the latest values of alpha, beta, and omega stored in global vectors.
normalized_objective_delta(delta, X1, L_alpha, L_beta, L_omega)normalized_objective_delta(delta, X1, L_alpha, L_beta, L_omega)
delta |
Location parameter. |
X1 |
Numeric vector of observations. |
L_alpha |
Vector of alpha values. |
L_beta |
Vector of beta values. |
L_omega |
Vector of omega values. |
Scalar value representing the normalized gra
Computes the normalized gradient of the log-likelihood with respect to the omega parameter using the latest values of alpha, beta, and delta stored in global vectors.
normalized_objective_omega(omega, X1, L_alpha, L_beta, L_delta)normalized_objective_omega(omega, X1, L_alpha, L_beta, L_delta)
omega |
Location parameter. |
X1 |
Numeric vector of observations. |
L_alpha |
Vector of alpha values. |
L_beta |
Vector of beta values. |
L_delta |
Vector of delta values. |
Scalar value representing the normalized gradient.
Plots the fitted EM mixture density alongside a manually defined reference mixture to visually compare estimation quality.
plot_comparison(data, p1, p2, w)plot_comparison(data, p1, p2, w)
data |
Numeric vector of observations. |
p1 |
Vector of parameters for component 1 (alpha, beta, gamma, delta). |
p2 |
Vector of parameters for component 2. |
w |
Mixing weight for component 1. |
Invisibly returns the file path to the saved PNG image of the comparison plot.
Displays a histogram of the data with overlaid normal and alpha-stable probability density functions.
plot_distributions(x, params_stable)plot_distributions(x, params_stable)
x |
Numeric vector of data. |
params_stable |
List with alpha, beta, gamma, delta. |
NULL (plot is displayed as a side effect)
Computes and visualizes the effective reproduction number (Rt) over time using incidence data and generation time distribution. Optionally overlays a smoothed spline curve.
plot_effective_reproduction_number( GT, S, inc, dates, est_r0_ml, RT, output_file = "RN_avec_dates_EM-ML.pdf" )plot_effective_reproduction_number( GT, S, inc, dates, est_r0_ml, RT, output_file = "RN_avec_dates_EM-ML.pdf" )
GT |
Numeric vector. Generation time distribution. |
S |
Numeric vector. Secondary cases. |
inc |
Numeric vector. Incidence time series. |
dates |
Date vector corresponding to observations. |
est_r0_ml |
Function to estimate R0. |
RT |
Function to compute Rt. |
output_file |
Output PDF filename. |
NULL (plot is saved as PDF)
Plots the final fitted mixture PDF over the data histogram.
plot_final_mixture_fit(data, p1, p2, w)plot_final_mixture_fit(data, p1, p2, w)
data |
Numeric vector of observations. |
p1 |
Vector of parameters for component 1. |
p2 |
Vector of parameters for component 2. |
w |
Mixing weight for component 1. |
NULL (plot is saved as PNG)
Compares the true mixture density with the estimated one by overlaying both on the histogram of the observed data.
plot_fit_vs_true(true_params, est_params, data, bins = 100)plot_fit_vs_true(true_params, est_params, data, bins = 100)
true_params |
List of true mixture components with alpha, beta, gamma, delta, pi. |
est_params |
List of estimated mixture components. |
data |
Numeric vector of observations. |
bins |
Number of histogram bins. |
NULL (plot is displayed)
Plots the true mixture density and compares it with two estimated densities obtained from different methods (e.g., MLE vs ECF).
plot_fit_vs_true_methods( data, true_params, method1 = "MLE", method2 = "ECF", bins = 100 )plot_fit_vs_true_methods( data, true_params, method1 = "MLE", method2 = "ECF", bins = 100 )
data |
Numeric vector of observations. |
true_params |
List of true mixture components. |
method1 |
First estimation method ("MLE", "ECF", etc.). |
method2 |
Second estimation method. |
bins |
Number of histogram bins. |
NULL (plot is displayed)
Generates bar plots comparing RMSE and log-likelihood values across different estimation methods.
plot_method_comparison(scores)plot_method_comparison(scores)
scores |
Named list of score objects with RMSE and LogLikelihood. |
NULL (plot is saved as PNG)
Plots the histogram of data and overlays the estimated mixture density and its components.
plot_mixture(data, params1, params2, w, label = "EM")plot_mixture(data, params1, params2, w, label = "EM")
data |
Numeric vector of observations. |
params1 |
Vector of parameters for component 1 (alpha, beta, gamma, delta). |
params2 |
Vector of parameters for component 2. |
w |
Mixing weight for component 1. |
label |
Optional label for output file. |
NULL (plot is saved as PNG)
Displays the estimated mixture density and optionally its individual components over a histogram of the data.
plot_mixture_fit( data, estimated_params, bins = 200, plot_components = TRUE, save_path = NULL, show_plot = TRUE, title = "Mixture of Alpha-Stable Distributions" )plot_mixture_fit( data, estimated_params, bins = 200, plot_components = TRUE, save_path = NULL, show_plot = TRUE, title = "Mixture of Alpha-Stable Distributions" )
data |
Numeric vector of observations. |
estimated_params |
List with weights, alphas, betas, gammas, deltas. |
bins |
Number of histogram bins. |
plot_components |
Logical, whether to show individual components. |
save_path |
Optional PNG filename. |
show_plot |
Logical, whether to display the plot. |
title |
Plot title. |
Invisibly returns the file path to the saved plot (if save_path is provided), or NULL otherwise.
Plots the fitted mixture model over a histogram of real-world data, showing both components and the overall mixture.
plot_real_mixture_fit(X, result)plot_real_mixture_fit(X, result)
X |
Numeric vector of observations. |
result |
List containing params1, params2, and lambda1. |
NULL (plot is saved as PNG)
Visualizes the estimated two-component alpha-stable mixture density using parameters obtained from MCMC sampling. Optionally overlays the true density for comparison.
plot_results( M2_w1, M2_alpha1, M2_beta1, M2_delta1, M2_omega1, M2_w2, M2_alpha2, M2_beta2, M2_delta2, M2_omega2, xx, xx_true = NULL, yy_true = NULL )plot_results( M2_w1, M2_alpha1, M2_beta1, M2_delta1, M2_omega1, M2_w2, M2_alpha2, M2_beta2, M2_delta2, M2_omega2, xx, xx_true = NULL, yy_true = NULL )
M2_w1 |
Numeric scalar. Mixture weight of first component. |
M2_alpha1 |
Numeric vector. Stability parameter samples of first component. |
M2_beta1 |
Numeric vector. Skewness parameter samples of first component. |
M2_delta1 |
Numeric vector. Location parameter samples of first component. |
M2_omega1 |
Numeric vector. Scale parameter samples of first component. |
M2_w2 |
Numeric scalar. Mixture weight of second component. |
M2_alpha2 |
Numeric vector. Stability parameter samples of second component. |
M2_beta2 |
Numeric vector. Skewness parameter samples of second component. |
M2_delta2 |
Numeric vector. Location parameter samples of second component. |
M2_omega2 |
Numeric vector. Scale parameter samples of second component. |
xx |
Numeric vector of grid values for density evaluation. |
xx_true |
Optional numeric vector for true density x-values. |
yy_true |
Optional numeric vector for true density y-values. |
Invisibly returns the file path to the saved PNG image of the posterior mixture density plot.
Displays the evolution of a parameter across MCMC iterations to assess convergence.
plot_trace(samples, param_name)plot_trace(samples, param_name)
samples |
List of sample objects from MCMC. |
param_name |
Name of the parameter to trace. |
NULL (plot is displayed as a side effect)
Displays a histogram of the data with overlaid normal and alpha-stable PDFs.
plot_vs_normal_stable(x, params_stable, fig_path = NULL)plot_vs_normal_stable(x, params_stable, fig_path = NULL)
x |
Numeric vector of data. |
params_stable |
List with alpha, beta, gamma, delta. |
fig_path |
Optional path to save the plot (PNG). If NULL, uses tempdir(). |
NULL (saves plot to file)
Computes the QCV (Quantile Conditional Variance) statistic to assess tail heaviness of a distribution.
qcv_stat(x)qcv_stat(x)
x |
Numeric vector of data. |
Numeric: QCV value.
Robust stable PDF computation
r_stable_pdf(x, alpha, beta, scale, location)r_stable_pdf(x, alpha, beta, scale, location)
x |
Points at which to evaluate the density. |
alpha |
Stability parameter (0,2]. |
beta |
Skewness parameter [-1,1]. |
scale |
Scale (>0). |
location |
Location parameter. |
Numeric vector of density values.
Real part of the ECF integral
Re(r, u, x, bn)Re(r, u, x, bn)
r |
Integration variable. |
u |
Frequency. |
x |
Data point. |
bn |
Bandwidth. |
Real component value.
Recursive weight function
recursive_weight(l)recursive_weight(l)
l |
Index. |
Weight value.
Estimate stable parameters using robust ECF regression
robust_ecf_regression(x, u)robust_ecf_regression(x, u)
x |
Numeric vector of data. |
u |
Vector of frequency values. |
A list with estimated parameters: alpha, beta, gamma, and delta.
Performs multiple MLE estimations with randomized starting points and selects the best result based on log-likelihood.
robust_mle_estimate(data, n_starts = 5)robust_mle_estimate(data, n_starts = 5)
data |
Numeric vector of observations. |
n_starts |
Number of random initializations. |
List with best estimated alpha, beta, gamma, delta.
Generate random samples from stable distribution
rstable(n, alpha, beta, gamma = 1, delta = 0, pm = 1)rstable(n, alpha, beta, gamma = 1, delta = 0, pm = 1)
n |
Number of samples. |
alpha |
Stability parameter (0,2]. |
beta |
Skewness parameter [-1,1]. |
gamma |
Scale (>0). |
delta |
Location. |
pm |
Parameterization (0 or 1). |
Numeric vector of samples.
Estimates the effective reproduction number (Rt) over time using incidence data and a generation time distribution.
RT(inc, G)RT(inc, G)
inc |
Numeric vector of incidence counts. |
G |
Numeric vector representing the generation time distribution. |
Numeric vector of Rt values.
Executes multiple EM algorithms (recursive ECF, kernel ECF, weighted OLS, CDF-based) on the input data. Optionally saves mixture plots to a temporary directory.
run_all_estimations(X1, bw_sj, max_iter = 200, tol = 1e-04, save_plots = FALSE)run_all_estimations(X1, bw_sj, max_iter = 200, tol = 1e-04, save_plots = FALSE)
X1 |
Numeric vector of data. |
bw_sj |
Numeric. Bandwidth value (e.g., Silverman's rule). |
max_iter |
Integer. Maximum number of EM iterations. |
tol |
Numeric. Convergence tolerance. |
save_plots |
Logical. Whether to save PNG plots to tempdir(). |
Invisibly returns a list containing fitted parameters for each EM method.
Executes EM algorithms with Gibbs sampling on the input data. Optionally saves mixture plots to a temporary directory.
run_estimations_with_gibbs( data, bw_sj, max_iter = 100, tol = 1e-04, save_plots = FALSE )run_estimations_with_gibbs( data, bw_sj, max_iter = 100, tol = 1e-04, save_plots = FALSE )
data |
Numeric vector of observations. |
bw_sj |
Numeric. Bandwidth value (e.g., Silverman's rule). |
max_iter |
Integer. Maximum number of EM iterations. |
tol |
Numeric. Convergence tolerance. |
save_plots |
Logical. Whether to save PNG plots to tempdir(). |
Invisibly returns a list containing fitted parameters for each EM method with Gibbs.
Performs numerical integration with progressively more conservative settings to improve robustness. Useful when standard integration may fail due to oscillatory or heavy-tailed functions.
safe_integrate( integrand_func, lower = 1e-08, upper = 50, max_attempts = 3, ... )safe_integrate( integrand_func, lower = 1e-08, upper = 50, max_attempts = 3, ... )
integrand_func |
Function to integrate. Must accept a numeric vector as input and return numeric values. |
lower |
Numeric scalar. Lower bound of the integration interval (default = 1e-8 to avoid singularities at 0). |
upper |
Numeric scalar. Upper bound of the integration interval (default = 50). |
max_attempts |
Integer. Maximum number of fallback attempts with modified settings if the initial integration fails. |
... |
Additional arguments passed to |
Numeric scalar. The estimated value of the integral, or 0 if all attempts fail.
Initializes EM using k-means clustering and ECF-based parameter estimation.
simple_em_real(X, max_iter = 10)simple_em_real(X, max_iter = 10)
X |
Numeric vector of observations. |
max_iter |
Integer. Maximum number of iterations. |
List with lambda1 and estimated parameters for both components.
Generates synthetic data from a mixture of alpha-stable distributions using specified weights and parameters.
simulate_mixture(n, weights, params)simulate_mixture(n, weights, params)
n |
Number of samples to generate. |
weights |
Vector of mixture weights. |
params |
List of parameter sets for each component (each with alpha, beta, gamma, delta). |
Numeric vector of simulated samples.
Sine exponential function
sine_exp_ralpha(r, x, alpha, beta, delta, omega)sine_exp_ralpha(r, x, alpha, beta, delta, omega)
r |
Integration variable. |
x |
Observation. |
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
Numeric value of the integrand.
Sine-log-weighted exponential with r^(-alpha) term
sine_log_weighted_exp_ralpha(r, x, alpha, beta, delta, omega)sine_log_weighted_exp_ralpha(r, x, alpha, beta, delta, omega)
r |
Integration variable. |
x |
Observation. |
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
Numeric value of the integrand.
Sine-r-weighted exponential function
sine_r_weighted_exp_ralpha(r, x, alpha, beta, delta, omega)sine_r_weighted_exp_ralpha(r, x, alpha, beta, delta, omega)
r |
Integration variable. |
x |
Observation. |
alpha |
Numeric scalar. Stability parameter of the stable distribution
(0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
Numeric value of the integrand.
Sine-weighted exponential with r^alpha term
sine_weighted_exp_ralpha(r, x, alpha, beta, delta, omega)sine_weighted_exp_ralpha(r, x, alpha, beta, delta, omega)
r |
Integration variable. |
x |
Observation. |
alpha |
Numeric scalar. Stability parameter of the stable distribution
((0 < |
beta |
Numeric scalar. Skewness parameter of the stable distribution
( |
delta |
Numeric scalar. Location parameter of the stable distribution. |
omega |
Numeric scalar. Scale parameter of the stable distribution (omega > 0). |
Numeric value of the integrand.
Computes the skewness and kurtosis of a numeric vector.
skew_kurtosis(x)skew_kurtosis(x)
x |
Numeric vector of data. |
List with skewness and kurtosis.
Initialize stable distribution parameters
stable_fit_init(x)stable_fit_init(x)
x |
Numeric vector of data. |
A list with estimated parameters (alpha, beta, gamma, delta).
A data frame of infector-infectee pairs with demographic and serial interval information.
data(TableS2_serial_interval_mean_)data(TableS2_serial_interval_mean_)
A data frame with columns:
Character. Infector ID.
Numeric. Age of infector.
Character. Sex of infector.
Date. Infector symptom onset.
Date. Infector lab confirmation.
Character. Infectee ID.
Numeric. Age of infectee.
Character. Sex of infectee.
Date. Infectee symptom onset.
Date. Infectee lab confirmation.
Numeric. Mean-based serial interval.
Simulated or real data for demonstration.
Applies Shapiro-Wilk, Jarque-Bera, Anderson-Darling, and Kolmogorov-Smirnov tests to assess normality of a dataset.
test_normality(x)test_normality(x)
x |
Numeric vector of data. |
List of test statistics and p-values.
Helper function to unpack parameters
unpack_params(p)unpack_params(p)
p |
A list containing alpha, beta, gamma, delta. |
A numeric vector of parameters.
Ensures parameters are within valid bounds for stable distribution computations.
validate_params(alpha, beta, delta, r = NULL)validate_params(alpha, beta, delta, r = NULL)
alpha |
Stability parameter (must be > 0 and < 2). |
beta |
Skewness parameter (clipped to [-1, 1]). |
delta |
Scale parameter (must be > 0). |
r |
Optional numeric vector. Must be positive if provided. |
Clipped beta value.
Wasserstein distance between two mixture distributions
wasserstein_distance_mixture(params1, params2, size = 5000)wasserstein_distance_mixture(params1, params2, size = 5000)
params1 |
List of parameters for first mixture. |
params2 |
List of parameters for second mixture. |
size |
Number of samples to approximate distance. |
Wasserstein distance.