🛠️

Whiz Tools

Build • Create • Innovate

ਟੀ-ਟੈਸਟ ਕੈਲਕੁਲੇਟਰ: ਇੱਕ-ਨਮੂਨਾ, ਦੋ-ਨਮੂਨਾ, ਜੋੜੇ ਟੀ-ਟੈਸਟ

ਸਾਰੇ ਤਰ੍ਹਾਂ ਦੇ ਟੀ-ਟੈਸਟ ਕਰੋ: ਇੱਕ-ਨਮੂਨਾ, ਦੋ-ਨਮੂਨਾ, ਅਤੇ ਜੋੜੇ ਟੀ-ਟੈਸਟ। ਇਹ ਕੈਲਕੁਲੇਟਰ ਤੁਹਾਨੂੰ ਮੀਨ ਲਈ ਅੰਕੜਾ ਪਰਖ ਕਰਨ ਦੀ ਆਗਿਆ ਦਿੰਦਾ ਹੈ, ਜੋ ਡੇਟਾ ਵਿਸ਼ਲੇਸ਼ਣ ਅਤੇ ਨਤੀਜਿਆਂ ਦੀ ਵਿਆਖਿਆ ਵਿੱਚ ਮਦਦ ਕਰਦਾ ਹੈ।

ਟੀ-ਟੈਸਟ ਕੈਲਕੂਲੇਟਰ

sampleDataDescription
📚

ਦਸਤਾਵੇਜ਼

T-Test Calculator

Introduction

t-test ਇੱਕ ਮੁੱਢਲੀ ਅੰਕੜਾ ਸਾਧਨ ਹੈ ਜੋ ਸਮੂਹਾਂ ਦੇ ਮਾਧਿਆਨ ਵਿਚ ਮਹੱਤਵਪੂਰਨ ਫਰਕ ਹੈ ਜਾਂ ਨਹੀਂ, ਇਹ ਨਿਰਧਾਰਿਤ ਕਰਨ ਲਈ ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ। ਇਹ ਮਨੋਵਿਗਿਆਨ, ਚਿਕਿਤਸਾ ਅਤੇ ਵਪਾਰ ਵਰਗੇ ਵੱਖ-ਵੱਖ ਖੇਤਰਾਂ ਵਿੱਚ ਪਰਿਕਲਪਨਾ ਪਰੀਖਣ ਲਈ ਵਿਸ਼ੇਸ਼ਤਾਪੂਰਕ ਹੈ। ਇਹ ਕੈਲਕੁਲੇਟਰ ਤੁਹਾਨੂੰ ਸਾਰੇ ਕਿਸਮਾਂ ਦੇ t-ਟੈਸਟ ਕਰਨ ਦੀ ਆਗਿਆ ਦਿੰਦਾ ਹੈ:

  • One-Sample T-Test: ਇੱਕ ਸਮੂਹ ਦੇ ਮਾਧਿਆਨ ਨੂੰ ਜਾਣੇ ਜਾਂਦੇ ਮੁੱਲ ਨਾਲ ਤੁਲਨਾ ਕਰਦਾ ਹੈ।
  • Two-Sample T-Test (Independent Samples): ਦੋ ਸੁਤੰਤਰ ਸਮੂਹਾਂ ਦੇ ਮਾਧਿਆਨ ਦੀ ਤੁਲਨਾ ਕਰਦਾ ਹੈ।
  • Paired T-Test: ਇੱਕ ਹੀ ਸਮੂਹ ਦੇ ਵੱਖ-ਵੱਖ ਸਮੇਂ (ਜਿਵੇਂ, ਇਲਾਜ ਤੋਂ ਪਹਿਲਾਂ ਅਤੇ ਬਾਅਦ) ਦੇ ਮਾਧਿਆਨ ਦੀ ਤੁਲਨਾ ਕਰਦਾ ਹੈ।

Types of T-Tests

Sample Data Population Mean One-Sample T-Test Sample 1 Sample 2 Mean Difference Two-Sample T-Test Before After Differences Paired T-Test

