NAG CL Interface
g07cac (ttest_​2normal)

Settings help

CL Name Style:


1 Purpose

g07cac computes a t -test statistic to test for a difference in means between two Normal populations, together with a confidence interval for the difference between the means.

2 Specification

#include <nag.h>
void  g07cac (Nag_TailProbability tail, Nag_PopVar equal, Integer nx, Integer ny, double xmean, double ymean, double xstd, double ystd, double clevel, double *t, double *df, double *prob, double *dl, double *du, NagError *fail)
The function may be called by the names: g07cac, nag_univar_ttest_2normal or nag_2_sample_t_test.

3 Description

Consider two independent samples, denoted by X and Y , of size n x and n y drawn from two Normal populations with means μ x and μ y , and variances σ x 2 and σ y 2 respectively. Denote the sample means by x ¯ and y ¯ and the sample variances by s x 2 and s y 2 respectively.
g07cac calculates a test statistic and its significance level to test the null hypothesis H 0 : μ x = μ y , together with upper and lower confidence limits for μ x - μ y . The test used depends on whether or not the two population variances are assumed to be equal.
  1. 1.It is assumed that the two variances are equal, that is σ x 2 = σ y 2 .
    The test used is the two sample t -test. The test statistic t is defined by;
    t obs = x ¯ - y ¯ s (1/ n x ) + (1/ n y )  
    where s 2 = ( n x -1) s x 2 + ( n y -1) s y 2 n x + n y - 2 is the pooled variance of the two samples.
    Under the null hypothesis H 0 this test statistic has a t -distribution with ( n x + n y -2) degrees of freedom.
    The test of H 0 is carried out against one of three possible alternatives:
    1. (i) H 1 : μ x μ y ; the significance level, p = P (t| t obs |) , i.e., a two tailed probability.
    2. (ii) H 1 : μ x > μ y ; the significance level, p = P (t t obs ) , i.e., an upper tail probability.
    3. (iii) H 1 : μ x < μ y ; the significance level, p = P (t t obs ) , i.e., a lower tail probability.
    Upper and lower 100 (1-α) % confidence limits for μ x - μ y are calculated as:
    ( x ¯- y ¯) ± t 1 - α / 2 s (1/ n x ) + (1/ n y ) ,  
    where t 1 - α / 2 is the 100 (1-α/2) percentage point of the t -distribution with ( n x + n y -2) degrees of freedom.
  2. 2.It is not assumed that the two variances are equal.
    If the population variances are not equal the usual two sample t -statistic no longer has a t -distribution and an approximate test is used.
    This problem is often referred to as the Behrens–Fisher problem, see Kendall and Stuart (1979). The test used here is based on Satterthwaites procedure. To test the null hypothesis the test statistic t is used where
    t obs = x ¯ - y ¯ se( x ¯- y ¯)  
    where se( x ¯- y ¯) = s x 2 n x + s y 2 n y .
    A t -distribution with f degrees of freedom is used to approximate the distribution of t where
    f = se ( x ¯- y ¯) 4 s x 2 / n x 2 ( n x -1) + s y 2 / n y 2 ( n y -1) .  
    The test of H 0 is carried out against one of the three alternative hypotheses described above, replacing t × t and t obs × t obs .
    Upper and lower 100 (1-α) % confidence limits for μ x - μ y are calculated as:
    ( x ¯- y ¯) ± t 1 - α / 2 se(x- y ¯) .  
    where t 1 - α / 2 is the 100 (1-α/2) percentage point of the t -distribution with f degrees of freedom.

4 References

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

5 Arguments

1: tail Nag_TailProbability Input
On entry: indicates which tail probability is to be calculated, and thus which alternative hypothesis is to be used.
tail=Nag_TwoTail
The two tail probability, i.e., H 1 : μ x μ y .
tail=Nag_UpperTail
The upper tail probability, i.e., H 1 : μ x > μ y .
tail=Nag_LowerTail
The lower tail probability, i.e., H 1 : μ x < μ y .
Constraint: tail=Nag_UpperTail, Nag_LowerTail or Nag_TwoTail.
2: equal Nag_PopVar Input
On entry: indicates whether the population variances are assumed to be equal or not.
equal=Nag_PopVarEqual
The population variances are assumed to be equal, that is σ x 2 = σ y 2 .
equal=Nag_PopVarNotEqual
The population variances are not assumed to be equal.
Constraint: equal=Nag_PopVarEqual or Nag_PopVarNotEqual.
3: nx Integer Input
On entry: the size of the X sample, n x .
Constraint: nx2 .
4: ny Integer Input
On entry: the size of the Y sample, n y .
Constraint: ny2 .
5: xmean double Input
On entry: the mean of the X sample, x ¯ .
6: ymean double Input
On entry: the mean of the Y sample, y ¯ .
7: xstd double Input
On entry: the standard deviation of the X sample, s x .
Constraint: xstd>0.0 .
8: ystd double Input
On entry: the standard deviation of the Y sample, s y .
Constraint: ystd>0.0 .
9: clevel double Input
On entry: the confidence level, 1-α , for the specified tail. For example clevel=0.95 will give a 95% confidence interval.
Constraint: 0.0 < clevel < 1.0 .
10: t double * Output
On exit: contains the test statistic, t obs or t obs .
11: df double * Output
On exit: contains the degrees of freedom for the test statistic.
12: prob double * Output
On exit: contains the significance level, that is the tail probability, p , as defined by tail.
13: dl double * Output
On exit: contains the lower confidence limit for μ x - μ y .
14: du double * Output
On exit: contains the upper confidence limit for μ x - μ y .
15: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_BAD_PARAM
On entry, argument equal had an illegal value.
On entry, argument tail had an illegal value.
NE_INT_ARG_LT
On entry, nx=value.
Constraint: nx2.
On entry, ny=value.
Constraint: ny2.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_REAL_ARG_GE
On entry, clevel must not be greater than or equal to 1.0: clevel=value .
NE_REAL_ARG_LE
On entry, clevel must not be less than or equal to 0.0: clevel=value .
On entry, xstd must not be less than or equal to 0.0: xstd=value .
On entry, ystd must not be less than or equal to 0.0: ystd=value .

7 Accuracy

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

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
g07cac is not threaded in any implementation.

9 Further Comments

The sample means and standard deviations can be computed using g01atc.

10 Example

The following example program reads the two sample sizes and the sample means and standard deviations for two independent samples. The data is taken from page 116 of Snedecor and Cochran (1967) from a test to compare two methods of estimating the concentration of a chemical in a vat. A test of the equality of the means is carried out first assuming that the two population variances are equal and then making no assumption about the equality of the population variances.

10.1 Program Text

Program Text (g07cace.c)

10.2 Program Data

Program Data (g07cace.d)

10.3 Program Results

Program Results (g07cace.r)