FTestTwoSample |
Two-sample F-test of the null hypothesis that data in the samples are random samples from independent normal distributions with equal variances, against the alternative that the variances are different.
This topic contains the following sections:
Let X0, ..., Xn-1 and Y0, ..., Ym-1 be independent and identically distributed samples from two populations which each have a normal distribution. The expected values for the two populations can be different, and the hypothesis to be tested is that the variances are equal. Let SX2, SY2 be the sample variances. Then the test statistic:
has an F-distribution with n − 1 and m − 1 degrees of freedom if the null hypothesis of equality of variances is true. Otherwise it has a non-central F-distribution. The null hypothesis is rejected if F is either too large or too small.
This test can be either a two-sided test or a one-sided test.
Tail.Both. In the alternative hypothesis variance of the first distribution is not equal to variance of the second distribution.
Tail.Left. In the alternative hypothesis variance of the first distribution is less than variance of the second distribution.
Tail.Right. In the alternative hypothesis variance of the first distribution is greater than variance of the second distribution.
The following constructors create an instance of FTestTwoSample class.
Constructor | Description | Performance |
---|---|---|
two-tailed test, default significance level | Constructor without parameters. Creates FTestTwoSample instance with default significance level for two-tailed test. | |
default significance level | Creates FTestTwoSample instance with default significance level and user defined tail. | |
two-tailed test, user defined significance level | Creates FTestTwoSample instance for two-tailed test and user-defined significance level. | |
user defined tail and significance level | Creates FTestTwoSample instance with user defined significance level and tail. |
The class provides the following methods:
Method | Description | Performance |
---|---|---|
update | Updates test statistic using provided samples. User specifies two double array samples and offsets and number of elements to use in each sample: |
The class provides the following properties:
Property | Description | Performance |
---|---|---|
region of acceptance | We fail to reject null hypothesis if test statistics is between left and right borders of region of acceptance. Region of acceptance left border: Region of acceptance right border: | |
p-value | The probability of obtaining a test statistic at least as extreme as the one that was actually observed, assuming that the null hypothesis is true. |
The example of FTestTwoSample class usage:
1using System; 2using FinMath.LinearAlgebra; 3using FinMath.Statistics.HypothesisTesting; 4using FinMath.Statistics.Distributions; 5 6namespace FinMath.Samples 7{ 8 class FTestTwoSamplesSample 9 { 10 static void Main() 11 { 12 //Create instances of normal distribution; 13 Normal distr1 = new Normal(0, 5); 14 Normal distr2 = new Normal(3, 5); 15 16 // Generate random series. 17 Vector series1 = Vector.Random(100, distr1); 18 Vector series2 = Vector.Random(150, distr2); 19 20 // Create an instance of FTestTwoSample 21 FTestTwoSample test = new FTestTwoSample(0.05, Tail.Both); 22 test.Update(series1, series2); 23 24 Console.WriteLine("Test Result:"); 25 // Test decision 26 Console.WriteLine($" The null hypothesis failed to be rejected: {test.Decision}"); 27 // The statistic of FTestTwoSample test. 28 Console.WriteLine($" Statistics = {test.Statistics:0.000}"); 29 // The p-value of the test statistic. 30 Console.WriteLine($" P-Value = {test.PValue:0.000}"); 31 32 } 33 } 34}