How to Use This Calculator

  1. Select the Type of T-Test:

    • One-Sample T-Test
    • Two-Sample T-Test
    • Paired T-Test
  2. Enter the Required Inputs:

    • For One-Sample T-Test:

      • Sample Mean (xˉ\bar{x})
      • Sample Standard Deviation (ss)
      • Sample Size (nn)
      • Population Mean (μ0\mu_0)
    • For Two-Sample T-Test:

      • Mean of Sample 1 (xˉ1\bar{x}_1)
      • Standard Deviation of Sample 1 (s1s_1)
      • Sample Size of Sample 1 (n1n_1)
      • Mean of Sample 2 (xˉ2\bar{x}_2)
      • Standard Deviation of Sample 2 (s2s_2)
      • Sample Size of Sample 2 (n2n_2)
      • Variance Assumption: Select whether variances are assumed equal or unequal.
    • For Paired T-Test:

      • Differences Data: Enter the pairwise differences.
      • Alternatively, enter the Mean of Differences (dˉ\bar{d}), Standard Deviation of Differences (sds_d), and Sample Size (nn).
  3. Set the Significance Level (α\alpha):

    • Common choices are 0.05 for a 95% confidence level or 0.01 for a 99% confidence level.
  4. Choose the Test Direction:

    • Two-Tailed Test: Tests for any difference.
    • One-Tailed Test: Tests for a directional difference (specify if testing for greater than or less than).
  5. Click the "Calculate" Button:

    • The calculator will display:

      • T-Statistic
      • Degrees of Freedom
      • P-Value
      • Conclusion: Whether to reject or fail to reject the null hypothesis.

Assumptions

t-test ਵਰਤਣ ਤੋਂ ਪਹਿਲਾਂ, ਯਕੀਨੀ ਬਣਾਓ ਕਿ ਹੇਠਾਂ ਦਿੱਤੀਆਂ ਧਾਰਨਾਵਾਂ ਪੂਰੀਆਂ ਹੋਈਆਂ ਹਨ:

  • Normality: ਡੇਟਾ ਲਗਭਗ ਨਾਰਮਲ ਵੰਡਿਆ ਹੋਣਾ ਚਾਹੀਦਾ ਹੈ।
  • Independence: ਨਿਗਮਾਂ ਇੱਕ ਦੂਜੇ ਤੋਂ ਸੁਤੰਤਰ ਹੋਣੇ ਚਾਹੀਦੇ ਹਨ।
    • Two-Sample T-Test ਲਈ, ਦੋ ਸਮੂਹ ਸੁਤੰਤਰ ਹੋਣੇ ਚਾਹੀਦੇ ਹਨ।
    • Paired T-Test ਲਈ, ਫਰਕ ਸੁਤੰਤਰ ਹੋਣਾ ਚਾਹੀਦਾ ਹੈ।
  • Equality of Variances:
    • Two-Sample T-Test with Equal Variances ਲਈ, ਦੋ ਆਬਾਦੀਆਂ ਦੇ ਵੈਰੀਅੰਸ ਬਰਾਬਰ ਹੋਣੇ ਚਾਹੀਦੇ ਹਨ (ਹੋਮੋਸਕੇਡਾਸਿਟੀ)।
    • ਜੇ ਇਹ ਧਾਰਨਾ ਪੂਰੀ ਨਹੀਂ ਹੁੰਦੀ, ਤਾਂ Welch's T-Test (ਅਸਮਾਨ ਵੈਰੀਅੰਸ) ਵਰਤੋਂ।

Formula

One-Sample T-Test

t-ਸਟੈਟਿਸਟਿਕ ਦੀ ਗਣਨਾ ਇਸ ਤਰ੍ਹਾਂ ਕੀਤੀ ਜਾਂਦੀ ਹੈ:

t=xˉμ0snt = \frac{\bar{x} - \mu_0}{\frac{s}{\sqrt{n}}}
  • xˉ\bar{x}: ਨਮੂਨਾ ਮਾਧਿਆਨ
  • μ0\mu_0: ਨਲ ਧਾਰਨਾ ਦੇ ਅਧੀਨ ਆਬਾਦੀ ਦਾ ਮਾਧਿਆਨ
  • ss: ਨਮੂਨਾ ਮਿਆਰੀ ਵਿਸ਼ਮਤਾ
  • nn: ਨਮੂਨਾ ਆਕਾਰ

