Skip to content

Commit e060d65

Browse files
committed
friedman: update docstring and rework some logic and variable names in function
1 parent fd8c968 commit e060d65

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

inst/friedman.m

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
## @deftypefn {statistics} {@var{p} =} friedman (@var{x})
1919
## @deftypefnx {statistics} {@var{p} =} friedman (@var{x}, @var{reps})
2020
## @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{})
2323
##
2424
## Performs the nonparametric Friedman's test to compare column effects in a
2525
## two-way layout. @qcode{friedman} tests the null hypothesis that the column
@@ -46,16 +46,16 @@
4646
## @item
4747
## @var{p} is the p-value of the null hypothesis that all group means are equal.
4848
## @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.
5252
## @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.
5555
## @end itemize
5656
##
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.
5959
##
6060
## Examples:
6161
##
@@ -73,18 +73,20 @@
7373
## @seealso{anova2, kruskalwallis, multcompare}
7474
## @end deftypefn
7575

76-
function [p, table_out, stats] = friedman (x, reps, displayopt)
76+
function [p, tbl, stats] = friedman (x, reps, displayopt)
7777

7878
## Check for valid number of input arguments
7979
narginchk (1, 3);
8080
## Check for NaN values in X
8181
if (any (isnan (x(:))))
8282
error ("friedman: NaN values in input are not allowed.");
8383
endif
84+
8485
## Add defaults
8586
if (nargin == 1)
8687
reps = 1;
8788
endif
89+
8890
## Check for correct size of input matrix
8991
[r, c] = size (x);
9092
if (r <= 1 || c <= 1)
@@ -96,13 +98,16 @@
9698
error ("friedman: repetitions and observations do not match.");
9799
endif
98100
endif
101+
99102
## 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
104110
endif
105-
plotdata = ! (strcmp (displayopt, 'off'));
106111

107112
## Prepare a matrix of ranks. Replicates are ranked together.
108113
m = x;
@@ -152,9 +157,9 @@
152157
endif
153158

154159
## 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"});
158163

159164
## Create stats structure (if requested) for MULTCOMPARE
160165
if (nargout > 2)
@@ -164,10 +169,11 @@
164169
stats.sigma = sqrt (sigmasq);
165170
endif
166171

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);
170175
endif
176+
171177
endfunction
172178

173179

0 commit comments

Comments
 (0)