--- /usr/share/octave/3.6.1/m/statistics/tests/t_test_2.m 2012-04-27 01:06:51.000000000 +0800 +++ t_test_2.m 2012-06-12 17:26:01.000000000 +0800 @@ -57,8 +57,14 @@ mu_x = sum (x) / n_x; mu_y = sum (y) / n_y; v = sumsq (x - mu_x) + sumsq (y - mu_y); - t = (mu_x - mu_y) * sqrt ((n_x * n_y * df) / (v * (n_x + n_y))); - cdf = tcdf (t, df); + if (v != 0) + t = (mu_x - mu_y) * sqrt ((n_x * n_y * df) / (v * (n_x + n_y))); + cdf = tcdf (t, df); + elseif (mu_x == mu_y) + t = NaN; + else + t = Inf; + endif if (nargin == 2) alt = "!="; @@ -68,11 +74,23 @@ error ("t_test_2: ALT must be a string"); endif if (strcmp (alt, "!=") || strcmp (alt, "<>")) - pval = 2 * min (cdf, 1 - cdf); + if (v != 0) + pval = 2 * min (cdf, 1 - cdf); + else + pval = (mu_x == mu_y); + endif elseif strcmp (alt, ">") - pval = 1 - cdf; + if (v != 0) + pval = 1 - cdf; + else + pval = (mu_x <= mu_y); + endif elseif strcmp (alt, "<") - pval = cdf; + if (v != 0) + pval = cdf; + else + pval = (mu_x >= mu_y); + endif else error ("t_test_2: option %s not recognized", alt); endif