Two-Sample T-Test (Independent Samples)

Equal Variances Assumed
t=xˉ1xˉ2sp1n1+1n2t = \frac{\bar{x}_1 - \bar{x}_2}{s_p \sqrt{\frac{1}{n_1} + \frac{1}{n_2}}}

Pooled standard deviation (sps_p):

sp=(n11)s12+(n21)s22n1+n22s_p = \sqrt{\frac{(n_1 - 1)s_1^2 + (n_2 - 1)s_2^2}{n_1 + n_2 - 2}}
Unequal Variances (Welch's T-Test)
t=xˉ1xˉ2s12n1+s22n2t = \frac{\bar{x}_1 - \bar{x}_2}{\sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}}

Paired T-Test

t=dˉsdnt = \frac{\bar{d}}{\frac{s_d}{\sqrt{n}}}
  • dˉ\bar{d}: ਫਰਕਾਂ ਦਾ ਮਾਧਿਆਨ
  • sds_d: ਫਰਕਾਂ ਦੀ ਮਿਆਰੀ ਵਿਸ਼ਮਤਾ
  • nn: ਜੋੜਾਂ ਦੀ ਗਿਣਤੀ

Degrees of Freedom

One-Sample and Paired T-Test:
df=n1df = n - 1
Two-Sample T-Test with Equal Variances:
df=n1+n22df = n_1 + n_2 - 2
Welch's T-Test:
df=(s12n1+s22n2)2(s12n1)2n11+(s22n2)2n21df = \frac{\left( \frac{s_1^2}{n_1} + \frac{s_2^2}{n_2} \right)^2}{\frac{\left( \frac{s_1^2}{n_1} \right)^2}{n_1 -1} + \frac{\left( \frac{s_2^2}{n_2} \right)^2}{n_2 -1}}

Calculation

ਕੈਲਕੁਲੇਟਰ ਹੇਠਾਂ ਦਿੱਤੇ ਕਦਮਾਂ ਨੂੰ ਪੂਰਾ ਕਰਦਾ ਹੈ:

  1. ਚੁਣੇ ਗਏ ਟੈਸਟ ਦੇ ਅਧਾਰ 'ਤੇ ਸਹੀ ਫਾਰਮੂਲੇ ਦੀ ਵਰਤੋਂ ਕਰਕੇ T-ਸਟੈਟਿਸਟਿਕ ਦੀ ਗਣਨਾ ਕਰੋ
  2. Degrees of Freedom (df) ਨੂੰ ਨਿਰਧਾਰਿਤ ਕਰੋ
  3. t-ਸਟੈਟਿਸਟਿਕ ਅਤੇ df ਦੇ ਅਨੁਸਾਰ P-Value ਦੀ ਗਣਨਾ ਕਰੋ:
    • ਸੰਭਾਵਨਾ ਲੱਭਣ ਲਈ t-ਵੰਡਨ ਦਾ ਉਪਯੋਗ ਕਰੋ।
  4. P-Value ਦੀ ਤੁਲਨਾ Significance Level (α\alpha) ਨਾਲ ਕਰੋ:
    • ਜੇ pαp \leq \alpha, ਤਾਂ null hypothesis ਨੂੰ ਰੱਦ ਕਰੋ
    • ਜੇ p>αp > \alpha, ਤਾਂ null hypothesis ਨੂੰ ਰੱਦ ਨਾ ਕਰੋ
  5. ਨਤੀਜਿਆਂ ਦੀ ਵਿਆਖਿਆ ਕਰੋ:
    • ਟੈਸਟ ਦੇ ਸੰਦਰਭ ਵਿੱਚ ਇੱਕ ਨਤੀਜਾ ਪ੍ਰਦਾਨ ਕਰੋ।

Use Cases

