Mercurial > octave
changeset 23890:89a1ed157a2a
* z_test_2.m: New tests resembling those in z_test.m (bug #45378).
author | Allan Jacobs <allanjacobs@savannah.gnu.org> |
---|---|
date | Mon, 22 Jun 2015 11:37:59 -0700 |
parents | 97a237af2812 |
children | 142a9c7e403a |
files | scripts/statistics/tests/z_test_2.m |
diffstat | 1 files changed, 54 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/statistics/tests/z_test_2.m Fri Aug 11 13:25:45 2017 -0400 +++ b/scripts/statistics/tests/z_test_2.m Mon Jun 22 11:37:59 2015 -0700 @@ -88,3 +88,57 @@ endif endfunction + +#!test +%! ## Two-sided (also the default option) +%! x = randn (100, 1); v_x = 2; x = v_x * x; +%! [pval, z] = z_test_2 (x, x, v_x, v_x); +%! zval_exp = 0; pval_exp = 1.0; +%! assert (zval, zval_exp, eps); +%! assert (pval, pval_exp, eps); + +#!test +%! ## Two-sided (also the default option) +%! x = randn (10000, 1); v_x = 2; x = v_x * x; n_x = length (x); +%! y = randn (20000, 1); v_y = 3; y = v_y * y; n_y = length (y); +%! [pval, z] = z_test_2 (x, y, v_x, v_y); +%! if (mean (x) >= mean (y)) +%! zval = abs (norminv (0.5*pval)); +%! else +%! zval = -abs (norminv (0.5*pval)); +%! endif +%! unew = zval * sqrt (v_x/n_x + v_y/n_y); +%! delmu = mean (x) - mean (y); +%! assert (delmu, unew, 100*eps); + +#!test +%! x = randn (100, 1); v_x = 2; x = v_x * x; +%! [pval, z] = z_test_2 (x, x, v_x, v_x, ">"); +%! zval_exp = 0; pval_exp = 0.5; +%! assert (zval, zval_exp, eps); +%! assert (pval, pval_exp, eps); + +%!test +%! x = randn (10000, 1); v_x = 2; x = v_x * x; n_x = length (x); +%! y = randn (20000, 1); v_y = 3; y = v_y * y; n_y = length (y); +%! [pval, z] = z_test_2 (x, y, v_x, v_y, ">"); +%! zval = norminv (1-pval); +%! unew = zval * sqrt (v_x/n_x + v_y/n_y); +%! delmu = mean (x) - mean (y); +%! assert (delmu, unew, 100*eps); + +%!test +%! x = randn (100, 1); v_x = 2; x = v_x * x; +%! [pval, zval] = z_test_2 (x, x, v_x, v_x, "<"); +%! zval_exp = 0; pval_exp = 0.5; +%! assert (zval, zval_exp, eps); +%! assert (pval, pval_exp, eps); + +%!test +%! x = randn (10000, 1); v_x = 2; x = v_x * x; n_x = length (x); +%! y = randn (20000, 1); v_y = 3; y = v_y * y; n_y = length (y); +%! [pval, z] = z_test_2 (x, y, v_x, v_y, "<"); +%! zval = norminv (pval); +%! unew = zval * sqrt (v_x/n_x + v_y/n_y); +%! delmu = mean (x) - mean (y); +%! assert (delmu, unew, 100*eps);