Skip to content

SSM Results

circumplex.ssm

Structural Summary Method (SSM) analysis results and configuration classes.

This module provides dataclasses for representing SSM analysis results:

  • SSMDetails: Configuration and parameters used in SSM analysis
  • SSM: Complete SSM analysis results with estimates and confidence intervals
CLASS DESCRIPTION
SSMDetails

Details of SSM analysis configuration and parameters.

SSM

Results from a Structural Summary Method (SSM) analysis.

SSMDetails dataclass

SSMDetails(boots: int, interval: float, listwise: bool, angles: list[float], contrast: bool, score_type: str)

Details of SSM analysis configuration and parameters.

ATTRIBUTE DESCRIPTION
boots

Number of bootstrap resamples used for confidence intervals.

TYPE: int

interval

Confidence interval level (e.g., 0.95 for 95% CI).

TYPE: float

listwise

Whether listwise deletion was used for missing data.

TYPE: bool

angles

Angular displacements of the circumplex scales in degrees.

TYPE: list[float]

contrast

Whether the analysis involves contrasts between groups.

TYPE: bool

score_type

Type of scores used in analysis (mean or correlation).

TYPE: str

METHOD DESCRIPTION
from_dict

Create SSMDetails instance from dictionary.

to_dict

Convert SSMDetails instance to dictionary.

__rich_repr__

Generate rich console representation of SSM analysis details.

from_dict classmethod

from_dict(data: dict) -> SSMDetails

Create SSMDetails instance from dictionary.

PARAMETER DESCRIPTION
data

Dictionary containing SSM analysis parameters with keys: boots, interval, listwise, angles, contrast, score_type.

TYPE: dict

RETURNS DESCRIPTION
SSMDetails

New SSMDetails instance populated from dictionary data.

Source code in src/circumplex/ssm.py
@classmethod
def from_dict(cls, data: dict) -> SSMDetails:
    """Create SSMDetails instance from dictionary.

    Parameters
    ----------
    data
        Dictionary containing SSM analysis parameters with keys:
        boots, interval, listwise, angles, contrast, score_type.

    Returns
    -------
    :
        New SSMDetails instance populated from dictionary data.
    """
    return cls(
        boots=data["boots"],
        interval=data["interval"],
        listwise=data["listwise"],
        angles=data["angles"],
        contrast=data["contrast"],
        score_type=data["score_type"],
    )

to_dict

to_dict() -> dict[str, Any]

Convert SSMDetails instance to dictionary.

RETURNS DESCRIPTION
dict[str, Any]

Dictionary containing all SSMDetails attributes.

Source code in src/circumplex/ssm.py
def to_dict(self) -> dict[str, Any]:
    """Convert SSMDetails instance to dictionary.

    Returns
    -------
    :
        Dictionary containing all SSMDetails attributes.
    """
    return self.__dict__.copy()

__rich_repr__

__rich_repr__() -> Iterable[str]

Generate rich console representation of SSM analysis details.

Source code in src/circumplex/ssm.py
def __rich_repr__(self) -> Iterable[str]:
    """Generate rich console representation of SSM analysis details."""
    yield f"Statistical Basis:   {self.score_type.capitalize()} Scores"
    yield f"Bootstrap Resamples: {self.boots}"
    yield f"Confidence Level:    {self.interval}"
    yield f"Listwise Deletion:   {self.listwise}"
    yield f"Scale Displacements: {self.angles}"

SSM dataclass

SSM(results: DataFrame, scores: DataFrame, details: SSMDetails, type: str)

Results from a Structural Summary Method (SSM) analysis.

ATTRIBUTE DESCRIPTION
results

DataFrame containing SSM parameter estimates and confidence intervals.

TYPE: DataFrame

scores

DataFrame containing the circumplex scale scores used in the analysis.

TYPE: DataFrame

details

Configuration and parameters used in the SSM analysis.

TYPE: SSMDetails

type

Type of SSM analysis performed (e.g., profile, contrast).

TYPE: str

METHOD DESCRIPTION
from_dict

Create SSM instance from dictionary.

to_dict

Convert SSM instance to dictionary.

summary

Print a formatted summary of SSM analysis results.

plot_circle

Generate a circular SSM plot for the analysis results.

plot_curve

Generate SSM curve plots for the analysis results.

plot_contrast

Generate SSM parameter contrast plots for the analysis results.

from_dict classmethod

from_dict(data: dict) -> SSM

Create SSM instance from dictionary.

PARAMETER DESCRIPTION
data

Dictionary containing SSM analysis results with keys: results, scores, details, type.

TYPE: dict

RETURNS DESCRIPTION
SSM

New SSM instance populated from dictionary data.

Source code in src/circumplex/ssm.py
@classmethod
def from_dict(cls, data: dict) -> SSM:
    """Create SSM instance from dictionary.

    Parameters
    ----------
    data
        Dictionary containing SSM analysis results with keys:
        results, scores, details, type.

    Returns
    -------
    :
        New SSM instance populated from dictionary data.
    """
    return cls(
        results=data["results"],
        scores=data["scores"],
        details=SSMDetails.from_dict(data["details"]),
        type=data["type"],
    )

