Standard Normal Distribution (Z-Score)
สูตร: Z = (X - μ) / σ
X = ค่าที่ต้องการ, μ = ค่าเฉลี่ย (mean), σ = ส่วนเบี่ยงเบนมาตรฐาน (standard deviation)
ตัวอย่างโค้ด
public class Demo {
public static void main(String[] args) {
double x = 68; // ค่าสังเกต
double mean = 102; // ค่าเฉลี่ย
double sd = 26; // ส่วนเบี่ยงเบนมาตรฐาน
double zScore = (x - mean) / sd;
System.out.println("X = " + x);
System.out.println("Mean (μ) = " + mean);
System.out.println("Std Dev (σ) = " + sd);
System.out.println("Z-Score = " + zScore);
// การตีความ
if (zScore < 0) {
System.out.println("ค่าต่ำกว่าค่าเฉลี่ย " + Math.abs(zScore) + " standard deviations");
} else if (zScore > 0) {
System.out.println("ค่าสูงกว่าค่าเฉลี่ย " + zScore + " standard deviations");
} else {
System.out.println("ค่าเท่ากับค่าเฉลี่ยพอดี");
}
}
}
ผลลัพธ์
X = 68.0 Mean (μ) = 102.0 Std Dev (σ) = 26.0 Z-Score = -1.3076923076923077 ค่าต่ำกว่าค่าเฉลี่ย 1.3076923076923077 standard deviations
การใช้งานเพิ่มเติม
- หาพื้นที่ใต้โค้ง (probability): ใช้
Apache Commons Mathหรือjava.lang.Mathประมาณ - Standard Normal Table: Z = -1.31 → ประมาณ 9.5% อยู่ด้านซ้าย
- ใน Java ไม่มี built-in CDF สำหรับ normal distribution ต้องใช้ library หรือประมาณเอง
Library แนะนำ
// Apache Commons Math
NormalDistribution dist = new NormalDistribution(mean, sd);
double probability = dist.cumulativeProbability(x); // P(X <= x)