scikit_posthocs.critical_difference_diagram

scikit_posthocs.critical_difference_diagram(ranks: dict | Series, sig_matrix: DataFrame, *, ax: SubplotBase = None, label_fmt_left: str = '{label} ({rank:.2g})', label_fmt_right: str = '({rank:.2g}) {label}', label_props: dict = None, marker_props: dict = None, elbow_props: dict = None, crossbar_props: dict = None, color_palette: Dict[str, str] | List = {}, text_h_margin: float = 0.01) Dict[str, list]

Plot a Critical Difference diagram from ranks and post-hoc results.

The diagram arranges the average ranks of multiple groups on the x axis in order to facilitate performance comparisons between them. The groups that could not be statistically deemed as different are linked by a horizontal crossbar [1], [2].

             rank markers
X axis ---------O----O-------------------O-O------------O---------
                |----|                   | |            |
                |    |                   |---crossbar---|
       clf1 ----|    |                   | |            |---- clf3
       clf2 ---------|                   | |----------------- clf4
                                         |------------------- clf5
           |____|
       text_h_margin

In the drawing above, the two crossbars indicate that clf1 and clf2 cannot be statistically differentiated, the same occurring between clf3, clf4 and clf5. However, clf1 and clf2 are each significantly lower ranked than clf3, clf4 and clf5.

Parameters:
  • ranks (dict or Series) – Indicates the rank value for each sample or estimator (as keys or index).

  • sig_matrix (DataFrame) – The corresponding p-value matrix outputted by post-hoc tests, with indices matching the labels in the ranks argument.

  • ax (matplotlib.SubplotBase, optional) – The object in which the plot will be built. Gets the current Axes by default (if None is passed).

  • label_fmt_left (str, optional) – The format string to apply to the labels on the left side. The keywords label and rank can be used to specify the sample/estimator name and rank value, respectively, by default ‘{label} ({rank:.2g})’.

  • label_fmt_right (str, optional) – The same, but for the labels on the right side of the plot. By default ‘({rank:.2g}) {label}’.

  • label_props (dict, optional) – Parameters to be passed to pyplot.text() when creating the labels, by default None.

  • marker_props (dict, optional) – Parameters to be passed to pyplot.scatter() when plotting the rank markers on the axis, by default None.

  • elbow_props (dict, optional) – Parameters to be passed to pyplot.plot() when creating the elbow lines, by default None.

  • crossbar_props (dict, optional) – Parameters to be passed to pyplot.plot() when creating the crossbars that indicate lack of statistically significant difference. By default None.

  • text_h_margin (float, optional) – Space between the text labels and the nearest vertical line of an elbow, by default 0.01.

  • color_palette (dict, optional) – Parameters to be passed when you need specific colors for each category

Returns:

Lists of Artists created.

Return type:

dict[str, list[matplotlib.Artist]]

Examples

See the Tutorial.

References