R Under development (unstable) (2025-10-02 r88897 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # Clean environment and load libraries > rm(list = ls()) # Clear environment to avoid conflicts > > > # Source files > library(MixStable) Attaching package: 'MixStable' The following object is masked from 'package:graphics': clip > > # ===== TEST FUNCTIONS ===== > > # Test all ECF functions > test_all_ecf_functions <- function() { + cat("=== Testing All ECF Functions ===\n") + + # Generate test data + set.seed(123) + n <- 500 + test_data <- rt(n, df = 3) * 2 + 1 # Student-t as proxy + u_grid <- seq(0.1, 1.0, length.out = 20) + + functions_to_test <- list( + "CDF" = CDF, + "ecf_regression" = ecf_regression, + "robust_ecf_regression" = robust_ecf_regression, + "estimate_stable_recursive_ecf" = estimate_stable_recursive_ecf, + "estimate_stable_kernel_ecf" = estimate_stable_kernel_ecf, + "estimate_stable_weighted_ols" = estimate_stable_weighted_ols, + "estimate_stable_from_cdf" = estimate_stable_from_cdf, + "ecf_estimate_all" = function(x, u) ecf_estimate_all(x, u) + ) + + results <- list() + + for (func_name in names(functions_to_test)) { + cat("\nTesting", func_name, "...\n") + tryCatch({ + if (func_name == "fit_stable_ecf") { + result <- fit_stable_ecf(test_data, u_grid) + } else { + result <- functions_to_test[[func_name]](test_data, u_grid) + } + + cat(" Alpha:", result$alpha, "\n") + cat(" Beta:", result$beta, "\n") + cat(" Gamma:", result$gamma, "\n") + cat(" Delta:", result$delta, "\n") + + # Check if parameters are finite + if (all(sapply(result, is.finite))) { + cat(" ✓ All parameters finite\n") + } else { + cat(" ✗ Some parameters not finite\n") + } + + results[[func_name]] <- result + + }, error = function(e) { + cat(" ✗ Error:", e$message, "\n") + results[[func_name]] <- NA + }) + } + + return(results) + } > > # Test Bayesian mixture model > test_bayesian_mixture <- function() { + cat("\n=== Testing Bayesian Mixture Model ===\n") + + if (!requireNamespace("mixtools", quietly = TRUE)) { + cat("Skipping Bayesian test - mixtools package not available\n") + return(NULL) + } + + # Generate mixture data + set.seed(456) + n <- 300 + component <- rbinom(n, 1, 0.4) + test_data <- ifelse(component == 1, + rnorm(n, mean = -1, sd = 1), + rnorm(n, mean = 2, sd = 1.5)) + + tryCatch({ + mixture_result <- bayesian_mixture_model(test_data, draws = 100, chains = 2) + + cat("✓ Mixture model fitted successfully\n") + cat("Component weights:", mixture_result$weights, "\n") + cat("Component means:", mixture_result$means, "\n") + cat("Component sigmas:", mixture_result$sigmas, "\n") + + return(mixture_result) + }, error = function(e) { + cat("✗ Error in mixture model:", e$message, "\n") + return(NULL) + }) + } > > # Run all tests > run_all_tests <- function() { + cat("=== RUNNING ALL STABLE DISTRIBUTION TESTS ===\n\n") + + # Test ECF functions + ecf_results <- test_all_ecf_functions() + + # Test Bayesian mixture + mixture_result <- test_bayesian_mixture() + + # Summary + cat("\n=== TEST SUMMARY ===\n") + successful_tests <- sum(!is.na(ecf_results)) + total_tests <- length(ecf_results) + + cat("ECF Functions tested:", total_tests, "\n") + cat("Successful tests:", successful_tests, "\n") + cat("Success rate:", round(100 * successful_tests / total_tests, 1), "%\n") + + if (!is.null(mixture_result)) { + cat("✓ Bayesian mixture model test passed\n") + } else { + cat("✗ Bayesian mixture model test failed\n") + } + + cat("\nAll tests completed!\n") + + return(list( + ecf_results = ecf_results, + mixture_result = mixture_result + )) + } > > # To run tests: > results <- run_all_tests() === RUNNING ALL STABLE DISTRIBUTION TESTS === === Testing All ECF Functions === Testing CDF ... Alpha: 1.671299 Beta: -0.0042149 Gamma: 1.760674 Delta: 1.051394 ✓ All parameters finite Testing ecf_regression ... Alpha: 1.576576 Beta: 0.01237342 Gamma: 1.774798 Delta: 1.050888 ✓ All parameters finite Testing robust_ecf_regression ... Alpha: 1.639749 Beta: 0.01642045 Gamma: 1.796017 Delta: 1.050124 ✓ All parameters finite Testing estimate_stable_recursive_ecf ... Alpha: 1.481965 Beta: 0.02350956 Gamma: 1.758839 Delta: 1.044365 ✓ All parameters finite Testing estimate_stable_kernel_ecf ... Alpha: 1.604467 Beta: 0.01323445 Gamma: 1.780534 Delta: 1.050713 ✓ All parameters finite Testing estimate_stable_weighted_ols ... Alpha: 1.481965 Beta: 0.02390486 Gamma: 1.758839 Delta: 1.044241 ✓ All parameters finite Testing estimate_stable_from_cdf ... Alpha: 1.671299 Beta: -1 Gamma: 1.760674 Delta: 1.049927 ✓ All parameters finite Testing ecf_estimate_all ... Alpha: 1.516636 Beta: 0.004551384 Gamma: 1.632377 Delta: 1.059244 ✓ All parameters finite === Testing Bayesian Mixture Model === WARNING! NOT CONVERGENT! number of iterations= 100 WARNING! NOT CONVERGENT! number of iterations= 100 WARNING! NOT CONVERGENT! number of iterations= 100 ✓ Mixture model fitted successfully Component weights: 0.4182886 0.5817114 Component means: -0.8386837 2.02986 Component sigmas: 1.112646 1.525675 === TEST SUMMARY === ECF Functions tested: 8 Successful tests: 8 Success rate: 100 % ✓ Bayesian mixture model test passed All tests completed! > > proc.time() user system elapsed 7.98 0.78 8.75