One-Sample T-Test

  • ਨਵੀਂ ਦਵਾਈ ਦੀ ਪ੍ਰਭਾਵਸ਼ੀਲਤਾ ਦੀ ਜਾਂਚ:
    • ਇਹ ਨਿਰਧਾਰਿਤ ਕਰਨਾ ਕਿ ਇੱਕ ਨਵੀਂ ਦਵਾਈ ਨਾਲ ਠੀਕ ਹੋਣ ਦਾ ਔਸਤ ਸਮਾਂ ਜਾਣੇ ਜਾਂਦੇ ਔਸਤ ਠੀਕ ਹੋਣ ਦੇ ਸਮੇਂ ਤੋਂ ਵੱਖਰਾ ਹੈ ਜਾਂ ਨਹੀਂ।
  • ਗੁਣਵੱਤਾ ਨਿਯੰਤਰਣ:
    • ਇਹ ਜਾਂਚਣਾ ਕਿ ਨਿਰਮਿਤ ਭਾਗਾਂ ਦੀ ਔਸਤ ਲੰਬਾਈ ਨਿਰਧਾਰਿਤ ਮਿਆਰ ਤੋਂ ਬਦਲਦੀ ਹੈ ਜਾਂ ਨਹੀਂ।

Two-Sample T-Test

  • ਮਾਰਕੀਟਿੰਗ ਵਿੱਚ A/B ਟੈਸਟਿੰਗ:
    • ਦੋ ਵੱਖ-ਵੱਖ ਵੈਬ ਪੰਨਾ ਡਿਜ਼ਾਈਨਾਂ ਵਿਚਕਾਰ ਰੂਪਾਂਤਰਣ ਦਰ ਦੀ ਤੁਲਨਾ ਕਰੋ।
  • ਸਿੱਖਿਆ ਸੰਸ਼ੋਧਨ:
    • ਦੋ ਪਾਠ ਪਧਤੀਆਂ ਵਿਚਕਾਰ ਟੈਸਟ ਸਕੋਰ ਵਿਚ ਫਰਕ ਦੀ ਜਾਂਚ ਕਰੋ।

Paired T-Test

  • ਪਹਿਲਾਂ ਅਤੇ ਬਾਅਦ ਦੇ ਅਧਿਐਨ:
    • ਇੱਕ ਡਾਇਟ ਪ੍ਰੋਗਰਾਮ ਤੋਂ ਪਹਿਲਾਂ ਅਤੇ ਬਾਅਦ ਵਜ਼ਨ ਘਟਾਉਣ ਦੀ ਜਾਂਚ ਕਰੋ।
  • ਮਿਲੇ ਹੋਏ ਵਿਸ਼ਾ:
    • ਇੱਕੋ ਵਿਸ਼ਾ ਨੂੰ ਦਵਾਈ ਦੇਣ ਤੋਂ ਪਹਿਲਾਂ ਅਤੇ ਬਾਅਦ ਬਲੱਡ ਪ੍ਰੈਸ਼ਰ ਮਾਪਾਂ ਦੀ ਤੁਲਨਾ ਕਰੋ।

Alternatives

ਜਦੋਂ ਕਿ t-tests ਸ਼ਕਤੀਸ਼ਾਲੀ ਹੁੰਦੇ ਹਨ, ਉਹਨਾਂ ਦੀਆਂ ਧਾਰਨਾਵਾਂ ਹਮੇਸ਼ਾ ਪੂਰੀਆਂ ਨਹੀਂ ਹੁੰਦੀਆਂ। ਵਿਕਲਪਾਂ ਵਿੱਚ ਸ਼ਾਮਲ ਹਨ:

  • Mann-Whitney U Test:
    • ਜਦੋਂ ਡੇਟਾ ਨਾਰਮਲ ਵੰਡ ਨਹੀਂ ਕਰਦਾ, ਤਾਂ ਦੋ-ਨਮੂਨਾ t-test ਦਾ ਗੈਰ-ਪੈਰਾਮੈਟਰਿਕ ਵਿਕਲਪ।
  • Wilcoxon Signed-Rank Test:
    • ਗੈਰ-ਪੈਰਾਮੈਟਰਿਕ ਸਮਕਾਲੀ t-test।
  • ANOVA (Analysis of Variance):
    • ਜਦੋਂ ਦੋ ਤੋਂ ਵੱਧ ਸਮੂਹਾਂ ਵਿਚਕਾਰ ਮਾਧਿਆਨ ਦੀ ਤੁਲਨਾ ਕਰਨ ਲਈ ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ।

History

