Main Content

ttest2

两个样本t-测试

Description

例子

H= ttest2(X,,,,yreturns a test decision for the null hypothesis that the data in vectorsXandy使用平等平等和相等但未知方差的独立随机样本,使用two-samplet-测试。另一种假设是数据中的数据Xandy来自具有不平等手段的人口。结果His1如果该测试在5%的显着性水平上拒绝零假设,并且0否则。

例子

H= ttest2(X,,,,y,,,,姓名,,,,Valuereturns a test decision for the two-samplet- 通过一个或多个名称值对参数指定的其他选项。例如,您可以在不假设相等方差的情况下更改显着性水平或进行测试。

例子

[[H,,,,p] = ttest2(___还返回p-价值,p在测试中,使用上一个语法中的任何输入参数。

例子

[[H,,,,p,,,,CI,,,,统计] = ttest2(___还返回人口平均值差异的置信区间,CI和结构统计containing information about the test statistic.

Examples

collapse all

Load the data set. Create vectors containing the first and second columns of the data matrix to represent students’ grades on two exams.

加载examgradesx =级别(:,1);y =等级(:,2);

测试两个数据样本来自均值相等的人群的零假设。

[[H,,,,p,,,,CI,,,,stats] = ttest2(x,y)
h = 0
p = 0.9867
CI=2×1-1.9438 1.9771
统计=struct with fields:TSTAT:0.0167 DF:238 SD:7.7084

返回的值h = 0表示这ttest2does not reject the null hypothesis at the default 5% significance level.

Load the data set. Create vectors containing the first and second columns of the data matrix to represent students’ grades on two exams.

加载examgradesx =级别(:,1);y =等级(:,2);

Test the null hypothesis that the two data vectors are from populations with equal means, without assuming that the populations also have equal variances.

[h,p] = ttest2(X,,,,y,,,,'vartype',,,,'不等'
h = 0
p = 0.9867

返回的值h = 0表示这ttest2即使不假定相等的差异,也不会在默认的5%显着性水平下拒绝零假设。

Input Arguments

collapse all

示例数据,指定为矢量,矩阵或多维数组。ttest2零食值为缺少数据并忽略它们。

  • IfXandy被指定为向量,它们不需要相同的长度。

  • IfXandyare specified as matrices, they must have the same number of columns.ttest2执行单独t-测试along each column and returns a vector of results.

  • IfXandyare specified as多维阵列,除了所有人之外,它们都必须具有相同的大小第一个nonsingleton维度

数据类型:单身的|double

示例数据,指定为矢量,矩阵或多维数组。ttest2零食值为缺少数据并忽略它们。

  • IfXandy被指定为向量,它们不需要相同的长度。

  • IfXandyare specified as matrices, they must have the same number of columns.ttest2执行单独t-测试along each column and returns a vector of results.

  • IfXandyare specified as多维阵列,除了所有人之外,它们都必须具有相同的大小第一个nonsingleton维度ttest2works along the first nonsingleton dimension.

数据类型:单身的|double

名称值参数

Specify optional pairs of arguments asname1 = value1,...,namen = valuen,,,,在哪里姓名是参数名称和Valueis the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

在R2021a之前,请使用逗号分隔每个名称和值,并附上姓名用引号。

Example:'尾巴',,,,'正确的',,,,'Alpha',0.01,'Vartype','unequal'specifies a right-tailed test at the 1% significance level, and does not assume thatXandy人口差异相等。

显着性水平of the hypothesis test, specified as the comma-separated pair consisting of'Alpha'以及范围内的标量值(0,1)。

Example:'Alpha',0.01

数据类型:单身的|double

输入矩阵的尺寸,该矩阵测试均值,指定为逗号分隔对'Dim'和积极的整数价值。例如,指定“昏暗”,1测试列的含义,而“昏暗”,2tests the row means.

Example:“昏暗”,2

数据类型:单身的|double

评估的替代假设类型,指定为逗号分隔对'尾巴'and one of:

  • '两个都'-Test against the alternative hypothesis that the population means are not equal.

  • '正确的'-Test against the alternative hypothesis that the population mean ofX大于人口的平均值y

  • 'left'-Test against the alternative hypothesis that the population mean ofXis less than the population mean ofy

ttest2tests the null hypothesis that the population means are equal against the specified alternative hypothesis.

Example:'尾巴',,,,'正确的'

方差类型,指定为逗号分隔对,由'vartype'以及以下内容之一。

'equal' Conduct test using the assumption thatXandy来自具有未知但相等方差的正常分布。
'不等' Conduct test using the assumption thatXandyare from normal distributions with unknown and unequal variances. This is called the Behrens-Fisher problem.ttest2将萨特沃特的近似值用于有效的自由度。

Vartype即使X是矩阵或多维阵列。

Example:“ vartype”,“不平等”

输出参数

collapse all

假设测试结果,返回1或者0

  • IfH=1,,,,tHis indicates the rejection of the null hypothesis at theAlphasignificance level.

  • IfH=0,这表明未能拒绝在Alphasignificance level.

p-价值of the test, returned as a scalar value in the range [0,1].p观察测试统计量的概率比原假设下观察到的值更为极端或更极端。小值pcast doubt on the validity of the null hypothesis.

Confidence interval for the difference in population means ofXandy,,,,returned as a two-element vector containing the lower and upper boundaries of the 100 × (1 –Alpha)% confidence interval.

两样本的测试统计数据t-测试,,,,returned as a structure containing the following:

  • TSTAT-Value of the test statistic.

  • DF-Degrees of freedom of the test.

  • SD-Pooled estimate of the population standard deviation (for the equal variance case) or a vector containing the unpooled estimates of the population standard deviations (for the unequal variance case).

更多关于

collapse all

两个样本t-测试

两个样本t- 检验是一个参数测试,比较了两个独立数据样本的位置参数。

The test statistic is

t = X - y s X 2 n + s y 2 m ,,,,

在哪里 X and y 是样本手段,sXandsyare the sample standard deviations, andnandm是样本量。

In the case where it is assumed that the two data samples are from populations with equal variances, the test statistic under the null hypothesis has Student'st分配n+m– 2自由度和样本标准偏差被合并的标准偏差所取代

s = (( n - 1 s X 2 + (( m - 1 s y 2 n + m - 2

In the case where it is not assumed that the two data samples are from populations with equal variances, the test statistic under the null hypothesis has an approximate Student'stSatterthwaite的近似值给出了许多自由度的分布。该测试有时称为韦尔奇t-测试。

Multidimensional Array

多维阵列具有两个以上的维度。例如,如果X是一个1 x-3 x-4阵列,然后Xis a three-dimensional array.

第一个nonsingleton维度

The first nonsingleton dimension is the first dimension of an array whose size is not equal to 1. For example, ifX是一个1 x-2-by-3-by-4阵列,那么第二维是第一个非元素维度。X

Tips

  • Usesampsizepwr计算:

    • 对应于指定的功率和参数值的样本大小;

    • 给定真实参数值,对于特定样本量获得的功率;

    • 参数值可通过指定的样本量和功率检测到。

扩展功能

版本历史记录

Introduced before R2006a

也可以看看

||