NAG Library Routine Document
g07caf
(ttest_2normal)
1
Purpose
g07caf computes a -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
Fortran Interface
Subroutine g07caf ( |
tail,
equal,
nx,
ny,
xmean,
ymean,
xstd,
ystd,
clevel,
t,
df,
prob,
dl,
du,
ifail) |
Integer, Intent (In) | :: |
nx,
ny | Integer, Intent (Inout) | :: |
ifail | Real (Kind=nag_wp), Intent (In) | :: |
xmean,
ymean,
xstd,
ystd,
clevel | Real (Kind=nag_wp), Intent (Out) | :: |
t,
df,
prob,
dl,
du | Character (1), Intent (In) | :: |
tail,
equal |
|
C Header Interface
#include nagmk26.h
void |
g07caf_ (
const char *tail,
const char *equal,
const Integer *nx,
const Integer *ny,
const double *xmean,
const double *ymean,
const double *xstd,
const double *ystd,
const double *clevel,
double *t,
double *df,
double *prob,
double *dl,
double *du,
Integer *ifail,
const Charlen length_tail,
const Charlen length_equal) |
|
3
Description
Consider two independent samples, denoted by and , of size and drawn from two Normal populations with means and , and variances and respectively. Denote the sample means by and and the sample variances by and respectively.
g07caf calculates a test statistic and its significance level to test the null hypothesis
, together with upper and lower confidence limits for
. 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 .
The test used is the two sample -test. The test statistic is defined by;
where
is the pooled variance of the two samples.
Under the null hypothesis this test statistic has a -distribution with degrees of freedom.
The test of is carried out against one of three possible alternatives;
- ; the significance level, , i.e., a two tailed probability.
- ; the significance level, , i.e., an upper tail probability.
- ; the significance level, , i.e., a lower tail probability.
Upper and lower confidence limits for are calculated as:
where is the percentage point of the -distribution with ( ) 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 -statistic no longer has a -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 is used where
where .
A -distribution with degrees of freedom is used to approximate the distribution of where
The test of is carried out against one of the three alternative hypotheses described above, replacing by and by .
Upper and lower confidence limits for are calculated as:
where is the percentage point of the -distribution with degrees of freedom. |
4
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
5
Arguments
- 1: – Character(1)Input
-
On entry: indicates which tail probability is to be calculated, and thus which alternative hypothesis is to be used.
- The two tail probability, i.e., .
- The upper tail probability, i.e., .
- The lower tail probability, i.e., .
Constraint:
, or .
- 2: – Character(1)Input
-
On entry: indicates whether the population variances are assumed to be equal or not.
- The population variances are assumed to be equal, that is .
- The population variances are not assumed to be equal.
Constraint:
or .
- 3: – IntegerInput
-
On entry: , the size of the sample.
Constraint:
.
- 4: – IntegerInput
-
On entry: , the size of the sample.
Constraint:
.
- 5: – Real (Kind=nag_wp)Input
-
On entry: , the mean of the sample.
- 6: – Real (Kind=nag_wp)Input
-
On entry: , the mean of the sample.
- 7: – Real (Kind=nag_wp)Input
-
On entry: , the standard deviation of the sample.
Constraint:
.
- 8: – Real (Kind=nag_wp)Input
-
On entry: , the standard deviation of the sample.
Constraint:
.
- 9: – Real (Kind=nag_wp)Input
-
On entry: the confidence level, , for the specified tail. For example will give a confidence interval.
Constraint:
.
- 10: – Real (Kind=nag_wp)Output
-
On exit: contains the test statistic, or .
- 11: – Real (Kind=nag_wp)Output
-
On exit: contains the degrees of freedom for the test statistic.
- 12: – Real (Kind=nag_wp)Output
-
On exit: contains the significance level, that is the tail probability,
, as defined by
tail.
- 13: – Real (Kind=nag_wp)Output
-
On exit: contains the lower confidence limit for .
- 14: – Real (Kind=nag_wp)Output
-
On exit: contains the upper confidence limit for .
- 15: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
On entry, | , or , |
or | or , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | . |
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
The computed probability and the confidence limits should be accurate to approximately five significant figures.
8
Parallelism and Performance
g07caf is not threaded in any implementation.
The sample means and standard deviations can be computed using
g01atf.
10
Example
This example 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 (g07cafe.f90)
10.2
Program Data
Program Data (g07cafe.d)
10.3
Program Results
Program Results (g07cafe.r)