t-test ਨੂੰ William Sealy Gosset ਦੁਆਰਾ 1908 ਵਿੱਚ ਵਿਕਸਿਤ ਕੀਤਾ ਗਿਆ ਸੀ, ਜਿਸਨੇ "Student" ਨਾਮਕ ਛਦਮ ਨਾਮ ਹੇਠਾਂ ਪ੍ਰਕਾਸ਼ਿਤ ਕੀਤਾ ਜਦੋਂ ਉਹ ਡਬਲਿਨ ਵਿੱਚ ਗਿਨੇਸ ਬ੍ਰਿਊਅਰੀ ਵਿੱਚ ਕੰਮ ਕਰ ਰਿਹਾ ਸੀ। ਇਹ ਟੈਸਟ ਸਟਾਊਟ ਦੀ ਗੁਣਵੱਤਾ ਦੀ ਨਿਗਰਾਨੀ ਕਰਨ ਲਈ ਨਮੂਨਾ ਬੈਚਾਂ ਦੀ ਸੰਗਤੀ ਨੂੰ ਨਿਰਧਾਰਿਤ ਕਰਨ ਲਈ ਡਿਜ਼ਾਈਨ ਕੀਤਾ ਗਿਆ ਸੀ। ਗੋਸੇਟ ਨੇ ਛਦਮ ਨਾਮ "Student" ਦੀ ਵਰਤੋਂ ਕੀਤੀ, ਜਿਸ ਨਾਲ "Student's t-test" ਦਾ ਸ਼ਬਦ ਬਣਿਆ।

ਸਮੇਂ ਦੇ ਨਾਲ, t-test ਅੰਕੜਾ ਵਿਸ਼ਲੇਸ਼ਣ ਵਿੱਚ ਇੱਕ ਕੋਰਨਰਸਟੋਨ ਬਣ ਗਿਆ, ਜੋ ਵੱਖ-ਵੱਖ ਵਿਗਿਆਨਕ ਵਿਸ਼ਿਆਂ ਵਿੱਚ ਵਿਸ਼ੇਸ਼ਤਾਪੂਰਕ ਹੈ। ਇਸਨੇ ਹੋਰ ਜਟਿਲ ਅੰਕੜਾ ਮੈਥਡਾਂ ਦੇ ਵਿਕਾਸ ਦੇ ਲਈ ਰਸਤਾ ਬਣਾਇਆ ਅਤੇ ਇਹ ਅੰਕੜਾ ਅਨੁਮਾਨ ਵਿੱਚ ਮੁੱਢਲੀ ਭੂਮਿਕਾ ਨਿਭਾਉਂਦਾ ਹੈ।

Examples

ਇੱਥੇ ਵੱਖ-ਵੱਖ ਪ੍ਰੋਗ੍ਰਾਮਿੰਗ ਭਾਸ਼ਾਵਾਂ ਵਿੱਚ One-Sample T-Test ਕਰਨ ਲਈ ਕੋਡ ਉਦਾਹਰਣ ਹਨ:

Excel

1' One-Sample T-Test in Excel VBA
2Sub OneSampleTTest()
3    Dim sampleData As Range
4    Set sampleData = Range("A1:A9") ' Replace with your data range
5    Dim hypothesizedMean As Double
6    hypothesizedMean = 50 ' Replace with your hypothesized mean
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

R

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

Python

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

JavaScript

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// Example usage:
11const sampleData = [51, 49, 52, 48, 50, 47, 53, 49, 51];
12const tStatistic = oneSampleTTest(sampleData, 50);
13console.log(`T-Statistic: ${tStatistic.toFixed(2)}`);
14

MATLAB

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

Java

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

C#

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

Go

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

Swift

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

PHP

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

Ruby

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

Rust

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

Numerical Example

Problem: ਇੱਕ ਨਿਰਮਾਤਾ ਦਾਅਵਾ ਕਰਦਾ ਹੈ ਕਿ ਇੱਕ ਬੈਟਰੀ ਦੀ ਔਸਤ ਉਮਰ 50 ਘੰਟੇ ਹੈ। ਇੱਕ ਉਪਭੋਗਤਾ ਸਮੂਹ 9 ਬੈਟਰੀਆਂ ਦੀ ਜਾਂਚ ਕਰਦਾ ਹੈ ਅਤੇ ਹੇਠਾਂ ਦਿੱਤੇ ਉਮਰਾਂ (ਘੰਟਿਆਂ ਵਿੱਚ) ਨੂੰ ਦਰਜ ਕਰਦਾ ਹੈ:

