hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_univar_ttest_2normal (g07ca)

Purpose

nag_univar_ttest_2normal (g07ca) computes a tt-test statistic to test for a difference in means between two Normal populations, together with a confidence interval for the difference between the means.

Syntax

[t, df, prob, dl, du, ifail] = g07ca(tail, equal, nx, ny, xmean, ymean, xstd, ystd, clevel)
[t, df, prob, dl, du, ifail] = nag_univar_ttest_2normal(tail, equal, nx, ny, xmean, ymean, xstd, ystd, clevel)

Description

Consider two independent samples, denoted by XX and YY, of size nxnx and nyny drawn from two Normal populations with means μxμx and μyμy, and variances σx2σx2 and σy2σy2 respectively. Denote the sample means by xx- and yy- and the sample variances by sx2sx2 and sy2sy2 respectively.
nag_univar_ttest_2normal (g07ca) calculates a test statistic and its significance level to test the null hypothesis H0 : μx = μyH0:μx=μy, together with upper and lower confidence limits for μxμyμx-μy. The test used depends on whether or not the two population variances are assumed to be equal.
  1. It is assumed that the two variances are equal, that is σx2 = σy2σx2=σy2.
    The test used is the two sample tt-test. The test statistic tt is defined by;
    tobs = (xy)/(s×sqrt((1 / nx) + (1 / ny)))
    tobs=x--y- s(1/nx)+(1/ny)
    where
    s2 = ( (nx1) sx2 + (ny1) sy2 )/( nx + ny 2 )
    s2 = (nx-1) sx2 + (ny-1) sy2 nx + ny - 2
    is the pooled variance of the two samples.
    Under the null hypothesis H0H0 this test statistic has a tt-distribution with (nx + ny2)(nx+ny-2) degrees of freedom.
    The test of H0H0 is carried out against one of three possible alternatives;
    • H1 : μxμyH1:μxμy; the significance level, p = P(t|tobs|)p=P(t|tobs|), i.e., a two tailed probability.
    • H1 : μx > μyH1:μx>μy; the significance level, p = P(ttobs)p=P(ttobs), i.e., an upper tail probability.
    • H1 : μx < μyH1:μx<μy; the significance level, p = P(ttobs)p=P(ttobs), i.e., a lower tail probability.
    Upper and lower 100(1α)%100(1-α)% confidence limits for μxμyμx-μy are calculated as:
    (xy) ± t1α / 2s×sqrt((1 / nx) + (1 / ny)).
    (x--y-)±t1-α/2s(1/nx)+(1/ny).
    where t1α / 2t1-α/2 is the 100(1α / 2)100(1-α/2) percentage point of the tt-distribution with (nx + ny2nx+ny-2) degrees of freedom.
  2. It is not assumed that the two variances are equal.
    If the population variances are not equal the usual two sample tt-statistic no longer has a tt-distribution and an approximate test is used.
    This problem is often referred to as the Behrens–Fisher problem, see Kendall and Stuart (1969). The test used here is based on Satterthwaites procedure. To test the null hypothesis the test statistic tt is used where
    tobs = (xy)/(se(xy))
    tobs=x--y- se(x--y-)
    where se(xy) = sqrt((sx2)/(nx) + (sy2)/(ny))se(x--y-)= sx2nx+ sy2ny.
    A tt-distribution with ff degrees of freedom is used to approximate the distribution of tt where
    f = ( se(xy)4 )/( ((sx2 / nx)2)/((nx1)) + ((sy2 / ny)2)/((ny1)) ) .
    f = se ( x- - y- ) 4 ( sx2 / nx ) 2 (nx-1) + ( sy2 / ny ) 2 (ny-1) .
    The test of H0H0 is carried out against one of the three alternative hypotheses described above, replacing tt by tt and tobstobs by tobstobs.
    Upper and lower 100(1α)%100(1-α)% confidence limits for μxμyμx-μy are calculated as:
    (xy) ± t1α / 2se(xy).
    (x--y-)±t1-α/2se(x-y-).
    where t1α / 2t1-α/2 is the 100(1α / 2)100(1-α/2) percentage point of the tt-distribution with ff degrees of freedom.

