用MATLAB做T检验(ttest)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
⽤MATLAB做T检验(ttest)
t-检验:
t-检验,⼜称student‘s t-test,可以⽤于⽐较两组数据是否来⾃同⼀分布(可以⽤于⽐较两组数据的区分度),假设了数据的正态性,并反应两组数据的⽅差在统计上是否有显著差异。
matlab中提供了两种相同形式的⽅法来解决这⼀假设检验问题,分别为ttest⽅法和ttest2⽅法,两者的参数、返回值类型均相同,不同之处在于ttest⽅法做的是 One-sample and paired-sample t-test,⽽ttest2则是 Two-sample t-test with pooled or unpooled variance
estimate, performs an unpaired two-sample t-test。
但是这⾥⾄于paired和unpaired之间的区别我却还没搞清楚,只是在Student's t-test中看到了如下这样⼀段解释:
“Two-sample t-tests for a difference in mean involve independent samples, paired samples and overlapping samples. Paired t-tests are a form of , and have greater than unpaired tests when the paired units are similar with respect to "noise factors" that are independent of membership in the two groups being compared. In a different context, paired t-tests can be used to reduce the effects of in an .”
因此粗略认为paired是考虑了噪声因素的。
在同样的两组数据上分别⽤ttest和ttest2⽅法得出的结果进⾏⽐较,发现ttest返回的参数p普遍更⼩,且置信区间ci也更⼩。
最常⽤⽤法:
[H,P,CI]=ttest2(x,y);(⽤法上ttest和ttest2相同,完整形式为[H,P,CI, STATS]=ttest2(x,y, ALPHA);)
其中,x,y均为⾏向量(维度必须相同),各表⽰⼀组数据,ALPHA为可选参数,表⽰设置⼀个值作为t检验执⾏的显著性⽔平(performs the test at the significance level
(100*ALPHA)%),在不设置ALPHA的情况下默认ALPHA为0.05,即计算x和y在5%的显著性⽔平下是否来⾃同⼀分布(假设是否被接受)
结果:H=0,则表明零假设在5%的置信度下不被拒绝(根据当设置x=y时候,返回的H=0推断⽽来),即x,y在统计上可看做来⾃同⼀分布的数据;H=1,表明零假设被拒绝,即x,y在统计上认为是来⾃不同分布的数据,即有区分度。
P为⼀个概率,matlab help中的解释是“ 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.” 暂且认为表⽰判断值在真实分布中被观察到的概率(?不太懂)
CI为置信区间(confidence interval),表⽰“a 100*(1-ALPHA)% confidence interval for the true difference of population means”,即达到100* (1-ALPHA)%的置信度的数据区间(?)
应⽤:常与k-fold crossValidation(交叉验证)联⽤可以⽤于两种算法效果的⽐较,例如A1,A2两算法得出的结果分别为x,y,且从均值上看mean(x)>mean(y),则对[h,p,ci]=ttest2(x,y);当h=1时,表明可以从统计上断定算法A1的结果⼤于(?)A2的结果(即两组数据均值的⽐较是有意义的),h=0则表⽰不能根据平均值来断定两组数据的⼤⼩关系(因为区分度⼩)
临时学的,没经过太多测试,不⼀定对,还请⾼⼿指教。
参考资料:
经验+⾃⾝理解
matlab 7.11.0(R2010b)的帮助⽂档
wikipedia
本⽂中提到的pair应该如此理解:两个样本是有顺序的(⽐如两个病⼈24个整点的体温),两个同⼀序号(⽐如说6点)的体温为⼀个配对.⽽不配对的则不考虑这些,把24个体温放在⼀起看分布情况。