to_dict

to_dict() -> dict[str, Any]

Convert SSM instance to dictionary.

RETURNS DESCRIPTION
dict[str, Any]

Dictionary containing all SSM attributes with details converted to dict format.

Source code in src/circumplex/ssm.py
def to_dict(self) -> dict[str, Any]:
    """Convert SSM instance to dictionary.

    Returns
    -------
    :
        Dictionary containing all SSM attributes
        with details converted to dict format.
    """
    d = self.__dict__.copy()
    d["details"] = self.details.to_dict()
    return d

summary

summary(*, rich_print: bool = True) -> None

Print a formatted summary of SSM analysis results.

PARAMETER DESCRIPTION
rich_print

Whether to use rich console formatting for output, by default True. If False or rich is not installed, falls back to standard printing.

TYPE: bool DEFAULT: True

Source code in src/circumplex/ssm.py
def summary(self, *, rich_print: bool = True) -> None:
    """Print a formatted summary of SSM analysis results.

    Parameters
    ----------
    rich_print
        Whether to use rich console formatting for output, by default True.
        If False or rich is not installed, falls back to standard printing.
    """
    summ_secs = []  # Initialize summ_secs here
    if is_package_installed("rich") and rich_print:
        summ_secs = [*self.details.__rich_repr__()]
        summ_secs.append("\n")

        for _, row in self.results.iterrows():
            tbl = Table(title=f"Profile[{row.Label}]")
            tbl.add_column("")
            tbl.add_column("Estimate")
            tbl.add_column("Lower CI")
            tbl.add_column("Upper CI")

            for label, val in zip(
                ["Elevation", "X-Value", "Y-Value", "Amplitude", "Displacement"],
                ["e", "x", "y", "a", "d"],
                strict=False,
            ):
                tbl.add_row(
                    label,
                    str(round(row[f"{val}_est"], 3)),
                    str(round(row[f"{val}_lci"], 3)),
                    str(round(row[f"{val}_uci"], 3)),
                )
            tbl.add_row("Model Fit", str(round(row.fit_est, 3)))

            summ_secs.append(tbl)

        summ_group = Group(*summ_secs)  # This will now work correctly
        if console is not None:
            console.print(summ_group)
    else:
        # Non-rich version of the summary
        print(f"Statistical Basis: {self.details.score_type.capitalize()} Scores")  # noqa: T201
        print(f"Bootstrap Resamples: {self.details.boots}")  # noqa: T201
        print(f"Confidence Level: {self.details.interval}")  # noqa: T201
        print(f"Listwise Deletion: {self.details.listwise}")  # noqa: T201
        print(f"Scale Displacements: {self.details.angles}")  # noqa: T201
        print("\nResults:")  # noqa: T201
        for _, row in self.results.iterrows():
            print(f"Profile[{row.Label}]:")  # noqa: T201
            print(  # noqa: T201
                f"  Elevation: {round(row.e_est, 3)}, "
                f"Lower CI: {round(row.e_lci, 3)}, "
                f"Upper CI: {round(row.e_uci, 3)}"
            )
            print(  # noqa: T201
                f"  X-Value: {round(row.x_est, 3)}, "
                f"Lower CI: {round(row.x_lci, 3)}, "
                f"Upper CI: {round(row.x_uci, 3)}"
            )
            print(  # noqa: T201
                f"  Y-Value: {round(row.y_est, 3)}, "
                f"Lower CI: {round(row.y_lci, 3)}, "
                f"Upper CI: {round(row.y_uci, 3)}"
            )
            print(  # noqa: T201
                f"  Amplitude: {round(row.a_est, 3)}, "
                f"Lower CI: {round(row.a_lci, 3)}, "
                f"Upper CI: {round(row.a_uci, 3)}"
            )
            print(f"  Displacement: {round(row.d_est, 3)}")  # noqa: T201
            print(f"  Model Fit: {round(row.fit_est, 3)}\n")  # noqa: T201

plot_circle

plot_circle(**kwargs: Any) -> Figure

Generate a circular SSM plot for the analysis results.

Convenience method that passes SSM data to the plot_circle() function. Automatically plots all profiles in the results.

PARAMETER DESCRIPTION
**kwargs

Additional plotting options passed to plot_circle(). See plot_circle() documentation for available options (e.g., amax, angle_labels, colors, fontsize, drop_lowfit, figsize, title).

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
Figure

Matplotlib Figure object.

Examples:

>>> results = ssm_analyze(data, scales=list(range(8)))
>>> fig = results.plot_circle()
>>> fig.savefig('profile.png')
>>> fig = results.plot_circle(colors="husl", fontsize=14)
See Also

plot_circle : Full function documentation

