Dataplot Vol 1 Vol 2

# FREQUENCY TEST

Name:
FREQUENCY TEST
Type:
Analysis Command
Purpose:
Perform a frequency or frequency within a block test for randomness.
Description:
The frequency (or frequency within a block) test is used to test the randomness of a sequence of zeroes and ones (Dataplot will covert a data set with exactly two distinct values to a sequence of zeroes and ones). The test is based on the proportion of zeroes and ones. Specifically, it tests the closeness of the proportion of ones to 0.5. The frequency within a block test is a refinement that tests the proportion of ones within M-value blocks.

The frequency test is defined as follows.

 H0: The data are random. Ha: The data are not random. Test Statistic: The test statistic is $$s_{obs} = \frac{|S_n|}{\sqrt{n}}$$ with n denoting the number of observations in the sequence and Sn = X1 + X2 + ... + Xn. The Xi are the data values where the zero values have been converted to negative ones. Significance Level: $$\alpha$$ (typically set to 0.01 for this test) Critical Region: sobs > $$\phi^{-1} (1 - \alpha/2$$ with $$\phi^{-1}$$ denoting the percent point function of the standard normal distribution. Conclusion: Reject H0 if the test statistic is greater than the critical value.

For the frequency within a block test, we partition the input values into N=[n/m] non-overlapping blocks with n denoting the number of observations and m the number of observations within a block. Any unused observations are discarded. The frequency within a block test is then defined as follows.

 H0: The data are random. Ha: The data are not random. Test Statistic: Compute the proportion, , of ones in each block (i.e., the number of ones in the block divided by m). The test statistic is $$\chi_{obs}^2 = 4m\sum_{i=1}^{n}{(\pi_i - 0.5)^2}$$ Significance Level: $$\alpha$$ (typically set to 0.01 for this test) Critical Region: Compute the p-value $$IGAMC(N/2,\chi^{2}(obs)/2)$$ with IGAMC denoting the incomplete gamma function (enter HELP GAMIP for details). Conclusion: Reject H0 if the p-value < $$\alpha$$.
Syntax 1:
FREQUENCY TEST <y>             <SUBSET/EXCEPT/FOR qualification>
where <y> is the response variable being tested;
and where the <SUBSET/EXCEPT/FOR qualification> is optional.
Syntax 2:
MULTIPLE FREQUENCY TEST <y1> ... <yk>
<SUBSET/EXCEPT/FOR qualification>
where <y1> ... <yk> is a list of 1 to 30 response variables;
and where the <SUBSET/EXCEPT/FOR qualification> is optional.

The keyword MULTIPLE is optional. The frequency test will be performed on each response variable and these response variables can be matrices. The TO syntax is supported for the variable list.

Syntax 3:
REPLICATED FREQUENCY TEST <y> <x1> ... <xk>
<SUBSET/EXCEPT/FOR qualification>
where <y> is the response variable;
<x1> ... <xk> is a list of 1 to 6 group-id variables;
and where the <SUBSET/EXCEPT/FOR qualification> is optional.

This syntax will cross-tabulate the group-id variables and performs the frequency test for each unique combination of cross-tabulated values. For example, if X1 has 3 levels and X2 has 2 levels, there will be 6 frequency tests performed. This syntax does not support matrix arguments and the keyword REPLICATED is required (to distinguish this from the MULTIPLE case). The TO syntax is supported for the variable list.

Syntax 4:
FREQUENCY BLOCK TEST <y>
<SUBSET/EXCEPT/FOR qualification>
where <y> is the response variable being tested;
and where the <SUBSET/EXCEPT/FOR qualification> is optional.

The length of the block is set by entering the command

LET M = <value>

before entering the FREQUENCY BLOCK TEST command.

Syntax 5:
MULTIPLE FREQUENCY BLOCK TEST <y1> ... <yk>
<SUBSET/EXCEPT/FOR qualification>
where <y1> ... <yk> is a list of 1 to 30 response variables;
and where the <SUBSET/EXCEPT/FOR qualification> is optional.

The keyword MULTIPLE is optional. The frequency block test will be performed on each response variable and these response variables can be matrices. The TO syntax is supported for the variable list.

Syntax 6:
REPLICATED FREQUENCY TEST <y> <x1> ... <xk>
<SUBSET/EXCEPT/FOR qualification>
where <y> is the response variable;
<x1> ... <xk> is a list of 1 to 6 group-id variables;
and where the <SUBSET/EXCEPT/FOR qualification> is optional.

This syntax will cross-tabulate the group-id variables and performs the frequency block test for each unique combination of cross-tabulated values. For example, if X1 has 3 levels and X2 has 2 levels, there will be 6 frequency block tests performed. This syntax does not support matrix arguments and the keyword REPLICATED is required (to distinguish this from the MULTIPLE case). The TO syntax is supported for the variable list.

Examples:
FREQUENCY TEST Y
FREQUENCY TEST Y1 TO Y10
REPLICATED FREQUENCY TEST Y X1 X2

LET M = 20
FREQUENCY BLOCK TEST Y SUBSET TAG > 1

Note:
The following statistics are also supported:

LET A = FREQUENCY TEST Y
LET A = FREQUENCY TEST CDF Y
LET A = FREQUENCY WITHIN A BLOCK TEST Y
LET A = FREQUENCY WITHIN A BLOCK TEST CDF Y

Enter HELP STATISTICS to see what commands can use these statistics.

Note:
If you want to test a uniform random number generator, you can use this test by converting the uniform random numbers to binomial random numbers. For example,

LET N = 1
LET P = 0.5
LET Y = BINOMIAL RANDOM NUMBERS FOR I = 1 1 1000
FREQUENCY TEST Y
Note:
The recommended minimum sample size for both the frequency test and for the frequency within a block test is 100.

For the frequency within a block test, it is additionally recommended that the block size should be at least 20 and it should also be greater than or equal to 0.01 times the sample size. It is recommended that the number of samples within a block be less than 100.

Default:
None
Synonyms:
FREQUENCY WITHIN A BLOCK TEST and FREQUENCY WITHIN BLOCK TEST are synonyms for FREQUENCY BLOCK TEST.
Related Commands:
 CUSUM TEST = Perform a cumulative sum test for randomness. RUNS TEST = Perform a runs test for randomness. UNIFORM PROBABILITY PLOT = Generate a uniform probability plot.
Reference:
"A Statistical Test Suite for Random and Psuedorandom Number Generators for Cryptographic Applications", Andrew Rukhin, Juan Soto, James Nechvatal, Miles Smid, Elaine Barker, Stefan Leigh, Mark Levenson, Mark Vangel, David Banks, Alan Heckert, James Dray, San Vo, NIST SP 800-22, October, 2000.
Applications:
Testing for Randomness
Implementation Date:
2004/1
2011/3: Support for MULTIPLE option
2011/3: Support for REPLICATION option
2011/3: Support for matrix arguments and the TO syntax
2011/3: Output reformatted, added support for RTF output
2011/3: Support for SET WRITE DECIMALS 2011/3: Added FREQUENCY TEST statistics
Program:

LET N = 1
LET P = 0.5
LET Y1 = BINOMIAL RANDOM NUMBERS FOR I = 1 1 200
LET P = 0.58
LET Y2 = BINOMIAL RANDOM NUMBERS FOR I = 1 1 200
LET P = 0.65
LET Y3 = BINOMIAL RANDOM NUMBERS FOR I = 1 1 200
LET P = 0.85
LET Y4 = BINOMIAL RANDOM NUMBERS FOR I = 1 1 200
SET WRITE DECIMALS 4
.
FREQUENCY TEST Y1
FREQUENCY TEST Y1 Y2 Y3
.
LET M = 20
FREQUENCY BLOCK TEST Y1

The following output is generated:
      *************************
**  FREQUENCY TEST Y1  **
*************************

Frequency Test for Randomness

Response Variable: Y1

H0: The Data Are Random
Ha: The Data Are Not Random

Summary Statistics:
Number of Observations:                             200
Sum of +1 and -1 Values:                        -6.0000

Frequency Test Statistic:                        0.4242
CDF Value:                                       0.6643
P-Value:                                         0.6713

Conclusions

------------------------------------------------------------------------
Null
Null     Confidence           Test       Critical     Hypothesis
Hypothesis          Level      Statistic    Value (+/-)     Conclusion
------------------------------------------------------------------------
Random          50.0%         0.4242         0.6744         ACCEPT
Random          75.0%         0.4242         1.1503         ACCEPT
Random          90.0%         0.4242         1.6448         ACCEPT
Random          95.0%         0.4242         1.9599         ACCEPT
Random          97.5%         0.4242         2.2414         ACCEPT
Random          99.0%         0.4242         2.5758         ACCEPT
Random          99.9%         0.4242         3.2905         ACCEPT

*******************************
**  FREQUENCY TEST Y1 Y2 Y3  **
*******************************

Frequency Test for Randomness

Response Variable: Y1

H0: The Data Are Random
Ha: The Data Are Not Random

Summary Statistics:
Number of Observations:                             200
Sum of +1 and -1 Values:                        -6.0000

Frequency Test Statistic:                        0.4242
CDF Value:                                       0.6643
P-Value:                                         0.6713

Conclusions

------------------------------------------------------------------------
Null
Null     Confidence           Test       Critical     Hypothesis
Hypothesis          Level      Statistic    Value (+/-)     Conclusion
------------------------------------------------------------------------
Random          50.0%         0.4242         0.6744         ACCEPT
Random          75.0%         0.4242         1.1503         ACCEPT
Random          90.0%         0.4242         1.6448         ACCEPT
Random          95.0%         0.4242         1.9599         ACCEPT
Random          97.5%         0.4242         2.2414         ACCEPT
Random          99.0%         0.4242         2.5758         ACCEPT
Random          99.9%         0.4242         3.2905         ACCEPT

Frequency Test for Randomness

Response Variable: Y2

H0: The Data Are Random
Ha: The Data Are Not Random

Summary Statistics:
Number of Observations:                             200
Sum of +1 and -1 Values:                        30.0000

Frequency Test Statistic:                        2.1213
CDF Value:                                       0.9830
P-Value:                                         0.0338

Conclusions

------------------------------------------------------------------------
Null
Null     Confidence           Test       Critical     Hypothesis
Hypothesis          Level      Statistic    Value (+/-)     Conclusion
------------------------------------------------------------------------
Random          50.0%         2.1213         0.6744         REJECT
Random          75.0%         2.1213         1.1503         REJECT
Random          90.0%         2.1213         1.6448         REJECT
Random          95.0%         2.1213         1.9599         REJECT
Random          97.5%         2.1213         2.2414         ACCEPT
Random          99.0%         2.1213         2.5758         ACCEPT
Random          99.9%         2.1213         3.2905         ACCEPT

Frequency Test for Randomness

Response Variable: Y3

H0: The Data Are Random
Ha: The Data Are Not Random

Summary Statistics:
Number of Observations:                             200
Sum of +1 and -1 Values:                        58.0000

Frequency Test Statistic:                        4.1012
CDF Value:                                       0.9999
P-Value:                                         0.0000

Conclusions

------------------------------------------------------------------------
Null
Null     Confidence           Test       Critical     Hypothesis
Hypothesis          Level      Statistic    Value (+/-)     Conclusion
------------------------------------------------------------------------
Random          50.0%         4.1012         0.6744         REJECT
Random          75.0%         4.1012         1.1503         REJECT
Random          90.0%         4.1012         1.6448         REJECT
Random          95.0%         4.1012         1.9599         REJECT
Random          97.5%         4.1012         2.2414         REJECT
Random          99.0%         4.1012         2.5758         REJECT
Random          99.9%         4.1012         3.2905         REJECT

*******************************
**  FREQUENCY BLOCK TEST Y1  **
*******************************

Frequency Within a Block Test for Randomness

Response Variable: Y1

H0: The Data Are Random
Ha: The Data Are Not Random

Summary Statistics:
Number of Observations:                             200
Block Size:                                          20
Number of Observations Within a Block:               10

Frequency Within A Block Test Statistic:         8.5999
P-Value:                                         0.5704

Conclusions

---------------------------------------------------------
Null
Null     Confidence                    Hypothesis
Hypothesis          Level        P-Value     Conclusion
---------------------------------------------------------
Random          50.0%         0.5704         ACCEPT
Random          75.0%         0.5704         ACCEPT
Random          90.0%         0.5704         ACCEPT
Random          95.0%         0.5704         ACCEPT
Random          97.5%         0.5704         ACCEPT
Random          99.0%         0.5704         ACCEPT
Random          99.9%         0.5704         ACCEPT


NIST is an agency of the U.S. Commerce Department.

Date created: 2/3/2004
Last updated: 10/13/2015