def get_correlation_items(stats_object) -> dict:
    """Create the list of correlation items

    Args:
        stats_object: dict of correlations

    Returns:
        List of correlation items to show in the interface.
    """
    items = {}
    if "pearson" in stats_object["correlations"]:
        items["pearson"] = {
            "matrix": plot.correlation_matrix(stats_object["correlations"]["pearson"]),
            "name": "Pearson's r",
        }

    if "spearman" in stats_object["correlations"]:
        items["spearman"] = {
            "matrix": plot.correlation_matrix(stats_object["correlations"]["spearman"]),
            "name": "Spearman's ρ",
        }

    if "kendall" in stats_object["correlations"]:
        items["kendall"] = {
            "matrix": plot.correlation_matrix(stats_object["correlations"]["kendall"]),
            "name": "Kendall's τ",
        }

    if "phi_k" in stats_object["correlations"]:
        items["phi_k"] = {
            "matrix": plot.correlation_matrix(
                stats_object["correlations"]["phi_k"], vmin=0
            ),
            "name": "Phik (&phi;<sub><em>k</em></sub>)",
        }

    if "cramers" in stats_object["correlations"]:
        items["cramers"] = {
            "matrix": plot.correlation_matrix(
                stats_object["correlations"]["cramers"], vmin=0
            ),
            "name": "Cramér's V (&phi;<sub><em>c</em></sub>)",
        }

    if "recoded" in stats_object["correlations"]:
        items["recoded"] = {
            "matrix": plot.correlation_matrix(
                stats_object["correlations"]["recoded"], vmin=0
            ),
            "name": "Recoded",
        }

    return items
Exemple #2
0
def render_correlations_html(stats_object: dict) -> str:
    """Render the correlations HTML.

    Args:
        stats_object: The diagrams to display in the correlation component.

    Returns:
        The rendered HTML of the correlations component of the profile.
    """
    values = {}
    active = ""
    if "pearson" in stats_object["correlations"]:
        if active == "":
            active = "pearson"
        values["pearson"] = {
            "matrix":
            plot.correlation_matrix(stats_object["correlations"]["pearson"]),
            "name":
            "Pearson",
        }

    if "spearman" in stats_object["correlations"]:
        if active == "":
            active = "spearman"
        values["spearman"] = {
            "matrix":
            plot.correlation_matrix(stats_object["correlations"]["spearman"]),
            "name":
            "Spearman",
        }

    if "kendall" in stats_object["correlations"]:
        if active == "":
            active = "kendall"
        values["kendall"] = {
            "matrix":
            plot.correlation_matrix(stats_object["correlations"]["kendall"]),
            "name":
            "Kendall",
        }

    if "phi_k" in stats_object["correlations"]:
        if active == "":
            active = "phi_k"
        values["phi_k"] = {
            "matrix":
            plot.correlation_matrix(stats_object["correlations"]["phi_k"],
                                    vmin=0),
            "name":
            "Phi<sub>k</sub>",
        }

    if "cramers" in stats_object["correlations"]:
        if active == "":
            active = "cramers"
        values["cramers"] = {
            "matrix":
            plot.correlation_matrix(stats_object["correlations"]["cramers"],
                                    vmin=0),
            "name":
            "Cramér's V",
        }

    if "recoded" in stats_object["correlations"]:
        if active == "":
            active = "recoded"
        values["recoded"] = {
            "matrix":
            plot.correlation_matrix(stats_object["correlations"]["recoded"],
                                    vmin=0),
            "name":
            "Recoded",
        }

    return templates.template("correlations.html").render(values=values,
                                                          active=active)