Computing p-values

Computing p-values for test statistics


Suppose a test statistic has a t-distribution with k degrees of freedom. For a two-tailed test, the p-value is computed as:

         p = 2 P(tk > |tstat|)         

where |tstat| is the absolute value of the calculated test statistic. This probability can be evaluated by the use of computer algorithms. SHAZAM automatically reports p-values for many test statistics. For example, on the OLS estimation output, SHAZAM reports the p-value for a two-tail test of the null hypothesis that the coefficient is 0.

To get some further insight into how the computation is done, the DISTRIB command can be used to compute p-values for test statistics.

Example

This example uses the Griffiths, Hill and Judge data set on household expenditure for food. The OLS estimation results for the food expenditure relationship can be reviewed.

The SHAZAM program (filename: PVALUE.SHA) that follows shows how to compute p-values for test statistics. The commands replicate the calculation that is automatically done by SHAZAM for computing the p-values for a 2-sided test that is reported on the OLS estimation output. On the OLS output SHAZAM reports 3 decimal places for the p-value - the calculations here allow the curious user to print more decimal places ! The commands also show the calculation of p-values for 1-sided tests.

SAMPLE 1 40
READ (GHJ.txt) FOOD INCOME
* Save the t-ratios from the OLS regression in the variable TR
OLS FOOD INCOME / TRATIO=TR
* Save the degrees of freedom in the variable DF
GEN1 DF1=$DF
* Set the sample period to the number of estimated coefficients
SAMPLE 1 2
* Take the absolute value of the t-ratios.
GENR TRA=ABS(TR)
* Use the DISTRIB command - save the CDF in the variable CDF1
DISTRIB TRA / TYPE=T DF=DF1 CDF=CDF1
* Get the p-value for a 2-sided test.
GENR PVAL2=2*(1-CDF1)
*
* Now get p-values for 1-sided tests.
DISTRIB TR / TYPE=T DF=DF1 CDF=CDF1
* H0: coefficient > 0  vs.  H1: coefficient < 0 
GENR PA=CDF1
* H0: coefficient < 0  vs.  H1: coefficient > 0
GENR PB=1-CDF1
*
* Print the results
PRINT TR PVAL2 PA PB
STOP

The commands show a number of useful features of SHAZAM programming. The following steps should be noted:

  1. The TRATIO= option on the OLS command is used to save the computed t-ratios in the variable assigned the name TR.
  2. After model estimation some scalar results are available in SHAZAM temporary variables. These have special names that start with the $ character. For example, the degrees of freedom is available in the variable with the name $DF. The GEN1 command is used to save this value in the new variable DF1.
  3. The DISTRIB command can be used for computing the probability density function and the cumulative distribution function for a wide variety of probability distributions. The options that are used in this example are:
    TYPE= This option specifies the type of distribution. The option TYPE=T specifies the t-distribution.
    DF= This option is required when TYPE=T is used and this gives the degrees of freedom.
    CDF= This option is used to save the values of the cumulative distribution function in the variable specified.

The SHAZAM output follows. Note that PVAL2 is identical to the value listed in the p-value column on the SHAZAM OLS estimation output. However, more decimal places are displayed when the PRINT command is used to list the values of PVAL2.


 |_SAMPLE 1 40
 |_READ (GHJ.txt) FOOD INCOME
 
 UNIT 88 IS NOW ASSIGNED TO: GHJ.txt
    2 VARIABLES AND       40 OBSERVATIONS STARTING AT OBS       1
 
 |_* Save the t-ratios from the OLS regression in the variable TR
 |_OLS FOOD INCOME / TRATIO=TR
 
  OLS ESTIMATION
       40 OBSERVATIONS     DEPENDENT VARIABLE = FOOD
 ...NOTE..SAMPLE RANGE SET TO:    1,   40
 
  R-SQUARE =    .3171     R-SQUARE ADJUSTED =    .2991
 VARIANCE OF THE ESTIMATE-SIGMA**2 =   46.853
 STANDARD ERROR OF THE ESTIMATE-SIGMA =   6.8449
 SUM OF SQUARED ERRORS-SSE=   1780.4
 MEAN OF DEPENDENT VARIABLE =   23.595
 LOG OF THE LIKELIHOOD FUNCTION = -132.672
 
 VARIABLE   ESTIMATED  STANDARD   T-RATIO        PARTIAL STANDARDIZED ELASTICITY
   NAME    COEFFICIENT   ERROR      38 DF   P-VALUE CORR. COEFFICIENT  AT MEANS 
 INCOME     .23225      .5529E-01   4.200      .000  .563      .5631      .6871
 CONSTANT   7.3832      4.008       1.842      .073  .286      .0000      .3129

 |_* Save the degrees of freedom in the variable DF
 |_GEN1 DF1=$DF
 ..NOTE..CURRENT VALUE OF $DF  =   38.000
 |_* Set the sample period to the number of estimated coefficients
 |_SAMPLE 1 2
 |_* Take the absolute value of the t-ratios.
 |_GENR TRA=ABS(TR)

 |_* Use the DISTRIB command - save the CDF in the variable CDF1
 |_DISTRIB TRA / TYPE=T DF=DF1 CDF=CDF1
 T DISTRIBUTION DF=   38.000
 VARIANCE=   1.0556       H=   1.0000
 
               DATA        PDF        CDF        1-CDF
   TRA
  ROW     1     4.2004      .23351E-03  .99992      .77568E-04
  ROW     2     1.8420      .74782E-01  .96335      .36648E-01

 |_* Get the p-value for a 2-sided test.
 |_GENR PVAL2=2*(1-CDF1)
 |_*
 |_* Now get p-values for 1-sided tests.
 |_DISTRIB TR / TYPE=T DF=DF1 CDF=CDF1
 T DISTRIBUTION DF=   38.000
 VARIANCE=   1.0556       H=   1.0000
 
               DATA        PDF        CDF        1-CDF
   TR
  ROW     1     4.2004      .23351E-03  .99992      .77568E-04
  ROW     2     1.8420      .74782E-01  .96335      .36648E-01

 |_* H0: coefficient > 0  vs.  H1: coefficient < 0
 |_GENR PA=CDF1
 |_* H0: coefficient < 0  vs.  H1: coefficient > 0
 |_GENR PB=1-CDF1
 |_*
 |_* Print the results
 |_PRINT TR PVAL2 PA PB
       TR             PVAL2          PA             PB
    4.200378       .1551364E-03   .9999224       .7756820E-04
    1.841956       .7329593E-01   .9633520       .3664796E-01
 |_STOP

Home [SHAZAM Guide home]