MATLAB ttest和ttest2的区别

Author:ZHANG TAO
Data:2018.4.3

student t-test假设检验

χ2 χ 2 − distribution

X1,X2,...,Xn X 1 , X 2 , . . . , X n 是来自总体 N(0,1) N ( 0 , 1 ) 的样本,则称统计量

χ2=X21+X22+...+X2n χ 2 = X 1 2 + X 2 2 + . . . + X n 2

服从自由度为n的卡方分布,记为 χ2(n) χ 2 ( n )

t t − distribution

XN(0,1),Yχ2(n) X ∼ N ( 0 , 1 ) , Y ∼ χ 2 ( n ) ,并且X和Y独立,则称随机变量

t=XY/n t = X Y / n

服从自由度为n的t分布,记作 tt(n) t ∼ t ( n )

这里写图片描述

t-test

One-sample

样本方差 σ2 σ 2 未知,关于 μ μ 的检验(t检验)

构造

t=X¯¯¯¯μ0S/nt(n1) t = X ¯ − μ 0 S / n ∼ t ( n − 1 )

作为检测统计量,如果观测值过大就拒绝 H0 H 0

P{H0H0}=Pμ0{|X¯¯¯¯μ0S/n|k}=α P { 当 H 0 为 真 时 拒 绝 H 0 } = P μ 0 { | X ¯ − μ 0 S / n | ≥ k } = α

如图1可知, H0 H 0 为真时,监测统计量位于阴影部分的概率时 α α (显著性水平,特别小的值),所以如果此事发生(也就是检测统计量的值位于阴影处时),就可以认为原假设时错误的,而拒绝 H0 H 0

这里写图片描述

问题1:matlab中的ttest返回的p_value表示的含义?

returns the p-value, i.e., the probability of observing the given result, or one more extreme, 
by chance if the null hypothesis is true.  Small values of P cast doubt on the validity of the 
null hypothesis.

形象的表示就是如图二所示,观测变量的值求出以后,红的区域的值就是P的value,而只有 Pvalue<α P v a l u e < α 时才会拒绝原假设。

假设检验的难点在于如何通过已知量构造已知分布的检验统计量

Paired sample

一般,假设有n对相互独立的观察结果: (X1,Y1),...,(Xn,Yn), ( X 1 , Y 1 ) , . . . , ( X n , Y n ) , D1=X1Y1,D2=X2Y2,...,Dn=XnYn, D 1 = X 1 − Y 1 , D 2 = X 2 − Y 2 , . . . , D n = X n − Y n , D1,D2,...,Dn D 1 , D 2 , . . . , D n 相互独立。又因为 D1,D2,...,Dn D 1 , D 2 , . . . , D n 是由同一个因素引起的,所以可以认为他们服从同一个分布。故:

H0:μD=0,H1:μD0 H 0 : μ D = 0 , H 1 : μ D ≠ 0

则检测统计量为:
t=|d¯¯¯sD/n|t(n1) t = | d ¯ s D / n | ∼ t ( n − 1 )

matlab实现使用ttest:

ttest  One-sample and paired-sample t-test.

Unpaired(Independent) sample

检验具有相同方差的两正态总体均值差的假设.假设 X1,X2...Xn1 X 1 , X 2 . . . X n 1 是来自分布 N(μ1,σ2) N ( μ 1 , σ 2 ) 的样本, Y1,Y2,...,Yn2 Y 1 , Y 2 , . . . , Y n 2 是来自正态总体 N(μ2,σ2) N ( μ 2 , σ 2 ) ,且设两样本独立。

H0:μ1μ2=σ,H1:μ1μ2σ H 0 : μ 1 − μ 2 = σ , H 1 : μ 1 − μ 2 ≠ σ

t=(X¯¯¯¯Y¯¯¯¯)σSw1n1+1n2,S2w=(n11)S21+(n21)S22n1+n22 t = ( X ¯ − Y ¯ ) − σ S w 1 n 1 + 1 n 2 , 其 中 S w 2 = ( n 1 − 1 ) S 1 2 + ( n 2 − 1 ) S 2 2 n 1 + n 2 − 2

易知:
tt(n1+n22) t ∼ t ( n 1 + n 2 − 2 )

matlab中实现时使用ttest2

ttest2默认是X和Y的方差时相等的,可以通过Vartype:unequal改成方差不相等。

'equal' Conduct test using the assumption that x and y are from normal distributions with unknown but equal variances.
'unequal'   Conduct test using the assumption that x and y are from normal distributions with unknown and unequal variances. This is called the Behrens-Fisher problem. ttest2 uses Satterthwaite's approximation for the effective degrees of freedom.
Vartype must be a single variance type, even when x is a matrix or a multidimensional array.

Example: 'Vartype','unequal'

不相等的情况下被称为Behrens-Fisher problem,优化方式可参看wiki

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值