CoolFace
Datasetpublic

CoreEmotionFramework/CEF_Main_Archive

Core Emotion Framework (CEF) Main Archive The Decalogue of Operators The Core Emotion Framework defines exactly ten functional operators. This is the complete and authoritative set. No additional operators exist. No operators may be removed, renamed, or substituted. This dataset serves as the absolute source of truth for the following: Sensing Calculating Deciding Expanding Constricting Achieving Arranging Appreciating Boosting Accepting { "@context":… See the full description on the dataset page: https://huggingface.co/datasets/CoreEmotionFramework/CEF_Main_Archive.

sourceHugging Facecc-by-4.0updated 3mo agoView on Hugging Face
0likes4.7kdownloads
Phase1_analysis.py104 linesDownload Raw Back to root
1import pandas as pd
2import numpy as np
3import pingouin as pg
4from semopy import Model
5from semopy import calc_stats
6
7# ---------------------------------------------------------
8# 1. LOAD DATA
9# ---------------------------------------------------------
10DATA_PATH = "phase1_clean.csv"
11print("Loading data from:", DATA_PATH)
12
13df = pd.read_csv(DATA_PATH)
14
15# ---------------------------------------------------------
16# 2. DEFINE OPERATORS
17# ---------------------------------------------------------
18operators = [
19    "accepting", "achieving", "appreciating", "arranging",
20    "boosting", "calculating", "constricting", "deciding",
21    "expanding", "sensing"
22]
23
24# ---------------------------------------------------------
25# 3. RECONSTRUCT ITEMS IN THE ORDER THEY APPEAR IN THE CSV
26# ---------------------------------------------------------
27ordered_items = {}
28
29for op in operators:
30    cols = [c for c in df.columns if c.startswith(op + "_")]
31    # Sort by the numeric suffix
32    cols_sorted = sorted(cols, key=lambda x: int(x.split("_")[1]))
33    ordered_items[op] = cols_sorted
34
35# ---------------------------------------------------------
36# 4. COMPUTE CRONBACH ALPHAS
37# ---------------------------------------------------------
38print("\n=== CRONBACH ALPHAS ===")
39alpha_results = {}
40
41for op, cols in ordered_items.items():
42    data = df[cols]
43    alpha = pg.cronbach_alpha(data)[0]
44    alpha_results[op] = alpha
45    print(f"{op:12s} α = {alpha:.3f}")
46
47pd.DataFrame(alpha_results.items(), columns=["operator", "alpha"]).to_csv(
48    "operator_reliability.csv", index=False
49)
50print("\nSaved operator_reliability.csv")
51
52# ---------------------------------------------------------
53# 5. BUILD CFA MODEL STRING
54# ---------------------------------------------------------
55model_lines = []
56for op, cols in ordered_items.items():
57    line = f"{op} =~ " + " + ".join(cols)
58    model_lines.append(line)
59
60model_string = "\n".join(model_lines)
61
62print("\n=== CFA MODEL STRING ===")
63print(model_string)
64
65# ---------------------------------------------------------
66# 6. FIT CFA MODEL
67# ---------------------------------------------------------
68print("\n=== FITTING CFA MODEL ===")
69
70# Drop rows with missing values
71all_items = [c for cols in ordered_items.values() for c in cols]
72cfa_data = df[all_items].dropna()
73
74model = Model(model_string)
75model.fit(cfa_data)
76
77# ---------------------------------------------------------
78# 7. FIT INDICES
79# ---------------------------------------------------------
80print("\n=== CFA FIT INDICES ===")
81stats = calc_stats(model)
82fit_df = pd.DataFrame(stats.items(), columns=["index", "value"])
83print(fit_df)
84
85fit_df.to_csv("cfa_fit_indices.csv", index=False)
86print("Saved cfa_fit_indices.csv")
87
88# ---------------------------------------------------------
89# 8. STANDARDIZED LOADINGS (modern semopy API)
90# ---------------------------------------------------------
91print("\n=== STANDARDIZED LOADINGS ===")
92
93params = model.inspect(std_est=True)
94
95# Filter for loadings: op == "=~"
96loadings = params[params["op"] == "~"]
97
98print(loadings)
99
100loadings.to_csv("cfa_loadings.csv", index=False)
101print("Saved cfa_loadings.csv")
102
103print("\nDone.")
104