İçeriğe geç
KAMPANYA Kurumsal Web Paketi — $499'dan başlayan fiyatlar Web & Logo Tasarımı · Kurumsal E-posta · LiteSpeed + CloudLinux · Imunify360 Güvenlik · cPanel Yönetim · 3 Gbps DDoS Koruması 00 Gün 00 Saat 00 Dk 00 Sn
AIOR

How to Calculate P-Value — Step-by-Step Computation, Interpretation and Pra

Sektör topluluğu — sorularınız, deneyimleriniz ve duyurularınız için.

How to Calculate P-Value — Step-by-Step Computation, Interpretation and Pra

Aior

Administrator
Staff member
Joined
Apr 2, 2023
Messages
895
Reaction score
2
Points
18
Age
40
Location
Turkey
Website
aior.com
1/3
Thread owner

P-value, istatistiksel hipotez testlerinde belki de en sık konuşulan ama yine de en sık yanlış yorumlanan kavramdır. Tanımı kısaca şu: H0 (sıfır hipotezi) gerçek olduğu durumda, eldeki veriyi veya daha aşırı bir sonucu gözlemleme olasılığı. Hesaplaması seçtiğiniz teste ve dağılım modeline göre değişir ama temel akış aynıdır. Bu yazıda en yaygın senaryolar için adım adım hesaplama yöntemini, pratik kod örneklerini ve sık yapılan yorumlama hatalarını anlatıyoruz.

1) Test türüne karar verin
Veri tipinize ve hipotezinize göre test farklıdır:
  • Tek örneklem t-testi: tek bir grubun ortalaması bilinen bir değere eşit mi?
  • Bağımsız iki örneklem t-testi: iki grubun ortalaması farklı mı?
  • Eşleştirilmiş t-testi: aynı bireylerin önce/sonra ölçümleri farklı mı?
  • Ki-kare: kategorik veri için gözlenen vs beklenen.
  • Z-testi: büyük örneklem ve bilinen popülasyon varyansı için.
  • ANOVA: ikiden fazla grubun karşılaştırılması.

2) İstatistiği hesaplayın
İki örneklem t-testi için klasik formül:
Code:
t = (X̄₁ - X̄₂) / sqrt(s₁²/n₁ + s₂²/n₂)
Burada X̄ ortalama, s² varyans, n örneklem büyüklüğüdür. Python ile:
Code:
from scipy import stats
t_stat, p_val = stats.ttest_ind(group1, group2)
print(p_val)

3) Z-testi örneği
Code:
from statsmodels.stats.weightstats import ztest
z_stat, p_val = ztest(group1, group2)
Z-testi, n>30 ve varyansların bilindiği durumlarda tercih edilir; küçük örneklemde t-testi daha güvenlidir.

4) Ki-kare bağımsızlık testi
Code:
from scipy.stats import chi2_contingency
chi2, p_val, dof, expected = chi2_contingency(observed_table)
Çıktıdaki p_val değeri sıfır hipotezinin ("değişkenler bağımsız") reddedilip reddedilemeyeceğini gösterir.

5) ANOVA
İkiden fazla grup arasındaki ortalama farkı için:
Code:
from scipy.stats import f_oneway
f_stat, p_val = f_oneway(g1, g2, g3, g4)

6) Yorumlama
p < 0.05 ise sıfır hipotezi reddedilebilir (yaygın eşik). Ama bu "H1 doğru" demek değildir; sadece veriye uyumun düşük olduğunu söyler. p = 0.04 ile p = 0.06 arasında istatistiksel olarak büyük bir fark yoktur; bilimsel olarak ikisi de benzer kanıt gücü taşır.

7) Sık yapılan hatalar
  • "p düşük çünkü etki büyük": yanlış. p, etki büyüklüğünü değil, gözlenen sonucun H0 altında olası olmadığını ölçer.
  • Çoklu test düzeltmesi yapmama: aynı veri setinde 20 test yapıyorsanız, 0.05 eşiği Bonferroni veya FDR ile düzeltilmeli.
  • Tek yönlü vs iki yönlü test karıştırma: yönü baştan belirleyin, sonradan değiştirmek p-hacking'tir.
  • Küçük örneklemde t-testini büyük örneklem gibi kullanma: dağılım varsayımlarını kontrol edin.

8) Pratik öneri
P-value yalnız bir gösterge; etki büyüklüğü (Cohen's d), güven aralığı ve örneklem büyüklüğü ile birlikte raporlayın. AIOR analiz ekibinde her test çıktısı için bu üçlü standarttır.


P-value is one of the most-discussed and most-misinterpreted concepts in statistics. The short definition: it is the probability of observing the current data — or something even more extreme — assuming the null hypothesis (H0) is true. The actual computation depends on the test you choose, but the overall workflow is the same. This guide walks through the most common scenarios with code examples and the interpretation pitfalls we routinely see in client reports.

1) Choose the test
The right test depends on your data type and the question you're asking:
  • One-sample t-test — does a single group mean equal a known value?
  • Two-sample independent t-test — do two groups have different means?
  • Paired t-test — do before/after measurements on the same individuals differ?
  • Chi-square — for categorical data, observed vs expected.
  • Z-test — large samples with known population variance.
  • ANOVA — comparing three or more group means.

2) Compute the statistic
For an independent two-sample t-test the textbook formula is:
Code:
t = (X̄₁ - X̄₂) / sqrt(s₁²/n₁ + s₂²/n₂)
In Python:
Code:
from scipy import stats
t_stat, p_val = stats.ttest_ind(group1, group2)
print(p_val)

3) Z-test example
Code:
from statsmodels.stats.weightstats import ztest
z_stat, p_val = ztest(group1, group2)
Z is appropriate when n > 30 and the population variance is known; for smaller samples the t-test is safer.

4) Chi-square independence
Code:
from scipy.stats import chi2_contingency
chi2, p_val, dof, expected = chi2_contingency(observed_table)
The p_val tells you whether to reject the null that the two variables are independent.

5) ANOVA
For three or more groups:
Code:
from scipy.stats import f_oneway
f_stat, p_val = f_oneway(g1, g2, g3, g4)

6) Interpretation
p < 0.05 lets you reject the null at the conventional threshold. That does not mean H1 is "true" — only that the data are unlikely under H0. The difference between p = 0.04 and p = 0.06 is statistically and scientifically minor; do not treat them as categorically different evidence.

7) Common mistakes
  • "P is low because the effect is large" — wrong. P measures evidence against H0, not effect size.
  • Skipping multiple-testing corrections — when running 20 tests on the same data, adjust with Bonferroni or FDR.
  • Mixing one-sided and two-sided tests — fix the direction in advance; changing it after seeing the data is p-hacking.
  • Using t-test on small samples without checking distribution assumptions — visualise first, then test.

8) Practical advice
Always report effect size (Cohen's d), confidence intervals and sample size alongside p-value. At AIOR's analytics team this triple is the minimum bar for any reported test.
 

Forum statistics

Threads
891
Messages
898
Members
27
Latest member
AIORAli

Members online

No members online now.

Featured content

AIOR
AIOR TEKNOLOJİ

Tüm ihtiyaçlarınız için Teklif alın

Hosting · Domain · Sunucu · Tasarım · Yazılım · Mühendislik · Sektörel Çözümler

Teklif al

7/24 Destek · Anında yanıt

Back
Top