Shared Rust kernels
ported/confidence_test_family
All modules · quoted at commit 9e1884369a67 of DnaCalc/DnaCalc. Comments are the source's own.
z_test_kernel · 24 lines · calc-func/src/ported/confidence_test_family.rs on GitHubpub fn z_test_kernel(
values: &[f64],
x: f64,
sigma: Option<f64>,
) -> Result<f64, WorksheetErrorCode> {
if values.is_empty() || !x.is_finite() {
return Err(WorksheetErrorCode::Value);
}
let mean = values.iter().sum::<f64>() / values.len() as f64;
let sigma = match sigma {
Some(value) => value,
None => stdev_from_values(values, VarianceDivisor::Sample)?,
};
if sigma <= 0.0 || !sigma.is_finite() {
return Err(WorksheetErrorCode::Num);
}
// Live Excel 16.0 b20326: Z.TEST(array,x) with omitted sigma is
// NORMSDIST((x-AVERAGE)/(STDEV.S/SQRT(n))), not 1-NORMSDIST((mean-x)/se)
// and not STDEV.P. The two NORMSDIST complements are not bit-identical.
// F1 (dc-8dq): (x - mean) * sqrt(n) / sigma, as Excel's Z.TEST gives Z.TEST({1,5,3},2) (the
// catalogue oracle's capture); dividing by sigma/sqrt(n) is one ulp away there.
let z = (x - mean) * (values.len() as f64).sqrt() / sigma;
crate::ported::normal_log_family::norm_s_dist_kernel(z, true)
}
Used by 2 functions.