Source code in src/circumplex/ssm.py
def plot_circle(self, **kwargs: Any) -> Figure:
    """Generate a circular SSM plot for the analysis results.

    Convenience method that passes SSM data to the plot_circle() function.
    Automatically plots all profiles in the results.

    Parameters
    ----------
    **kwargs
        Additional plotting options passed to plot_circle(). See plot_circle()
        documentation for available options (e.g., amax, angle_labels, colors,
        fontsize, drop_lowfit, figsize, title).

    Returns
    -------
    :
        Matplotlib Figure object.

    Examples
    --------
    >>> results = ssm_analyze(data, scales=list(range(8)))
    >>> fig = results.plot_circle()
    >>> fig.savefig('profile.png')

    >>> fig = results.plot_circle(colors="husl", fontsize=14)

    See Also
    --------
    [`plot_circle`](../plots/#circumplex.visualization.plots.plot_circle) :
        Full function documentation
    """
    return plot_circle(
        results_df=self.results,
        angles=self.details.angles,
        **kwargs,
    )

plot_curve

plot_curve(**kwargs: Any) -> Figure

Generate SSM curve plots for the analysis results.

Convenience method that passes SSM data to the plot_curve() function. Creates faceted plots showing fitted curves overlaid on observed scores.

PARAMETER DESCRIPTION
**kwargs

Additional plotting options passed to plot_curve(). See plot_curve() documentation for available options (e.g., angle_labels, colors, base_size, drop_lowfit, figsize).

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
Figure

Matplotlib Figure object.

Examples:

>>> results = ssm_analyze(data, scales=list(range(8)))
>>> fig = results.plot_curve()
>>> fig.savefig('curves.png')
>>> fig = results.plot_curve(angle_labels=['PA', 'BC', 'DE', 'FG',
...                                         'HI', 'JK', 'LM', 'NO'])
See Also

plot_curve : Full function documentation

Source code in src/circumplex/ssm.py
def plot_curve(self, **kwargs: Any) -> Figure:
    """Generate SSM curve plots for the analysis results.

    Convenience method that passes SSM data to the plot_curve() function.
    Creates faceted plots showing fitted curves overlaid on observed scores.

    Parameters
    ----------
    **kwargs
        Additional plotting options passed to plot_curve(). See plot_curve()
        documentation for available options (e.g., angle_labels, colors,
        base_size, drop_lowfit, figsize).

    Returns
    -------
    :
        Matplotlib Figure object.

    Examples
    --------
    >>> results = ssm_analyze(data, scales=list(range(8)))
    >>> fig = results.plot_curve()
    >>> fig.savefig('curves.png')

    >>> fig = results.plot_curve(angle_labels=['PA', 'BC', 'DE', 'FG',
    ...                                         'HI', 'JK', 'LM', 'NO'])

    See Also
    --------
    [`plot_curve`](../plots/#circumplex.visualization.plots.plot_curve) :
        Full function documentation
    """
    return plot_curve(
        results_df=self.results,
        scores_df=self.scores,
        angles=self.details.angles,
        **kwargs,
    )

plot_contrast

plot_contrast(**kwargs: Any) -> Figure

Generate SSM parameter contrast plots for the analysis results.

Convenience method that passes SSM data to the plot_contrast() function. Only available for contrast analyses (when contrast=True in ssm_analyze).

PARAMETER DESCRIPTION
**kwargs

Additional plotting options passed to plot_contrast(). See plot_contrast() documentation for available options (e.g., drop_xy, sig_color, ns_color, linewidth, fontsize, figsize).

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
Figure

Matplotlib Figure object.

RAISES DESCRIPTION
ValueError

If this SSM object does not contain contrast results.

Examples:

>>> results = ssm_analyze(data, scales=list(range(8)),
...                       grouping='condition', contrast=True)
>>> fig = results.plot_contrast()
>>> fig.savefig('contrasts.png')
>>> fig = results.plot_contrast(drop_xy=True)
See Also

plot_contrast : Full function documentation

Source code in src/circumplex/ssm.py
def plot_contrast(self, **kwargs: Any) -> Figure:
    """Generate SSM parameter contrast plots for the analysis results.

    Convenience method that passes SSM data to the plot_contrast() function.
    Only available for contrast analyses (when contrast=True in ssm_analyze).

    Parameters
    ----------
    **kwargs
        Additional plotting options passed to plot_contrast(). See
        plot_contrast() documentation for available options (e.g., drop_xy,
        sig_color, ns_color, linewidth, fontsize, figsize).

    Returns
    -------
    :
        Matplotlib Figure object.

    Raises
    ------
    ValueError
        If this SSM object does not contain contrast results.

    Examples
    --------
    >>> results = ssm_analyze(data, scales=list(range(8)),
    ...                       grouping='condition', contrast=True)
    >>> fig = results.plot_contrast()
    >>> fig.savefig('contrasts.png')

    >>> fig = results.plot_contrast(drop_xy=True)

    See Also
    --------
    [`plot_contrast`](../plots/#circumplex.visualization.plots.plot_contrast) :
        Full function documentation
    """
    if not self.details.contrast:
        msg = (
            "plot_contrast() requires contrast results. "
            "Run ssm_analyze() with contrast=True."
        )
        raise ValueError(msg)

    return plot_contrast(
        results_df=self.results,
        **kwargs,
    )