Z-Test |
One sample z-test of the null hypothesis that data in the sample are a random sample from a normal distribution with specified supposed mean and standard deviation, against the alternative that the mean is different.
This topic contains the following sections:
For one sample z-test we consider the time series
Test statistic is calculated as follows:
where standard error SE:
Default supposed values of mean and variance are 0 and 1 correspondingly.
The following constructors create an instance of ZTest class.
Constructor | Description | Performance |
---|---|---|
two-tailed test, default significance level | Constructor without parameters. Creates ZTest instance with default significance level for two-tailed test. | |
default significance level | Creates ZTest instance with default significance level and user defined tail. | |
two-tailed test, user defined significance level | Creates ZTest instance for two-tailed test and user-defined significance level. | |
user defined tail and significance level | Creates ZTest instance with user defined significance level and tail. |
The class provides the following methods:
Method | Description | Performance |
---|---|---|
update | Update sample by double array part, user specifies offset and number of the elements to use: | |
update mean and variance | Updates test statistic using provided sample and supposition about mean and variance. Double array sample: Update(Double, Double, Double) Vector 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 ZTest class usage:
1using System; 2using FinMath.LinearAlgebra; 3using FinMath.Statistics.HypothesisTesting; 4using FinMath.Statistics.Distributions; 5 6namespace FinMath.Samples 7{ 8 class ZTestSample 9 { 10 static void Main() 11 { 12 // Create an instance of normal distribution. 13 Normal distr = new Normal(3, 1); 14 15 // Generate random sample from normal distribution. 16 Vector series = Vector.Random(100, distr); 17 18 // Create an instance of ZTest. 19 ZTest test = new ZTest(0.05, Tail.Both); 20 test.Update(series, 3, 1); 21 22 Console.WriteLine("Test Result:"); 23 // Test decision 24 Console.WriteLine($" The null hypothesis failed to be rejected: {test.Decision}"); 25 // The statistic of ZTest test. 26 Console.WriteLine($" Statistics = {test.Statistics:0.000}"); 27 // The p-value of the test statistic. 28 Console.WriteLine($" P-Value = {test.PValue:0.000}"); 29 } 30 } 31}