comparison scripts/statistics/tests/hotelling_test_2.m @ 3456:434790acb067

[project @ 2000-01-19 06:58:51 by jwe]
author jwe
date Wed, 19 Jan 2000 06:59:23 +0000
parents d8b731d3f7a3
children d25bc039237b
comparison
equal deleted inserted replaced
3455:f758be6e1730 3456:434790acb067
35 ## The p-value of the test is returned in @var{pval}. 35 ## The p-value of the test is returned in @var{pval}.
36 ## 36 ##
37 ## If no output argument is given, the p-value of the test is displayed. 37 ## If no output argument is given, the p-value of the test is displayed.
38 ## @end deftypefn 38 ## @end deftypefn
39 39
40 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> 40 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at>
41 ## Description: Compare means of two multivariate normals 41 ## Description: Compare means of two multivariate normals
42 42
43 function [pval, Tsq] = hotelling_test_2 (x, y) 43 function [pval, Tsq] = hotelling_test_2 (x, y)
44 44
45 if (nargin != 2) 45 if (nargin != 2)
46 usage ("hotelling_test_2 (x, y)"); 46 usage ("hotelling_test_2 (x, y)");
47 endif 47 endif
48 48
49 if (is_vector (x)) 49 if (is_vector (x))
50 n_x = length (x); 50 n_x = length (x);
51 if (! is_vector (y)) 51 if (! is_vector (y))
52 error ("hotelling_test_2: If x is a vector, y must be too."); 52 error ("hotelling_test_2: If x is a vector, y must be too.");
53 else 53 else
54 n_y = length (y); 54 n_y = length (y);
55 p = 1; 55 p = 1;
56 endif 56 endif
57 elseif (is_matrix (x)) 57 elseif (is_matrix (x))
58 [n_x, p] = size (x); 58 [n_x, p] = size (x);
59 [n_y, q] = size (y); 59 [n_y, q] = size (y);
60 if (p != q) 60 if (p != q)
61 error (strcat ("hotelling_test_2: ", 61 error ("hotelling_test_2: x and y must have the same number of columns");
62 "x and y must have the same number of columns"));
63 endif 62 endif
64 else 63 else
65 error ("hotelling_test_2: x and y must be matrices (or vectors)"); 64 error ("hotelling_test_2: x and y must be matrices (or vectors)");
66 endif 65 endif
67 66
68 d = mean (x) - mean (y); 67 d = mean (x) - mean (y);
69 S = ((n_x - 1) * cov (x) + (n_y - 1) * cov (y)) / (n_x + n_y - 2); 68 S = ((n_x - 1) * cov (x) + (n_y - 1) * cov (y)) / (n_x + n_y - 2);
70 Tsq = (n_x * n_y / (n_x + n_y)) * d * (S \ d'); 69 Tsq = (n_x * n_y / (n_x + n_y)) * d * (S \ d');
71 pval = 1 - f_cdf ((n_x + n_y - p - 1) * Tsq / (p * (n_x + n_y - 2)), 70 pval = 1 - f_cdf ((n_x + n_y - p - 1) * Tsq / (p * (n_x + n_y - 2)),
72 p, n_x + n_y - p - 1); 71 p, n_x + n_y - p - 1);
73 72
74 if (nargout == 0) 73 if (nargout == 0)
75 printf (" pval: %g\n", pval); 74 printf (" pval: %g\n", pval);
76 endif 75 endif
77 76
78 endfunction 77 endfunction