ทำการทดสอบ t-test ทุกประเภท: t-test แบบตัวอย่างเดียว, t-test แบบตัวอย่างสองตัว, และ t-test แบบคู่ เครื่องคิดเลขนี้ช่วยให้คุณสามารถทำการทดสอบสมมติฐานทางสถิติสำหรับค่าเฉลี่ย ช่วยในการวิเคราะห์ข้อมูลและการตีความผลลัพธ์
t-test เป็นเครื่องมือทางสถิติพื้นฐานที่ใช้ในการกำหนดว่ามีความแตกต่างที่มีนัยสำคัญระหว่างค่าเฉลี่ยของกลุ่มหรือไม่ มันถูกนำไปใช้ในหลายสาขา เช่น จิตวิทยา การแพทย์ และธุรกิจเพื่อการทดสอบสมมติฐาน เครื่องคิดเลขนี้ช่วยให้คุณสามารถทำ t-test ทุกประเภทได้:
เลือกประเภทของ T-Test:
ป้อนข้อมูลที่จำเป็น:
สำหรับ One-Sample T-Test:
สำหรับ Two-Sample T-Test:
สำหรับ Paired T-Test:
ตั้งค่าระดับความสำคัญ ():
เลือกทิศทางของการทดสอบ:
คลิกปุ่ม "คำนวณ":
เครื่องคิดเลขจะแสดง:
ก่อนใช้ t-test ให้แน่ใจว่าสมมติฐานต่อไปนี้ได้รับการตอบสนอง:
T-statistic คำนวณได้ดังนี้:
ส่วนเบี่ยงเบนมาตรฐานรวม ():
เครื่องคิดเลขจะทำตามขั้นตอนต่อไปนี้:
แม้ว่า t-tests จะมีประสิทธิภาพ แต่ก็มีสมมติฐานที่อาจไม่เป็นจริงเสมอไป ทางเลือกอื่น ๆ ได้แก่:
t-test ถูกพัฒนาโดย William Sealy Gosset ในปี 1908 ซึ่งเขาเผยแพร่ภายใต้ชื่อ "Student" ขณะทำงานที่โรงเบียร์ Guinness ในดับลิน การทดสอบถูกออกแบบมาเพื่อตรวจสอบคุณภาพของเบียร์โดยการกำหนดว่าตัวอย่างที่ทดสอบมีความสอดคล้องกับมาตรฐานของโรงเบียร์หรือไม่ เนื่องจากข้อตกลงความลับ Gosset จึงใช้ชื่อเล่น "Student" ซึ่งนำไปสู่คำว่า "Student's t-test."
เมื่อเวลาผ่านไป t-test ได้กลายเป็นรากฐานในด้านการวิเคราะห์ทางสถิติ ซึ่งได้รับการสอนและนำไปใช้ในหลายสาขาวิทยาศาสตร์ มันได้ปูทางสำหรับการพัฒนาวิธีการทางสถิติที่ซับซ้อนมากขึ้นและเป็นพื้นฐานในสถิติอนุมาน
นี่คือตัวอย่างโค้ดสำหรับการทำ One-Sample T-Test ในหลายภาษาโปรแกรม:
1' One-Sample T-Test in Excel VBA
2Sub OneSampleTTest()
3 Dim sampleData As Range
4 Set sampleData = Range("A1:A9") ' แทนที่ด้วยช่วงข้อมูลของคุณ
5 Dim hypothesizedMean As Double
6 hypothesizedMean = 50 ' แทนที่ด้วยค่าเฉลี่ยที่คุณสมมติ
7
8 Dim sampleMean As Double
9 Dim sampleStdDev As Double
10 Dim sampleSize As Integer
11 Dim tStat As Double
12
13 sampleMean = Application.WorksheetFunction.Average(sampleData)
14 sampleStdDev = Application.WorksheetFunction.StDev_S(sampleData)
15 sampleSize = sampleData.Count
16
17 tStat = (sampleMean - hypothesizedMean) / (sampleStdDev / Sqr(sampleSize))
18
19 MsgBox "T-Statistic: " & Format(tStat, "0.00")
20End Sub
21
1## One-Sample T-Test in R
2sample_data <- c(51, 49, 52, 48, 50, 47, 53, 49, 51)
3t_test_result <- t.test(sample_data, mu = 50)
4print(t_test_result)
5
1import numpy as np
2from scipy import stats
3
4## One-Sample T-Test in Python
5sample_data = [51, 49, 52, 48, 50, 47, 53, 49, 51]
6t_statistic, p_value = stats.ttest_1samp(sample_data, 50)
7print(f"T-Statistic: {t_statistic:.2f}, P-Value: {p_value:.4f}")
8
1// One-Sample T-Test in JavaScript
2function oneSampleTTest(sample, mu0) {
3 const n = sample.length;
4 const mean = sample.reduce((a, b) => a + b) / n;
5 const sd = Math.sqrt(sample.map(x => (x - mean) ** 2).reduce((a, b) => a + b) / (n - 1));
6 const t = (mean - mu0) / (sd / Math.sqrt(n));
7 return t;
8}
9
10// ตัวอย่างการใช้งาน:
11const sampleData = [51, 49, 52, 48, 50, 47, 53, 49, 51];
12const tStatistic = oneSampleTTest(sampleData, 50);
13console.log(`T-Statistic: ${tStatistic.toFixed(2)}`);
14
1% One-Sample T-Test in MATLAB
2sampleData = [51, 49, 52, 48, 50, 47, 53, 49, 51];
3[h, p, ci, stats] = ttest(sampleData, 50);
4disp(['T-Statistic: ', num2str(stats.tstat)]);
5disp(['P-Value: ', num2str(p)]);
6
1import org.apache.commons.math3.stat.inference.TTest;
2
3public class OneSampleTTest {
4 public static void main(String[] args) {
5 double[] sampleData = {51, 49, 52, 48, 50, 47, 53, 49, 51};
6 TTest tTest = new TTest();
7 double mu = 50;
8 double tStatistic = tTest.t(mu, sampleData);
9 double pValue = tTest.tTest(mu, sampleData);
10 System.out.printf("T-Statistic: %.2f%n", tStatistic);
11 System.out.printf("P-Value: %.4f%n", pValue);
12 }
13}
14
1using System;
2using MathNet.Numerics.Statistics;
3
4class OneSampleTTest
5{
6 static void Main()
7 {
8 double[] sampleData = {51, 49, 52, 48, 50, 47, 53, 49, 51};
9 double mu0 = 50;
10 int n = sampleData.Length;
11 double mean = Statistics.Mean(sampleData);
12 double stdDev = Statistics.StandardDeviation(sampleData);
13 double tStatistic = (mean - mu0) / (stdDev / Math.Sqrt(n));
14 Console.WriteLine($"T-Statistic: {tStatistic:F2}");
15 }
16}
17
1package main
2
3import (
4 "fmt"
5 "math"
6)
7
8func oneSampleTTest(sample []float64, mu0 float64) float64 {
9 n := float64(len(sample))
10 var sum, mean, sd float64
11
12 for _, v := range sample {
13 sum += v
14 }
15 mean = sum / n
16
17 for _, v := range sample {
18 sd += math.Pow(v - mean, 2)
19 }
20 sd = math.Sqrt(sd / (n - 1))
21
22 t := (mean - mu0) / (sd / math.Sqrt(n))
23 return t
24}
25
26func main() {
27 sampleData := []float64{51, 49, 52, 48, 50, 47, 53, 49, 51}
28 tStatistic := oneSampleTTest(sampleData, 50)
29 fmt.Printf("T-Statistic: %.2f\n", tStatistic)
30}
31
1import Foundation
2
3func oneSampleTTest(sample: [Double], mu0: Double) -> Double {
4 let n = Double(sample.count)
5 let mean = sample.reduce(0, +) / n
6 let sd = sqrt(sample.map { pow($0 - mean, 2) }.reduce(0, +) / (n - 1))
7 let t = (mean - mu0) / (sd / sqrt(n))
8 return t
9}
10
11let sampleData = [51, 49, 52, 48, 50, 47, 53, 49, 51]
12let tStatistic = oneSampleTTest(sample: sampleData, mu0: 50)
13print(String(format: "T-Statistic: %.2f", tStatistic))
14
1<?php
2function oneSampleTTest($sample, $mu0) {
3 $n = count($sample);
4 $mean = array_sum($sample) / $n;
5 $sd = sqrt(array_sum(array_map(function($x) use ($mean) {
6 return pow($x - $mean, 2);
7 }, $sample)) / ($n - 1));
8 $t = ($mean - $mu0) / ($sd / sqrt($n));
9 return $t;
10}
11
12$sampleData = [51, 49, 52, 48, 50, 47, 53, 49, 51];
13$tStatistic = oneSampleTTest($sampleData, 50);
14echo "T-Statistic: " . number_format($tStatistic, 2);
15?>
16
1## One-Sample T-Test in Ruby
2def one_sample_t_test(sample, mu0)
3 n = sample.size
4 mean = sample.sum(0.0) / n
5 sd = Math.sqrt(sample.map { |x| (x - mean)**2 }.sum / (n - 1))
6 t = (mean - mu0) / (sd / Math.sqrt(n))
7 t
8end
9
10sample_data = [51, 49, 52, 48, 50, 47, 53, 49, 51]
11t_statistic = one_sample_t_test(sample_data, 50)
12puts format("T-Statistic: %.2f", t_statistic)
13
1// One-Sample T-Test in Rust
2fn one_sample_t_test(sample: &Vec<f64>, mu0: f64) -> f64 {
3 let n = sample.len() as f64;
4 let mean: f64 = sample.iter().sum::<f64>() / n;
5 let sd = (sample.iter().map(|x| (x - mean).powi(2)).sum::<f64>() / (n - 1.0)).sqrt();
6 let t = (mean - mu0) / (sd / n.sqrt());
7 t
8}
9
10fn main() {
11 let sample_data = vec![51.0, 49.0, 52.0, 48.0, 50.0, 47.0, 53.0, 49.0, 51.0];
12 let t_statistic = one_sample_t_test(&sample_data, 50.0);
13 println!("T-Statistic: {:.2}", t_statistic);
14}
15
ปัญหา: ผู้ผลิตอ้างว่าค่าเฉลี่ยอายุการใช้งานของแบตเตอรี่คือ 50 ชั่วโมง กลุ่มผู้บริโภคทดสอบแบตเตอรี่ 9 ตัวและบันทึกอายุการใช้งานดังต่อไปนี้ (เป็นชั่วโมง):
มีหลักฐานที่ระดับความสำคัญ 0.05 เพื่อแสดงว่าค่าเฉลี่ยอายุการใช้งานแบตเตอรี่แตกต่างจาก 50 ชั่วโมงหรือไม่?
วิธีการแก้ไข:
ตั้งสมมติฐาน:
คำนวณค่าเฉลี่ยตัวอย่าง ():
คำนวณส่วนเบี่ยงเบนมาตรฐานของตัวอย่าง ():
คำนวณ T-Statistic:
Degrees of Freedom:
กำหนด P-Value:
ข้อสรุป:
ค้นพบเครื่องมือเพิ่มเติมที่อาจมีประโยชน์สำหรับการทำงานของคุณ