NAG C Library Function Document
nag_2_sample_t_test (g07cac)
1
Purpose
nag_2_sample_t_test (g07cac) 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
#include <nag.h> |
#include <nagg07.h> |
void |
nag_2_sample_t_test (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) |
|
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.
nag_2_sample_t_test (g07cac) 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:
(i) |
; the significance level, , i.e., a two tailed probability. |
(ii) |
; the significance level, , i.e., an upper tail probability. |
(iii) |
; 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 (1979). 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 (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:
– Nag_TailProbabilityInput
-
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:
– Nag_PopVarInput
-
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:
– doubleInput
-
On entry: the mean of the sample, .
- 6:
– doubleInput
-
On entry: the mean of the sample, .
- 7:
– doubleInput
-
On entry: the standard deviation of the sample, .
Constraint:
.
- 8:
– doubleInput
-
On entry: the standard deviation of the sample, .
Constraint:
.
- 9:
– doubleInput
-
On entry: the confidence level, , for the specified tail. For example will give a 95% confidence interval.
Constraint:
.
- 10:
– double *Output
-
On exit: contains the test statistic, or .
- 11:
– double *Output
-
On exit: contains the degrees of freedom for the test statistic.
- 12:
– double *Output
-
On exit: contains the significance level, that is the tail probability,
, as defined by
tail.
- 13:
– double *Output
-
On exit: contains the lower confidence limit for .
- 14:
– double *Output
-
On exit: contains the upper confidence limit for .
- 15:
– NagError *Input/Output
-
The NAG error argument (see
Section 3.7 in How to Use the NAG Library and its Documentation).
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, .
Constraint: .
On entry, .
Constraint: .
- 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:
.
- NE_REAL_ARG_LE
-
On entry,
clevel must not be less than or equal to 0.0:
.
On entry,
xstd must not be less than or equal to 0.0:
.
On entry,
ystd must not be less than or equal to 0.0:
.
7
Accuracy
The computed probability and the confidence limits should be accurate to approximately five significant figures.
8
Parallelism and Performance
nag_2_sample_t_test (g07cac) is not threaded in any implementation.
The sample means and standard deviations can be computed using
nag_summary_stats_onevar (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)