-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze_data.py
More file actions
231 lines (181 loc) · 8.66 KB
/
analyze_data.py
File metadata and controls
231 lines (181 loc) · 8.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
"""
Stroop Test Veri Analizi
Stroop Etkisi hesaplama ve görselleştirme
"""
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import os
import glob
from datetime import datetime
# Türkçe karakter desteği için
plt.rcParams['font.family'] = 'DejaVu Sans'
sns.set_style("whitegrid")
sns.set_palette("husl")
def load_stroop_data(data_dir='data'):
"""Stroop test verilerini yükle"""
csv_files = glob.glob(os.path.join(data_dir, 'stroop_*.csv'))
if not csv_files:
print("Stroop test verisi bulunamadı!")
return None
# Tüm CSV dosyalarını birleştir
dfs = []
for file in csv_files:
df = pd.read_csv(file)
dfs.append(df)
if not dfs:
return None
data = pd.concat(dfs, ignore_index=True)
return data
def calculate_stroop_effect(data):
"""Stroop Etkisini hesapla"""
# Uyumlu denemeler: kelime ve renk aynı
# Uyumsuz denemeler: kelime ve renk farklı
congruent = data[data['congruent'] == True]
incongruent = data[data['congruent'] == False]
# Sadece doğru cevapları analiz et
congruent_correct = congruent[congruent['correct'] == True]
incongruent_correct = incongruent[incongruent['correct'] == True]
stats = {
'congruent': {
'mean_rt': congruent_correct['reactionTime'].mean() if len(congruent_correct) > 0 else 0,
'median_rt': congruent_correct['reactionTime'].median() if len(congruent_correct) > 0 else 0,
'std_rt': congruent_correct['reactionTime'].std() if len(congruent_correct) > 0 else 0,
'count': len(congruent_correct),
'accuracy': len(congruent_correct) / len(congruent) * 100 if len(congruent) > 0 else 0
},
'incongruent': {
'mean_rt': incongruent_correct['reactionTime'].mean() if len(incongruent_correct) > 0 else 0,
'median_rt': incongruent_correct['reactionTime'].median() if len(incongruent_correct) > 0 else 0,
'std_rt': incongruent_correct['reactionTime'].std() if len(incongruent_correct) > 0 else 0,
'count': len(incongruent_correct),
'accuracy': len(incongruent_correct) / len(incongruent) * 100 if len(incongruent) > 0 else 0
}
}
# Stroop Etkisi = Uyumsuz RT - Uyumlu RT
stroop_effect = stats['incongruent']['mean_rt'] - stats['congruent']['mean_rt']
stats['stroop_effect'] = stroop_effect
return stats
def visualize_stroop_effect(data, stats, output_dir='results'):
"""Stroop Etkisini görselleştir"""
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# 1. Uyumlu vs Uyumsuz Ortalama RT Karşılaştırması
fig, axes = plt.subplots(2, 2, figsize=(15, 12))
fig.suptitle('Stroop Etkisi Analizi', fontsize=16, fontweight='bold')
# Grafik 1: Ortalama Reaksiyon Zamanları
ax1 = axes[0, 0]
categories = ['Uyumlu\n(Congruent)', 'Uyumsuz\n(Incongruent)']
means = [stats['congruent']['mean_rt'], stats['incongruent']['mean_rt']]
stds = [stats['congruent']['std_rt'], stats['incongruent']['std_rt']]
bars = ax1.bar(categories, means, yerr=stds, capsize=10,
color=['#4CAF50', '#f44336'], alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.set_ylabel('Ortalama Reaksiyon Zamanı (ms)', fontsize=12)
ax1.set_title('Uyumlu vs Uyumsuz Ortalama RT', fontsize=14, fontweight='bold')
ax1.grid(axis='y', alpha=0.3)
# Değerleri çubukların üzerine yaz
for i, (bar, mean) in enumerate(zip(bars, means)):
height = bar.get_height()
ax1.text(bar.get_x() + bar.get_width()/2., height + stds[i],
f'{mean:.0f}ms',
ha='center', va='bottom', fontweight='bold')
# Stroop Etkisi değerini göster
ax1.text(0.5, max(means) * 0.9, f"Stroop Etkisi: {stats['stroop_effect']:.0f}ms",
ha='center', fontsize=11, bbox=dict(boxstyle='round', facecolor='yellow', alpha=0.5))
# Grafik 2: RT Dağılımı (Box Plot)
ax2 = axes[0, 1]
congruent_rt = data[(data['congruent'] == True) & (data['correct'] == True)]['reactionTime']
incongruent_rt = data[(data['congruent'] == False) & (data['correct'] == True)]['reactionTime']
box_data = [congruent_rt.dropna(), incongruent_rt.dropna()]
bp = ax2.boxplot(box_data, labels=['Uyumlu', 'Uyumsuz'],
patch_artist=True, widths=0.6)
# Box plot renklendirme
colors = ['#4CAF50', '#f44336']
for patch, color in zip(bp['boxes'], colors):
patch.set_facecolor(color)
patch.set_alpha(0.7)
ax2.set_ylabel('Reaksiyon Zamanı (ms)', fontsize=12)
ax2.set_title('RT Dağılımı (Box Plot)', fontsize=14, fontweight='bold')
ax2.grid(axis='y', alpha=0.3)
# Grafik 3: Doğruluk Oranları
ax3 = axes[1, 0]
accuracies = [stats['congruent']['accuracy'], stats['incongruent']['accuracy']]
bars3 = ax3.bar(categories, accuracies, color=['#4CAF50', '#f44336'],
alpha=0.7, edgecolor='black', linewidth=1.5)
ax3.set_ylabel('Doğruluk Oranı (%)', fontsize=12)
ax3.set_title('Uyumlu vs Uyumsuz Doğruluk', fontsize=14, fontweight='bold')
ax3.set_ylim([0, 100])
ax3.grid(axis='y', alpha=0.3)
for bar, acc in zip(bars3, accuracies):
height = bar.get_height()
ax3.text(bar.get_x() + bar.get_width()/2., height,
f'{acc:.1f}%',
ha='center', va='bottom', fontweight='bold')
# Grafik 4: Zaman Serisi (Deneme numarasına göre RT)
ax4 = axes[1, 1]
congruent_trials = data[(data['congruent'] == True) & (data['correct'] == True)].copy()
incongruent_trials = data[(data['congruent'] == False) & (data['correct'] == True)].copy()
if len(congruent_trials) > 0:
ax4.scatter(congruent_trials['trial'], congruent_trials['reactionTime'],
alpha=0.6, color='#4CAF50', label='Uyumlu', s=50)
if len(incongruent_trials) > 0:
ax4.scatter(incongruent_trials['trial'], incongruent_trials['reactionTime'],
alpha=0.6, color='#f44336', label='Uyumsuz', s=50)
ax4.set_xlabel('Deneme Numarası', fontsize=12)
ax4.set_ylabel('Reaksiyon Zamanı (ms)', fontsize=12)
ax4.set_title('RT Zaman Serisi', fontsize=14, fontweight='bold')
ax4.legend()
ax4.grid(alpha=0.3)
plt.tight_layout()
# Kaydet
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
output_file = os.path.join(output_dir, f'stroop_analysis_{timestamp}.png')
plt.savefig(output_file, dpi=300, bbox_inches='tight')
print(f"Grafik kaydedildi: {output_file}")
plt.show()
return output_file
def print_statistics(stats):
"""İstatistikleri yazdır"""
print("\n" + "="*60)
print("STROOP ETKİSİ ANALİZ SONUÇLARI")
print("="*60)
print("\n📊 UYUMLU DENEMELER (Congruent):")
print(f" Ortalama RT: {stats['congruent']['mean_rt']:.2f} ms")
print(f" Medyan RT: {stats['congruent']['median_rt']:.2f} ms")
print(f" Standart Sapma: {stats['congruent']['std_rt']:.2f} ms")
print(f" Doğru Cevap Sayısı: {stats['congruent']['count']}")
print(f" Doğruluk Oranı: {stats['congruent']['accuracy']:.2f}%")
print("\n📊 UYUMSUZ DENEMELER (Incongruent):")
print(f" Ortalama RT: {stats['incongruent']['mean_rt']:.2f} ms")
print(f" Medyan RT: {stats['incongruent']['median_rt']:.2f} ms")
print(f" Standart Sapma: {stats['incongruent']['std_rt']:.2f} ms")
print(f" Doğru Cevap Sayısı: {stats['incongruent']['count']}")
print(f" Doğruluk Oranı: {stats['incongruent']['accuracy']:.2f}%")
print("\n" + "="*60)
print(f"🎯 STROOP ETKİSİ: {stats['stroop_effect']:.2f} ms")
print("="*60)
if stats['stroop_effect'] > 0:
print(f"\n✅ Stroop Etkisi tespit edildi!")
print(f" Uyumsuz denemeler, uyumlu denemelerden {stats['stroop_effect']:.2f} ms daha yavaş.")
else:
print(f"\n⚠️ Beklenmeyen sonuç: Stroop Etkisi negatif veya sıfır.")
print()
def main():
"""Ana analiz fonksiyonu"""
print("Stroop Test Veri Analizi Başlatılıyor...")
# Veriyi yükle
data = load_stroop_data()
if data is None or len(data) == 0:
print("Analiz için yeterli veri bulunamadı!")
print("Lütfen önce testi çalıştırıp veri toplayın.")
return
print(f"Toplam {len(data)} deneme yüklendi.")
# Stroop Etkisini hesapla
stats = calculate_stroop_effect(data)
# İstatistikleri yazdır
print_statistics(stats)
# Görselleştir
visualize_stroop_effect(data, stats)
print("\n✅ Analiz tamamlandı!")
if __name__ == '__main__':
main()