References

Johnson M G and Kotz A (1969) The Encyclopedia of Statistics 2 Griffin
Kendall M G and Stuart A (1969) The Advanced Theory of Statistics (Volume 1) (3rd Edition) Griffin
Snedecor G W and Cochran W G (1967) Statistical Methods Iowa State University Press

Parameters

Compulsory Input Parameters

1:     tail – string (length ≥ 1)
Indicates which tail probability is to be calculated, and thus which alternative hypothesis is to be used.
tail = 'T'tail='T'
The two tail probability, i.e., H1 : μxμyH1:μxμy.
tail = 'U'tail='U'
The upper tail probability, i.e., H1 : μx > μyH1:μx>μy.
tail = 'L'tail='L'
The lower tail probability, i.e., H1 : μx < μyH1:μx<μy.
Constraint: tail = 'T'tail='T', 'U''U' or 'L''L'.
2:     equal – string (length ≥ 1)
Indicates whether the population variances are assumed to be equal or not.
equal = 'E'equal='E'
The population variances are assumed to be equal, that is σx2 = σy2σx2=σy2.
equal = 'U'equal='U'
The population variances are not assumed to be equal.
Constraint: equal = 'E'equal='E' or 'U''U'.
3:     nx – int64int32nag_int scalar
nxnx, the size of the XX sample.
Constraint: nx2nx2.
4:     ny – int64int32nag_int scalar
nyny, the size of the YY sample.
Constraint: ny2ny2.
5:     xmean – double scalar
xx-, the mean of the XX sample.
6:     ymean – double scalar
yy-, the mean of the YY sample.
7:     xstd – double scalar
sxsx, the standard deviation of the XX sample.
Constraint: xstd > 0.0xstd>0.0.
8:     ystd – double scalar
sysy, the standard deviation of the YY sample.
Constraint: ystd > 0.0ystd>0.0.
9:     clevel – double scalar
The confidence level, 1α1-α, for the specified tail. For example clevel = 0.95clevel=0.95 will give a 95%95% confidence interval.
Constraint: 0.0 < clevel < 1.00.0<clevel<1.0.

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     t – double scalar
Contains the test statistic, tobstobs or tobstobs.
2:     df – double scalar
Contains the degrees of freedom for the test statistic.
3:     prob – double scalar
Contains the significance level, that is the tail probability, pp, as defined by tail.
4:     dl – double scalar
Contains the lower confidence limit for μxμyμx-μy.
5:     du – double scalar
Contains the upper confidence limit for μxμyμx-μy.
6:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,tail'T'tail'T', 'U''U' or 'L''L',
orequal'E'equal'E' or 'U''U',
ornx < 2nx<2,
orny < 2ny<2,
orxstd0.0xstd0.0,
orystd0.0ystd0.0,
orclevel0.0clevel0.0,
orclevel1.0clevel1.0.

Accuracy

The computed probability and the confidence limits should be accurate to approximately five significant figures.

Further Comments

The sample means and standard deviations can be computed using nag_stat_summary_onevar (g01at).

Example

function nag_univar_ttest_2normal_example
tail = 'Two';
equal = 'Equal';
nx = int64(4);
ny = int64(8);
xmean = 25;
ymean = 21;
xstd = 0.8185;
ystd = 4.2083;
clevel = 0.95;
[t, df, prob, dl, du, ifail] = ...
    nag_univar_ttest_2normal(tail, equal, nx, ny, xmean, ymean, xstd, ystd, clevel)
 

t =

    1.8403


df =

    10


prob =

    0.0955


dl =

   -0.8429


du =

    8.8429


ifail =

                    0


function g07ca_example
tail = 'Two';
equal = 'Equal';
nx = int64(4);
ny = int64(8);
xmean = 25;
ymean = 21;
xstd = 0.8185;
ystd = 4.2083;
clevel = 0.95;
[t, df, prob, dl, du, ifail] = ...
    g07ca(tail, equal, nx, ny, xmean, ymean, xstd, ystd, clevel)
 

t =

    1.8403


df =

    10


prob =

    0.0955


dl =

   -0.8429


du =

    8.8429


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013