R Under development (unstable) (2026-11-02 r90827 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 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. > # This file is part of the standard setup for testthat. > # It is recommended that you do not modify it. > # > # Where should you do additional test configuration? > # Learn more about the roles of various files in: > # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview > # * https://testthat.r-lib.org/articles/special-files.html > > library(testthat) > library(bayesintervals) > > test_check("bayesintervals") === Testing Without Krishnamoorthy Method === Standard Results: By N CI_Lower CI_Upper Median TI_Lower TI_Upper PI_Lower PI_Upper 1 60 10 -3.45755 3.1204 0.452 -22.2154 21.3439 -18.56751 18.52959 ReducibleUpper ReducibleLower 1 0.13471 0.16093 === Testing With Krishnamoorthy Method === Krishnamoorthy Results: By N CI_Lower CI_Upper Median TI_Lower TI_Upper PI_Lower PI_Upper 1 60 10 -3.45755 3.1204 0.452 -22.2154 21.3439 -18.56751 18.52959 ReducibleUpper ReducibleLower K_TI_Lower K_TI_Upper 1 0.13471 0.16093 -22.01662 22.09612 === Comparing Results === === Test Complete === === TOY DATASET === EGTPTNUM Iteration s2 b0 b1 b2 b3 b4 b5 1 60 1001 74.1817 45.8727 -4.5644 -5.2276 6.8522 1.3195 -0.1019 2 60 1301 58.9170 46.3931 -1.8261 -3.9667 10.6505 3.6841 -0.1120 3 60 1601 75.0402 63.4306 -1.9153 -2.9237 10.7839 3.3926 -0.1536 4 60 1901 64.7470 37.1383 -4.8739 -7.6383 6.4292 3.1260 -0.0809 5 60 2201 67.8113 37.4012 -4.1826 -2.5675 8.9568 3.4957 -0.0868 6 60 2501 64.5019 14.7810 -3.6536 -5.1732 8.8313 2.9057 -0.0265 7 60 2801 69.6509 31.5076 -4.6351 -1.4510 4.3675 3.2898 -0.0700 8 60 3101 70.4482 39.1860 -3.1368 -3.6605 7.8938 2.0038 -0.0899 9 60 3401 55.4610 42.1068 -3.3774 -4.1559 9.3794 3.9755 -0.0994 10 60 3701 70.8997 36.5392 -5.8277 -5.7852 8.1801 1.4375 -0.0786 LogPrior LogLike LogPost 1 -42.2500 -863.2 -905.5 2 -42.0222 -862.6 -904.6 3 -42.3597 -864.8 -907.1 4 -42.0782 -862.3 -904.3 5 -42.1250 -860.0 -902.1 6 -42.0160 -863.1 -905.1 7 -42.1286 -869.4 -911.5 8 -42.1690 -860.9 -903.1 9 -41.9415 -860.9 -902.9 10 -42.1678 -862.4 -904.5 === TEST PARAMETERS === Fixed Effects: b2 Covariate Column: b3 Covariate Value: 0.9 Variances: s2 Multiplication Factor: 1.9 By Identifier: EGTPTNUM Tolerance Interval Level: 90 % Credibility of Tolerance: 80 % === EXPECTED RESULTS === By Median CI_Lower CI_Upper PI_Lower PI_Upper TI_Lower TI_Upper 1 60 3.1095 -0.5961 6.2586 -15.4312 21.74 -18.7388 24.3898 === TEST 1: calculate_predicted_distributions() === Fixed effects columns: b2 Random params columns: s2 By column: EGTPTNUM Tolerance level: 90 Multiplication factor: 1.9 Covariate columns: b3 Covariate values: 0.9 === Data Summary === Number of rows: 10 First few rows of input data: EGTPTNUM Iteration s2 b0 b1 b2 b3 b4 b5 1: 60 1001 74.1817 45.8727 -4.5644 -5.2276 6.8522 1.3195 -0.1019 2: 60 1301 58.9170 46.3931 -1.8261 -3.9667 10.6505 3.6841 -0.1120 3: 60 1601 75.0402 63.4306 -1.9153 -2.9237 10.7839 3.3926 -0.1536 4: 60 1901 64.7470 37.1383 -4.8739 -7.6383 6.4292 3.1260 -0.0809 5: 60 2201 67.8113 37.4012 -4.1826 -2.5675 8.9568 3.4957 -0.0868 6: 60 2501 64.5019 14.7810 -3.6536 -5.1732 8.8313 2.9057 -0.0265 LogPrior LogLike LogPost 1: -42.2500 -863.2 -905.5 2: -42.0222 -862.6 -904.6 3: -42.3597 -864.8 -907.1 4: -42.0782 -862.3 -904.3 5: -42.1250 -860.0 -902.1 6: -42.0160 -863.1 -905.1 === Processing Covariates === Added Covariate 1 effect: b3 * 0.9 Sample covariate effect values: 6.16698, 9.58545, 9.70551 Sample cumulative mean after covariate 1 : 6.16698, 9.58545, 9.70551 === Processing Fixed Effects === Fixed effects matrix (first few rows): [,1] [1,] -5.2276 [2,] -3.9667 [3,] -2.9237 [4,] -7.6383 [5,] -2.5675 [6,] -5.1732 Sample fixed effects sum: -5.2276, -3.9667, -2.9237 Sample total mean after fixed effects: 0.93938, 5.61875, 6.78181 === Processing Random Parameters === Random parameters matrix (first few rows): [,1] [1,] 74.1817 [2,] 58.9170 [3,] 75.0402 [4,] 64.7470 [5,] 67.8113 [6,] 64.5019 Sample variance values: 140.94523, 111.9423, 142.57638 === Final Calculations === Number of rows: 10 Final mean vector sample: 0.93938, 5.61875, 6.78181 Final variance vector sample: 140.94523, 111.9423, 142.57638 === Tolerance Parameters === Tolerance alpha: 0.9 Tolerance slice: 0.05 === Quantiles === First few lower quantiles: -18.58838 -11.78426 -12.85862 -20.09576 -13.17684 -15.43421 First few upper quantiles: 20.46714 23.02176 26.42224 16.39172 24.16408 20.98415 First few medians: 0.93938 5.61875 6.78181 -1.85202 5.49362 2.77497 === Final Result === First few rows of result: By mean median lower_quantile upper_quantile variance 1: 60 0.939 0.939 -18.588 20.467 140.945 2: 60 5.619 5.619 -11.784 23.022 111.942 3: 60 6.782 6.782 -12.859 26.422 142.576 4: 60 -1.852 -1.852 -20.096 16.392 123.019 5: 60 5.494 5.494 -13.177 24.164 128.841 6: 60 2.775 2.775 -15.434 20.984 122.554 --- Predicted Distributions Output --- By mean median lower_quantile upper_quantile variance 1 60 0.939 0.939 -18.588 20.467 140.945 2 60 5.619 5.619 -11.784 23.022 111.942 3 60 6.782 6.782 -12.859 26.422 142.576 4 60 -1.852 -1.852 -20.096 16.392 123.019 5 60 5.494 5.494 -13.177 24.164 128.841 6 60 2.775 2.775 -15.434 20.984 122.554 7 60 2.480 2.480 -16.442 21.402 132.337 8 60 3.444 3.444 -15.586 22.474 133.852 9 60 4.286 4.286 -12.599 21.170 105.376 10 60 1.577 1.577 -17.514 20.668 134.709 ✓ TEST 1 PASSED: calculate_predicted_distributions() works correctly with covariates === TEST 2: bayesian_statistical_intervals() === --- Bayesian Statistical Intervals Output --- By N CI_Lower CI_Upper Median TI_Lower TI_Upper PI_Lower PI_Upper 1 60 10 -0.59605 6.25865 3.1095 -18.7388 24.3898 -15.88816 22.11858 ReducibleUpper ReducibleLower 1 0.10673 0.13047 --- Summary --- For parameters y ~ N(0.9 * b3 + b2 , 1.9 * (s2)) and a 90% credible interval, 90% prediction interval, 90% tolerance interval with 80% credibility of tolerance, the following results have been reached. === COMPARISON WITH EXPECTED RESULTS === Metric Expected Actual Difference Within_Tolerance 1 Median 3.1095 3.10950 -4.440892e-16 TRUE 2 CI_Lower -0.5961 -0.59605 5.000000e-05 TRUE 3 CI_Upper 6.2586 6.25865 5.000000e-05 TRUE 4 PI_Lower -15.4312 -15.88816 -4.569635e-01 TRUE 5 PI_Upper 21.7400 22.11858 3.785814e-01 TRUE 6 TI_Lower -18.7388 -18.73880 0.000000e+00 TRUE 7 TI_Upper 24.3898 24.38980 0.000000e+00 TRUE ✓ TEST 2 PASSED: bayesian_statistical_intervals() works correctly with covariates === TEST 3: Backward Compatibility (No Covariates) === --- Results WITHOUT Covariates --- By N CI_Lower CI_Upper Median TI_Lower TI_Upper PI_Lower PI_Upper 1 60 10 -6.80415 -1.9532 -4.0615 -24.9766 16.7924 -23.02433 14.54393 ReducibleUpper ReducibleLower 1 0.10782 0.09334 ✓ TEST 3 PASSED: Backward compatibility maintained === TEST 4: Multiple Covariates === --- Results WITH Multiple Covariates (b3=0.9, b4=1.5) --- By N CI_Lower CI_Upper Median TI_Lower TI_Upper PI_Lower PI_Upper 1 60 10 2.8739 11.5443 7.274 -15.5272 29.6183 -12.00555 26.69853 ReducibleUpper ReducibleLower 1 0.13067 0.15445 --- Summary --- For parameters y ~ N(0.9 * b3 + 1.5 * b4 + b2 , 1.9 * (s2)) and a 90% credible interval, 90% prediction interval, 90% tolerance interval with 80% credibility of tolerance, the following results have been reached. ✓ TEST 4 PASSED: Multiple covariates work correctly === TEST 5: Error Handling === ✓ Test 5a PASSED: Detects mismatched covariate lengths ✓ Test 5b PASSED: Detects non-existent covariate columns ✓ Test 5c PASSED: Detects non-numeric covariate values ====================================================================== === ALL TESTS COMPLETED SUCCESSFULLY === ====================================================================== Summary: ✓ calculate_predicted_distributions() works with covariates ✓ bayesian_statistical_intervals() works with covariates ✓ Results match expected values within tolerance ✓ Backward compatibility maintained (works without covariates) ✓ Multiple covariates supported ✓ Error handling works correctly The updated functions are ready for production use! Test data summary: Group Value Length :200 Min. : 5.382 N.unique : 2 1st Qu.:10.008 N.blank : 0 Median :11.951 Min.nchar: 1 Mean :12.429 Max.nchar: 1 3rd Qu.:14.359 Max. :24.723 First few rows of test data: Group Value 1 A 8.879049 2 A 9.539645 3 A 13.117417 4 A 10.141017 5 A 10.258575 6 A 13.430130 Calculating credibility intervals with 95% level... Full result from calculate_ci: By N CI_Lower CI_Upper Median 1 A 100 6.757657 13.85016 10.12351 2 B 100 10.169646 21.15370 14.32251 Checking result structure... Class: data.frame Dimensions: 2 5 Column names: By N CI_Lower CI_Upper Median Checking N values... [1] 100 100 Checking interval relationships... CI_Lower < Median: TRUE Median < CI_Upper: TRUE Checking approximate values... Group A results: By N CI_Lower CI_Upper Median 1 A 100 6.757657 13.85016 10.12351 Expected median ~10, got: 10.12351 Expected CI_Lower ~ 9.608 , got: 6.757657 Expected CI_Upper ~ 10.392 , got: 13.85016 Group B results: By N CI_Lower CI_Upper Median 2 B 100 10.16965 21.1537 14.32251 Expected median ~15, got: 14.32251 Expected CI_Lower ~ 14.412 , got: 10.16965 Expected CI_Upper ~ 15.588 , got: 21.1537 TESTING EDGE CASES Testing with single group... Group Value 1 A 1 2 A 2 3 A 3 4 A 4 5 A 5 6 A 6 Result with single group: By N CI_Lower CI_Upper Median 1 A 10 1.45 9.55 5.5 Testing with data.table input... Group Value 1: A 1 2: A 2 3: A 3 4: A 4 5: A 5 6: B 6 Class of input: data.table data.frame Result with data.table input: By N CI_Lower CI_Upper Median 1 A 5 1.4 4.6 3 2 B 5 6.4 9.6 8 Comparing different credibility levels... 95% credibility intervals: By N CI_Lower CI_Upper Median 1 A 5 1.1 4.9 3 2 B 5 6.1 9.9 8 80% credibility intervals: By N CI_Lower CI_Upper Median 1 A 5 1.4 4.6 3 2 B 5 6.4 9.6 8 Width of 95% intervals: 3.8 3.8 Width of 80% intervals: 3.2 3.2 TESTING ERROR HANDLING Test data for error handling: Group Value 1 A 1 2 A 2 3 A 3 4 A 4 5 A 5 6 B 6 7 B 7 8 B 8 9 B 9 10 B 10 Testing with non-existent column... Expected error caught: Column NonExistentColumn or Group not found in the dataframe Testing with non-existent grouping column... Expected error caught: Column Value or NonExistentGroup not found in the dataframe TESTING BASIC FUNCTIONALITY Test data summary: Group lower_quantile upper_quantile Length :200 Min. : 2.691 Min. :13.24 N.unique : 2 1st Qu.: 5.066 1st Qu.:15.04 N.blank : 0 Median : 6.792 Median :16.65 Min.nchar: 1 Mean : 7.438 Mean :17.52 Max.nchar: 1 3rd Qu.: 9.538 3rd Qu.:19.98 Max. :16.482 Max. :25.14 First few rows of test data: Group lower_quantile upper_quantile 1 A 4.439524 17.19881 2 A 4.769823 16.31241 3 A 6.558708 14.73485 4 A 5.070508 15.54319 5 A 5.129288 14.58566 6 A 6.715065 14.52375 Calculating tolerance intervals with 95% confidence level... Full result from calculate_tolerance_interval: By TI_Lower TI_Upper 1 A 3.378828 16.98007 2 B 6.779764 23.73967 Checking result structure... Class: data.frame Dimensions: 2 3 Column names: By TI_Lower TI_Upper Checking interval values... Group A results: By TI_Lower TI_Upper 1 A 3.378828 16.98007 Expected TI_Lower ~ 3.378828 , got: 3.378828 Expected TI_Upper ~ 16.98007 , got: 16.98007 Group B results: By TI_Lower TI_Upper 2 B 6.779764 23.73967 Expected TI_Lower ~ 6.779764 , got: 6.779764 Expected TI_Upper ~ 23.73967 , got: 23.73967 TESTING DIFFERENT CONFIDENCE LEVELS 95% confidence tolerance intervals: By TI_Lower TI_Upper 1 A 3.378828 17.05123 80% confidence tolerance intervals: By TI_Lower TI_Upper 1 A 3.93178 16.05843 Interval widths: 95% confidence width: 13.67241 80% confidence width: 12.12665 Expected values: 95% confidence: [ 3.378828 , 17.05123 ] 80% confidence: [ 3.93178 , 16.05843 ] TESTING DATA.TABLE INPUT Test data (data.table): Group lower_quantile upper_quantile 1: A 4.439524 14.28959 2: A 4.769823 15.25688 3: A 6.558708 14.75331 4: A 5.070508 14.65246 5: A 5.129288 14.04838 6: A 6.715065 14.95497 Class: data.table data.frame Result with data.table input: By TI_Lower TI_Upper 1 A 3.734754 16.66417 2 B 7.692598 23.33380 Group A expected vs. actual: Expected TI_Lower: 3.734754 , got: 3.734754 Expected TI_Upper: 16.66417 , got: 16.66417 TESTING ERROR HANDLING Test data for error handling: Group lower_quantile upper_quantile 1 A 1 11 2 A 2 12 3 A 3 13 4 A 4 14 5 A 5 15 6 B 6 16 7 B 7 17 8 B 8 18 9 B 9 19 10 B 10 20 Testing with non-existent column... Expected error caught: One or more required columns not found in the dataframe Testing with non-existent grouping column... Expected error caught: One or more required columns not found in the dataframe TESTING SINGLE GROUP CASE Test data (single group): Group lower_quantile upper_quantile 1 A 4.439524 14.28959 2 A 4.769823 15.25688 3 A 6.558708 14.75331 4 A 5.070508 14.65246 5 A 5.129288 14.04838 6 A 6.715065 14.95497 Result with single group: By TI_Lower TI_Upper 1 A 3.378828 17.05123 Expected vs. actual: Expected TI_Lower: 3.378828 , got: 3.378828 Expected TI_Upper: 17.05123 , got: 17.05123 Predicted Distributions: By mean median lower_quantile upper_quantile variance 1 60 -3.24835 -3.24835 -22.25528 15.75858 133.5271 2 60 1.55945 1.55945 -15.37940 18.49830 106.0506 3 60 2.16520 2.16520 -16.95139 21.28179 135.0724 === Testing calculate_gP_mean === gP_mean_vector: 0.03957 === Testing calculate_gamma_difference === Gamma differences: -20 80 80 Points satisfying: 10 0 0 Total points: 10 === Testing find_optimal_point === Optimal Results: $`60` $`60`$By [1] 60 $`60`$g1 [1] -22.0169 $`60`$g2 60 22.09604 $`60`$gamma_difference 60 0 $`60`$gamma_achieved 60 80 $`60`$points_satisfying 60 8 $`60`$total_points [1] 10 $`60`$iterations [1] 4 === Testing add_krishnamoorthy_ti === Updated Data with Krishnamoorthy TI: By TI_Lower TI_Upper K_TI_Lower K_TI_Upper 1 60 -15 15 -22.0169 22.09604 === All Krishnamoorthy Tests Passed! === [ FAIL 0 | WARN 0 | SKIP 0 | PASS 430 ] > > proc.time() user system elapsed 6.84 0.56 7.40