|
18 | 18 | ## @deftypefn {statistics} {@var{p} =} friedman (@var{x}) |
19 | 19 | ## @deftypefnx {statistics} {@var{p} =} friedman (@var{x}, @var{reps}) |
20 | 20 | ## @deftypefnx {statistics} {@var{p} =} friedman (@var{x}, @var{reps}, @var{displayopt}) |
21 | | -## @deftypefnx {statistics} {[@var{p}, @var{atab}] =} friedman (@dots{}) |
22 | | -## @deftypefnx {statistics} {[@var{p}, @var{atab}, @var{stats}] =} friedman (@dots{}) |
| 21 | +## @deftypefnx {statistics} {[@var{p}, @var{tbl}] =} friedman (@dots{}) |
| 22 | +## @deftypefnx {statistics} {[@var{p}, @var{tbl}, @var{stats}] =} friedman (@dots{}) |
23 | 23 | ## |
24 | 24 | ## Performs the nonparametric Friedman's test to compare column effects in a |
25 | 25 | ## two-way layout. @qcode{friedman} tests the null hypothesis that the column |
|
46 | 46 | ## @item |
47 | 47 | ## @var{p} is the p-value of the null hypothesis that all group means are equal. |
48 | 48 | ## @item |
49 | | -## @var{atab} is a table array containing the results of the Friedman's test in |
50 | | -## ANOVA table format. The table includes columns for Source, SS, df, MS, |
51 | | -## Chi-sq, and Prob>Chi-sq with rows for Columns, [Interaction], Error, and Total. |
| 49 | +## @var{tbl} is a table containing the results of the Friedman's test in ANOVA |
| 50 | +## table format. The table includes columns for Source, SS, df, MS, Chi-sq, and |
| 51 | +## Prob>Chi-sq with rows for Columns, [Interaction], Error, and Total. |
52 | 52 | ## @item |
53 | | -## @var{stats} is a structure containing statistics useful for performing |
54 | | -## a multiple comparison of medians with the MULTCOMPARE function. |
| 53 | +## @var{stats} is a structure containing statistics useful for performing a |
| 54 | +## multiple comparison of medians with the MULTCOMPARE function. |
55 | 55 | ## @end itemize |
56 | 56 | ## |
57 | | -## If friedman is called without any output arguments, then it prints the results |
58 | | -## in a Friedman's ANOVA table to the standard output. |
| 57 | +## If friedman is called without any output arguments, then it prints the |
| 58 | +## results in a Friedman's ANOVA table to the standard output. |
59 | 59 | ## |
60 | 60 | ## Examples: |
61 | 61 | ## |
|
73 | 73 | ## @seealso{anova2, kruskalwallis, multcompare} |
74 | 74 | ## @end deftypefn |
75 | 75 |
|
76 | | -function [p, table_out, stats] = friedman (x, reps, displayopt) |
| 76 | +function [p, tbl, stats] = friedman (x, reps, displayopt) |
77 | 77 |
|
78 | 78 | ## Check for valid number of input arguments |
79 | 79 | narginchk (1, 3); |
80 | 80 | ## Check for NaN values in X |
81 | 81 | if (any (isnan (x(:)))) |
82 | 82 | error ("friedman: NaN values in input are not allowed."); |
83 | 83 | endif |
| 84 | + |
84 | 85 | ## Add defaults |
85 | 86 | if (nargin == 1) |
86 | 87 | reps = 1; |
87 | 88 | endif |
| 89 | + |
88 | 90 | ## Check for correct size of input matrix |
89 | 91 | [r, c] = size (x); |
90 | 92 | if (r <= 1 || c <= 1) |
|
96 | 98 | error ("friedman: repetitions and observations do not match."); |
97 | 99 | endif |
98 | 100 | endif |
| 101 | + |
99 | 102 | ## Check for displayopt |
100 | | - if (nargin < 3) |
101 | | - displayopt = 'off'; |
102 | | - elseif ! (strcmp (displayopt, 'off') || strcmp (displayopt, 'on')) |
103 | | - error ("friedman: displayopt must be either 'on' or 'off'."); |
| 103 | + disp_table = false; |
| 104 | + if (nargin == 3) |
| 105 | + if (! any (strcmp (displayopt, {'on', 'off'}))) |
| 106 | + error ("friedman: displayopt must be either 'on' or 'off'."); |
| 107 | + elseif (strcmp (displayopt, 'on')) |
| 108 | + disp_table = true; |
| 109 | + endif |
104 | 110 | endif |
105 | | - plotdata = ! (strcmp (displayopt, 'off')); |
106 | 111 |
|
107 | 112 | ## Prepare a matrix of ranks. Replicates are ranked together. |
108 | 113 | m = x; |
|
152 | 157 | endif |
153 | 158 |
|
154 | 159 | ## Create output table using datatypes package |
155 | | - table_out = table (source_list, ss_list, df_list, ms_list, chi_sq_list, ... |
156 | | - prob_list, "VariableNames", {"Source", "SS", "df", "MS", ... |
157 | | - "Chi_sq", "Prob_Chi_sq"}); |
| 160 | + tbl = table (source_list, ss_list, df_list, ms_list, chi_sq_list, ... |
| 161 | + prob_list, "VariableNames", {"Source", "SS", "df", "MS", ... |
| 162 | + "Chi_sq", "Prob_Chi_sq"}); |
158 | 163 |
|
159 | 164 | ## Create stats structure (if requested) for MULTCOMPARE |
160 | 165 | if (nargout > 2) |
|
164 | 169 | stats.sigma = sqrt (sigmasq); |
165 | 170 | endif |
166 | 171 |
|
167 | | - ## Print results table on screen if no output argument was requested |
168 | | - if (nargout == 0 || plotdata) |
169 | | - disp (table_out); |
| 172 | + ## Display ANOVA table if opted or no output argument is requested |
| 173 | + if (nargout == 0 || disp_table) |
| 174 | + disp (tbl); |
170 | 175 | endif |
| 176 | + |
171 | 177 | endfunction |
172 | 178 |
|
173 | 179 |
|
|
0 commit comments