热线电话:13121318867

登录
首页精彩阅读数据分析之独立样本的T-Test分析_数据分析师
数据分析之独立样本的T-Test分析_数据分析师
2014-11-04
收藏

数据分析之独立样本的T-Test分析

比较两个独立样本数据之间是否有显著性差异,将实验数据与标准数据对比,查看

实验结果是否符合预期。T-Test在生物数据分析,实验数据效果验证中很常见的数

据处理方法。- T-table查找表

独立样本T-test条件:

1.      每个样本相互独立没有影响

2.      样本大致符合正态分布曲线

3.      具有同方差异性

单侧检验(one-tail Test)与双侧检验(Two-Tail Test)

20140420223257859

基本步骤:

1.双侧检验, 条件声明  alpha值设置为0.05

根据t-table, alpha = 0.05, df = 38时, 对于t-table的值为2.0244

20140420223336734

2. 计算自由度(Degree of Freedom)

Df = (样本1的总数 + 样本2的总数)- 2

3. 声明决策规则

如果计算出来的结果t-value的结果大于2.0244或者小于-2.0244则拒绝

4. 计算T-test统计值

20140420223400687

5. 得出结论

如果计算结果在双侧区间之内,说明两组样本之间没有显著差异。

可重复样本的T-Test计算

同样一组数据在不同的条件下得到结果进行比对,发现是否有显著性差异,最常见

的对一个人在饮酒与不饮酒条件下驾驶车辆测试,很容易得出酒精对驾驶员有显著

影响

算法实现:

对独立样本的T-Test计算最重要的是计算各自的方差与自由度df1与df2

20140420223438750

对可重复样本的对比t-test计算

20140420223457937

程序实现:

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
package com.gloomyfish.data.mining.analysis;
         
public class TTestAnalysisAlg {
         
    private double alpahValue = 0.05; // default
    private boolean dependency = false; // default
         
    public TTestAnalysisAlg() {
        System.out.println("t-test algorithm");
    }
         
    public double getAlpahValue() {
        return alpahValue;
    }
         
    public void setAlpahValue(double alpahValue) {
        this.alpahValue = alpahValue;
    }
         
    public boolean isDependency() {
        return dependency;
    }
         
    public void setDependency(boolean dependency) {
        this.dependency = dependency;
    }
         
    public double analysis(double[] data1, double[] data2) {
        double tValue = 0;
        if (dependency) {
            // Repeated Measures T-test.
            // Uses the same sample of subjects measured on two different
            // occasions
            double diffSum = 0.0;
            double diffMean = 0.0;
            int size = Math.min(data1.length, data2.length);
            double[] diff = new double[size];
            for(int i=0; i
            {
                diff[i] = data2[i] -data1[i];
                diffSum += data2[i] -data1[i];
            }
            diffMean = diffSum / size;
            diffSum = 0.0;
            for(int i=0; i
            {
                diffSum += Math.pow((diff[i] -diffMean), 2);
            }
            double diffSD = Math.sqrt(diffSum / (size - 1.0));
            double diffSE = diffSD / Math.sqrt(size);
            tValue = diffMean / diffSE;
         
        } else {
         
            double means1 = 0;
            double means2 = 0;
            double sum1 = 0;
            double sum2 = 0;
         
            // calcuate means
            for (int i = 0; i < data1.length; i++) {
                sum1 += data1[i];
            }
         
            for (int i = 0; i < data2.length; i++) {
                sum2 += data2[i];
            }
         
            means1 = sum1 / data1.length;
            means2 = sum2 / data2.length;
         
            // calculate SD (Standard Deviation)
            sum1 = 0.0;
            sum2 = 0.0;
         
            for (int i = 0; i < data1.length; i++) {
                sum1 += Math.pow((means1 - data1[i]), 2);
            }
         
            for (int i = 0; i < data2.length; i++) {
                sum2 += Math.pow((means2 - data2[i]), 2);
            }
         
            double sd1 = Math.sqrt(sum1 / (data1.length - 1.0));
            double sd2 = Math.sqrt(sum2 / (data2.length - 1.0));
         
            // calculate SE (Standard Error)
            double se1 = sd1 / Math.sqrt(data1.length);
            double se2 = sd2 / Math.sqrt(data2.length);
            System.out.println("Data Sample one - > Means :" + means1
                    + " SD : " + sd1 + " SE : " + se1);
            System.out.println("Data Sample two - > Means :" + means2
                    + " SD : " + sd2 + " SE : " + se2);
         

数据分析咨询请扫描二维码

最新资讯
更多
客服在线
立即咨询