51, 49, 52, 48, 50, 47, 53, 49, 5151,\ 49,\ 52,\ 48,\ 50,\ 47,\ 53,\ 49,\ 51

ਕੀ ਇਹ 0.05 ਮਹੱਤਵਪੂਰਨਤਾ ਦੇ ਪੱਧਰ 'ਤੇ ਕੋਈ ਸਬੂਤ ਹੈ ਕਿ ਔਸਤ ਬੈਟਰੀ ਦੀ ਉਮਰ 50 ਘੰਟਿਆਂ ਤੋਂ ਵੱਖਰੀ ਹੈ?

Solution:

  1. Hypotheses ਦਾ ਬਿਆਨ ਕਰੋ:

    • Null Hypothesis (H0H_0): μ=50\mu = 50
    • Alternative Hypothesis (HaH_a): μ50\mu \neq 50
  2. Sample Mean (xˉ\bar{x}) ਦੀ ਗਣਨਾ ਕਰੋ:

    xˉ=51+49+52+48+50+47+53+49+519=50.00\bar{x} = \frac{51 + 49 + 52 + 48 + 50 + 47 + 53 + 49 + 51}{9} = 50.00
  3. Sample Standard Deviation (ss) ਦੀ ਗਣਨਾ ਕਰੋ:

    s=(xixˉ)2n1=2.0s = \sqrt{\frac{\sum (x_i - \bar{x})^2}{n - 1}} = 2.0
  4. T-ਸਟੈਟਿਸਟਿਕ ਦੀ ਗਣਨਾ ਕਰੋ:

    t=xˉμ0sn=50.00502.09=0.00t = \frac{\bar{x} - \mu_0}{\frac{s}{\sqrt{n}}} = \frac{50.00 - 50}{\frac{2.0}{\sqrt{9}}} = 0.00
  5. Degrees of Freedom:

    df=n1=8df = n - 1 = 8
  6. P-Value ਨੂੰ ਨਿਰਧਾਰਿਤ ਕਰੋ:

    • t=0.00t = 0.00 ਅਤੇ df=8df = 8 ਲਈ, p-value 1.00 ਹੈ।
  7. ਨਤੀਜਾ:

    • ਕਿਉਂਕਿ p-value (1.00) > α\alpha (0.05), ਅਸੀਂ null hypothesis ਨੂੰ ਰੱਦ ਨਹੀਂ ਕਰਦੇ
    • Interpretation: ਇਹ ਸਬੂਤ ਨਹੀਂ ਹੈ ਕਿ ਔਸਤ ਬੈਟਰੀ ਦੀ ਉਮਰ 50 ਘੰਟਿਆਂ ਤੋਂ ਵੱਖਰੀ ਹੈ।

References

  1. Gosset, W. S. (1908). "The Probable Error of a Mean". Biometrika, 6(1), 1–25. JSTOR.
  2. Student's t-test. Wikipedia. https://en.wikipedia.org/wiki/Student%27s_t-test
  3. GraphPad Statistics Guide: Understanding t-tests. Link
  4. Laerd Statistics: Independent t-test. Link

Additional Resources

  • Assumption Checks:
    • Shapiro-Wilk Test ਦਾ ਉਪਯੋਗ ਕਰੋ ਨਾਰਮਲਿਟੀ ਲਈ।
    • Levene's Test ਦਾ ਉਪਯੋਗ ਕਰੋ ਵੈਰੀਅੰਸ ਦੀ ਬਰਾਬਰੀ ਲਈ।
  • Software Tools:
    • SPSS, SAS, Stata, ਅਤੇ R ਅਗੇਤਰ ਅੰਕੜਾ ਵਿਸ਼ਲੇਸ਼ਣ ਲਈ।
  • Further Reading:
    • "Introduction to Statistical Learning" by Gareth James, Daniela Witten, Trevor Hastie, and Robert Tibshirani.
    • "Statistical Methods" by George W. Snedecor and William G. Cochran.