《用MATLAB做T检验=.docx》由会员分享,可在线阅读,更多相关《用MATLAB做T检验=.docx(3页珍藏版)》请在三一办公上搜索。
1、用MATLAB做T检验=用MATLAB做T检验 t-检验: t-检验,又称students t-test,可以用于比较两组数据是否来自同一分布,假设了数据的正态性,并反应两组数据的方差在统计上是否有显著差异。 matlab中提供了两种相同形式的方法来解决这一假设检验问题,分别为ttest方法和ttest2方法,两者的参数、返回值类型均相同,不同之处在于ttest方法做的是 One-sample and paired-sample t-test,而ttest2则是 Two-sample t-test with pooled or unpooled variance estimate, perfo
2、rms an unpaired two-sample t-test。但是这里至于paired和unpaired之间的区别我却还没搞清楚,只是在Students t-test中看到了如下这样一段解释: “Two-sample t-tests for a difference in mean involve independent samples, paired samples and overlapping samples. Pairedt-tests are a form of blocking, and have greater power than unpaired tests when
3、the paired units are similar with respect to noise factors that are independent of membership in the two groups being compared.8 In a different context, paired t-tests can be used to reduce the effects ofconfounding factors in an observational study.” 因此粗略认为paired是考虑了噪声因素的。 在同样的两组数据上分别用ttest和ttest2方
4、法得出的结果进行比较,发现ttest返回的参数p普遍更小,且置信区间ci也更小。 最常用用法: H,P,CI=ttest2(x,y); 其中,x,y均为行向量,各表示一组数据,ALPHA为可选参数,表示设置一个值作为t检验执行的显著性水平,在不设置ALPHA的情况下默认ALPHA为0.05,即计算x和y在5%的显著性水平下是否来自同一分布(假设是否被接受) 结果:H=0,则表明零假设在5%的置信度下不被拒绝,即x,y在统计上可看做来自同一分布的数据;H=1,表明零假设被拒绝,即x,y在统计上认为是来自不同分布的数据,即有区分度。 P为一个概率,matlab help中的解释是“ the p-v
5、alue, 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则表示不能根据平均值来断定两组数据的大小关系 临时学的,没经过太多测试,不一定对,还请高手指教。