from dataclasses import dataclass
import numpy as np
[docs]
@dataclass(slots=True, kw_only=True)
class KAlphaObservationsMatrix:
"""
Data class to hold the observations matrix and related totals for Krippendorff's Alpha analysis.
Attributes:
observations_matrix (np.ndarray): A 2D numpy array representing the observations matrix.
row_totals (np.ndarray): A 1D numpy array representing the totals for each row.
column_totals (np.ndarray): A 1D numpy array representing the totals for each column.
total (int): The grand total of all observations.
n_filtered_units (int | None): The number of filtered units (only set when filtering units).
macro_categories_dict (dict[str, list[int]] | None): An optional dictionary mapping macro-category names to lists of category indices.
"""
observations_matrix: np.ndarray
row_totals: np.ndarray
column_totals: np.ndarray
total: int
n_filtered_units: int | None = None
# Optional dictionary representing the macro-category mapping
macro_categories_dict: dict[str, list[int]] | None = None
def __str__(self):
s: str = f"{self.observations_matrix}\n"
s += f"Row totals: {self.row_totals}\n"
s += f"Column totals: {self.column_totals}\n"
s += f"Grand total: {self.total}\n"
if self.macro_categories_dict:
s += "Macro-categories mapping:\n"
for macro_cat, categories in self.macro_categories_dict.items():
s += f"Macro-category '{macro_cat}': Categories {categories}\n"
return s