Add test for turnbull
This commit is contained in:
parent
67ce046522
commit
fb4ca07131
1050
tests/minitab.csv
Normal file
1050
tests/minitab.csv
Normal file
File diff suppressed because it is too large
Load Diff
68
tests/turnbull.rs
Normal file
68
tests/turnbull.rs
Normal file
@ -0,0 +1,68 @@
|
||||
// hpstat: High-performance statistics implementations
|
||||
// Copyright © 2023 Lee Yingtong Li (RunasSudo)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use indicatif::ProgressBar;
|
||||
|
||||
use hpstat::turnbull;
|
||||
|
||||
#[test]
|
||||
fn test_turnbull_minitab() {
|
||||
// Compare "mufflers" example with Minitab output
|
||||
|
||||
let data_times = turnbull::read_data("tests/minitab.csv");
|
||||
|
||||
// Fit regression
|
||||
let progress_bar = ProgressBar::hidden();
|
||||
let result = turnbull::fit_turnbull(data_times, progress_bar, 500, 0.0001);
|
||||
|
||||
assert_eq!(result.failure_intervals[0], (20000.0, 30000.0));
|
||||
assert_eq!(result.failure_intervals[1], (30000.0, 40000.0));
|
||||
assert_eq!(result.failure_intervals[2], (40000.0, 50000.0));
|
||||
assert_eq!(result.failure_intervals[3], (50000.0, 60000.0));
|
||||
assert_eq!(result.failure_intervals[4], (60000.0, 70000.0));
|
||||
assert_eq!(result.failure_intervals[5], (70000.0, 80000.0));
|
||||
assert_eq!(result.failure_intervals[6], (80000.0, 90000.0));
|
||||
assert_eq!(result.failure_intervals[7], (90000.0, f64::INFINITY));
|
||||
|
||||
assert!(abs_diff(result.failure_prob[0], 0.002860) < 0.000001);
|
||||
assert!(abs_diff(result.failure_prob[1], 0.010486) < 0.000001);
|
||||
assert!(abs_diff(result.failure_prob[2], 0.032412) < 0.000001);
|
||||
assert!(abs_diff(result.failure_prob[3], 0.102955) < 0.000001);
|
||||
assert!(abs_diff(result.failure_prob[4], 0.170639) < 0.000001);
|
||||
assert!(abs_diff(result.failure_prob[5], 0.248808) < 0.000001);
|
||||
assert!(abs_diff(result.failure_prob[6], 0.231649) < 0.000001);
|
||||
assert!(abs_diff(result.failure_prob[7], 0.200191) < 0.000001);
|
||||
|
||||
assert!(abs_diff(result.survival_prob[0], 0.997140) < 0.000001);
|
||||
assert!(abs_diff(result.survival_prob[1], 0.986654) < 0.000001);
|
||||
assert!(abs_diff(result.survival_prob[2], 0.954242) < 0.000001);
|
||||
assert!(abs_diff(result.survival_prob[3], 0.851287) < 0.000001);
|
||||
assert!(abs_diff(result.survival_prob[4], 0.680648) < 0.000001);
|
||||
assert!(abs_diff(result.survival_prob[5], 0.431840) < 0.000001);
|
||||
assert!(abs_diff(result.survival_prob[6], 0.200191) < 0.000001);
|
||||
|
||||
assert!(abs_diff(result.survival_prob_se[0], 0.0016488) < 0.0000001);
|
||||
assert!(abs_diff(result.survival_prob_se[1], 0.0035430) < 0.0000001);
|
||||
assert!(abs_diff(result.survival_prob_se[2], 0.0064517) < 0.0000001);
|
||||
assert!(abs_diff(result.survival_prob_se[3], 0.0109856) < 0.0000001);
|
||||
assert!(abs_diff(result.survival_prob_se[4], 0.0143949) < 0.0000001);
|
||||
assert!(abs_diff(result.survival_prob_se[5], 0.0152936) < 0.0000001);
|
||||
assert!(abs_diff(result.survival_prob_se[6], 0.0123546) < 0.0000001);
|
||||
}
|
||||
|
||||
fn abs_diff(a: f64, b: f64) -> f64 {
|
||||
return (a - b).abs();
|
||||
}
|
Loading…
Reference in New Issue
Block a user