加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

两独立样本T检验的matlab命令ttest2

(2008-12-30 17:24:52)
标签:

杂谈

分类: matlab学习

ttest2

Hypothesis testing for the difference in means of two samples Syntax[h,significance,ci] = ttest2(x,y)
[h,significance,ci] = ttest2(x,y,alpha)
[h,significance,ci,stats] = ttest2(x,y,alpha)
[...] = ttest2(x,y,alpha,tail)
h = ttest2(x,y,alpha,tail,'unequal')

Descriptionh = ttest2(x,y) performs a t-test to determine whether two samples from a normal distribution (in x and y) could have the same mean when the standard deviations are unknown but assumed equal. The vectors x and y can have different lengths. The result, h, is 1 if you can reject the null hypothesis that the means are equal at the 0.05 significance level and 0 otherwise. significance is the p-value associated with the t-statistic  where s is the pooled sample standard deviation and n and m are the numbers of observations in the x and y samples. significance is the probability that the observed value of T could be as large or larger by chance under the null hypothesis that the mean of x is equal to the mean of y. ci is a 95% confidence interval for the true difference in means.

[h,significance,ci] = ttest2(x,y,alpha) gives control of the significance level alpha. For example if alpha = 0.01, and the result, h, is 1, you can reject the null hypothesis at the significance level 0.01. ci in this case is a 100(1 - alpha)% confidence interval for the true difference in means.

[h,significance,ci,stats] = ttest2(x,y,alpha) returns a structure stats with the following three fields: tstat -- Value of the test statistic df -- Degrees of freedom of the test 'sd' -- Pooled estimate of the population standard deviation in the equal variance case, or a vector containing the unpooled estimates of the population standard deviations in the unequal variance case

[...] = ttest2(x,y,alpha,tail) allows specification of one- or two-tailed tests, where tail is a flag that specifies one of three alternative hypotheses: tail = 'both' specifies the alternative  (default) tail = 'right' specifies the alternative  tail = 'left' specifies the alternative  h = ttest2(x,y,alpha,tail,'unequal') performs the test assuming that the two samples come from normal distributions with unknown and possibly unequal variances. This is known as the Behrens-Fisher problem. ttest2 uses Satterthwaite's approximation for the effective degrees of freedom. ExamplesThis example generates 100 normal random numbers with theoretical mean 0 and standard deviation 1. you then generate 100 more normal random numbers with theoretical mean 1/2 and standard deviation 1. The observed means and standard deviations are different from their theoretical values, of course. you test the hypothesis that there is no true difference between the two means. Notice that the true difference is only one half of the standard deviation of the individual observations, so you are trying to detect a signal that is only one half the size of the inherent noise in the process.

 x = normrnd(0,1,100,1);
y = normrnd(0.5,1,100,1);
[h,significance,ci] = ttest2(x,y)
h =
    1
significance =
    0.0017
ci =
   -0.7352   -0.1720
The result h = 1 means that you can reject the null hypothesis. The significance is 0.0017, which means that by chance you would have observed values of t more extreme than the one in this example in only 17 of 10,000 similar experiments! A 95% confidence interval on the mean is [-0.7352 -0.1720], which includes the theoretical (and hypothesized) difference of -0.5.

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有