EconGroup`NormalityTests

by Luci Ellis

This notebook implements various tests for univariate and multivariate normality.

Reference

Title

EconGroup`NormalityTests

Author

Luci Ellis

Summary

This notebook implements various tests for univariate and multivariate normality.

Copyright

© Copyright 1997, Luci Ellis. 

Permission is granted to distribute this file for any purpose except for inclusion in commercial software or program collections. This copyright notice must remain intact..

Notebook Version

1.0

Mathematica Version

3.0

History

Version 1.0 for Programming in Mathematica, 3rd edition.

Keywords

normality

Source

Maeder, R. Programming in Mathematica, 3rd ed. Addison-Wesley, 1996.

Urzùa, C. M.  “On the correct uses of Omnibus Normality Tests”, Economics Letters,  1997.

Urzùa, C. M. “Multivariate Normality Tests”, Advances in Econometrics,  1997.

Warnings

description of global effects, incompatibilities

Note: all cells marked as "InitializationCell" will be written to the Auto-Save package. This package can then be read in programs that use it with Needs["Template`"]. Cells not intended to belong to the package should not have this property.

Limitation

It is assumed that the data is in matrix or vector form, with each time series in its own row. Therefore, the data should be presented as, say, a 3 by 100 list, not a 100 by 3 list.

Discussion

description of algorithm, information for experts

Requirements

Statistics`DescriptiveStatistics`, Statistics`ContinuousDistributions`

Interface

This part declares the publicly visible functions, options, and values.

Set up the package context, including public imports

BeginPackage["EconGroup`NormalityTests`",
	"Statistics`DescriptiveStatistics`", "Statistics`ContinuousDistributions`"]

Needs["Statistics`ContinuousDistributions`"]

Usage messages for the exported functions and the context itself

NormalityTests::usage  =  
      "NormalityTests.m implements various tests for both univariate and \
multivariate normality."

normalityTestStatistic::usage = "normalityTestStatistic[x_Vector,opts] tests whether sample of data is normally distributed, using LM test of Jarque-Bera(1980) or Augmented LM test due to Urzúa (1997). Options 
are Method->JarqueBera and Significance->0.1"

multinormalTestStatistic::usage  =  
      "Tests whether matrix of data is distributed according to a \
multinormal distribution."

Method::usage = "Method is an option for normalityTestStatistic and multinormalTestStatistic indicating the type of test to do. The default for normalityTestStatistic is JarqueBera, with Urzua being an alternative. The default for multinormalTestStatistic is Automatic which gives the Omnibus test, with alternatives of Skewness, Kurtosis and Omnibus explicitly."

Significance::usage = "Significance is an option for normalityTestStatistic and multinormalTestStatistic indicating the size of the test. For normalityTestStatistic the available sizes are 0.2, 0.15, 0.1, 0.05 and 0.01, while for multinormalTestStatistic the available sizes are 0.9, 0.95, 0.975 and 0.99."

Residuals::usage = "Residuals is an option for multinormalTestStatistic which is not yet implemented. The critical values for multivariate normality tests of residuals are not the same as for raw data but instead depend on the design matrix of the regression."

JarqueBera::usage = "JarqueBera is the default type of normality test."

Urzua::usage = "Urzua is the alternative type of normality test which has better small-sample properties."

Omnibus::usage = "Omnibus is the default type of multivariate normality test."

Skewness::usage = "Skewness is a type of multivariate normality test, using a multivariate skewness measure to test for normality."

Kurtosis::usage = "Kurtosis is a type of multivariate normality test, using a multivariate kurtosis measure to test for normality."

Error messages for the exported objects

normalityTestStatistic::dims  =  
      "List of `1` dimensions entered, one-dimensional vector \
expected."

normalityTestStatistic::notnum  =  
      "Input data elements must be numerical quantities."

multinormalTestStatistic::notnum  =  
      "Input data elements must be numerical quantities."

multinormalTestStatistic::nocrit  =  
      "Data must be a matrix with five or fewer rows. You may need to \
transpose the matrix prior to calling multinormalTestStatistic."

Implementation

This part contains the actual definitions and any auxiliary functions that should not be visible outside.

Begin the private context (implementation part)

Begin["`Private`"]

Needs["Statistics`ContinuousDistributions`"]

Off[General::spell]

Definition of auxiliary functions and local (static) variables

ALMCritPointTable

\(\(ALMCritPointTable\  = \ 
      
{{" ", 10, 20, 35, 50, 75, 100, 150, 200, 300, 800, ∞}, 
        
		{0.20, \ 2.14, 2.25, 2.35, 2.42, 2.62, 2.69, 2.85, 2.88, 2.92, 
          3.07, 3.22}, 

        		{0.15, 2.77, \ 2.81, 2.84, 2.95, \ 3.20, 3.16, 3.38, \ 3.44, \ 
          3.50, \ 3.65, \ 3.79\ }, 

        		{0.1, \ 4.23, \ 4.01, \ 3.81, \ \ 3.89\ , 4.17, \ 4.05, 4.26, 
          4.31, \ 4.32, 4.47, \ 4.61}, 

        		{0.05, \ 7.7, \ 7.15, \ 6.38, \ 6.43, \ 6.45, \ 6.04, \ 6.34, \ 
          6.22, \ 6.15, \ 6., \ 5.99}, 

        		{0.01, 17.69, \ 19.59, \ 16.77, \ 16.33, \ 16.32, \ 13.27, \ 
          13.34, \ 12.62, \ 12.1, \ 10.68, \ 9.21}}; \)\)

Multivariate ALMCritPointTable(s)

\(\(OmnibusALMCritPointTable = 

      	{{{" ", 10, 20, 50, 100, 200, 800, ∞}, 

          		{0.9, 4.12, 3.94, 3.9, 4.06, 4.21, 4.39, 4.61}, 

          		{0.95, 7.79, 6.84, 6.42, 6.13, 6.07, 5.9, 5.99}, 

          		{0.975, 12.32, 11.25, 9.33, 9.02, 8.5, 7.64, 7.38}, 

          		{0.99, 18.61, 18.59, 15.56, 14.44, 12.55, 10.25, 9.21}}, 

        		{{" ", 10, 20, 50, 100, 200, 800, ∞}, 

          		{0.9, 8.65, 8.39, 7.83, 7.98, 7.88, 7.85, 7.78}, 

          		{0.95, 13.36, 12.63, 11.57, 11.2, 10.94, 10., 9.49}, 

          		{0.975, 18.82, 18.66, 16.96, 15.96, 14.34, 12.56, 11.14}, 

          		{0.99, 24.99, 27.68, 26.17, 23.03, 21.42, 16.35, 13.28}}, 

        	{{" ", 10, 20, 50, 100, 200, 800, ∞}, 

          		{0.9, 12.96, 11.94, 11.35, 11.12, 11.01, 10.83, 10.65}, 

          		{0.95, 18.39, 17.35, 16.62, 15.24, 14.37, 13.24, 12.59}, 

          		{0.975, 23.94, 24.03, 22.8, 21.47, 18.53, 15.97, 14.45}, 

          		{0.99, 32.33, 33.93, 33.48, 30.57, 24.14, 20.51, 16.81}}, 

        	{{" ", 10, 20, 50, 100, 200, 800, ∞}, 

          		{0.9, 16.27, 15.7, 14.81, 14.69, 14., 13.56, 13.36}, 

          		{0.95, 22.32, 22.35, 20.43, 19.16, 18.21, 16.3, 15.51}, 

          		{0.975, 28.83, 30.18, 27.49, 24.63, 23.03, 19.17, 17.54}, 

          		{0.99, 37.07, 40.82, 39.5, 34.01, 30.97, 23.46, 20.09}}, 

        	{{" ", 10, 20, 50, 100, 200, 800, ∞}, 

          		{0.9, 19.98, 18.67, 18.06, 17.60, 17., 16.21, 15.99}, 

          		{0.95, 26.99, 25.71, 23.95, 22.91, 21.25, 19.29, 18.31}, 

          		{0.975, 33.45, 34.01, 31.24, 28.68, 26.75, 22.24, 20.48}, 

          		{0.99, 42.49, 48.24, 44.01, 38.34, 33.21, 26.42, 23.21}}}; 
    \)\)

\(\(SkewnessALMCritPointTable = 

      	{{{" ", 10, 20, 50, 100, 200, 800, ∞}, 

          		{0.9, 2.70, 2.67, 2.67, 2.61, 2.63, 2.67, 2.71}, 

          		{0.95, 4.14, 3.96, 3.85, 3.89, 3.83, 3.85, 3.84}, 

          		{0.975, 5.68, 5.45, 5.18, 5.19, 5.07, 4.88, 5.02}, 

          		{0.99, 7.59, 7.66, 7.1, 7.46, 6.82, 6.35, 6.64}}, 

        		{{" ", 10, 20, 50, 100, 200, 800, ∞}, 

          		{0.9, 4.77, 4.79, 4.64, 4.59, 4.65, 4.63, 4.61}, 

          		{0.95, 6.42, 6.34, 6.34, 6.15, 6.1, 6.06, 5.99}, 

          		{0.975, 8.04, 8.21, 7.93, 7.78, 7.77, 7.44, 7.38}, 

          		{0.99, 9.94, 10.64, 10.41, 10.04, 10.15, 9.21, 9.21}}, 

        	{{" ", 10, 20, 50, 100, 200, 800, ∞}, 

          		{0.9, 6.57, 6.49, 6.38, 6.27, 6.27, 6.14, 6.25}, 

          		{0.95, 8.47, 8.46, 8.33, 8.01, 7.78, 7.75, 7.82}, 

          		{0.975, 10.28, 10.27, 10.42, 9.77, 9.5, 9.26, 9.39}, 

          		{0.99, 12.69, 13.14, 13.23, 12.28, 11.82, 11.11, 11.35}}, 

        	{{" ", 10, 20, 50, 100, 200, 800, ∞}, 

          		{0.9, 8.17, 8.07, 8.04, 7.95, 7.93, 7.81, 7.78}, 

          		{0.95, 10.36, 10.38, 10.18, 9.86, 9.7, 9.57, 9.49}, 

          		{0.975, 12.26, 12.68, 12.19, 11.77, 11.42, 11.09, 11.14}, 

          		{0.99, 15.09, 15.58, 15.28, 14.27, 13.98, 13.37, 13.28}}, 

        	{{" ", 10, 20, 50, 100, 200, 800, ∞}, 

          		{0.9, 9.83, 9.57, 9.45, 9.44, 9.31, 9.27}, 

          		{0.95, 12.16, 11.9, 11.83, 11.48, 11.31, 11.1, 11.07}, 

          		{0.975, 14.1, 14.42, 14.03, 13.64, 13.18, 12.93, 12.83}, 

          		{0.99, 17.42, 17.88, 16.99, 16.7, 15.88, 15.5, 15.09}}}; \)\)

\(\(KurtosisALMCritPointTable = 

      	{{{" ", 10, 20, 50, 100, 200, 800, ∞}, 

          		{0.9, 2.07, 1.9, 1.98, 2.12, 2.31, 2.47, 2.71}, 

          		{0.95, 4.06, 3.65, 3.26, 3.41, 3.5, 3.62, 3.84}, 

          		{0.975, 6.91, 6.53, 5.51, 5.39, 4.97, 5.02}, 

          		{0.99, 11.29, 12.03, 10., 9.02, 8.51, 7.23, 6.64}}, 

        		{{" ", 10, 20, 50, 100, 200, 800, ∞}, 

          		{0.9, 4.3, 4.22, 4.07, 4.19, 4.42, 4.53, 4.61}, 

          		{0.95, 7.34, 7.23, 6.8, 6.96, 6.4, 6.03, 5.99}, 

          		{0.975, 11.11, 11.3  .3, 10.82, 10.3, 9.38, 8.02, 7.38}, 

          		{0.99, 19.93, 22.28, 22.34, 21.59, 17.67, 14.75, 11.35}}, 

        	{{" ", 10, 20, 50, 100, 200, 800, ∞}, 

          		{0.9, 6.88, 6.24, 6.01, 6.07, 6.13, 6.34, 6.25}, 

          		{0.95, 10.33, 10.18, 9.63, 9.2, 8.53, 8.29, 7.82}, 

          		{0.975, 14.28, 14.96, 14.2, 13.69, 11.8, 10.55, 9.35}, 

          		{0.99, 19.93, 22.28, 22.34, 21.59, 17.67, 14.75, 11.35}}, 

        	{{" ", 10, 20, 50, 100, 200, 800, ∞}, 

          		{0.9, 8.55, 8.67, 8.03, 8.09, 7.93, 7.81, 7.78}, 

          		{0.95, 12.43, 13.04, 12.2, 11.68, 10.93, 9.99, 9.49}, 

          		{0.975, 17.06, 19.15, 17.29, 15.92, 15.29, 12.46, 11.14}, 

          		{0.99, 23.2, 27.77, 26.65, 24.45, 21.53, 16.03, 13.28}}, 

        	{{" ", 10, 20, 50, 100, 200, 800, ∞}, 

          		{0.9, 10.69, 10.16, 9.89, 9.77, 9.53, 9.25, 9.24}, 

          		{0.95, 15.19, 15.09, 14.37, 13.66, 12.97, 11.7, 11.07}, 

          		{0.975, 20., 21.41, 20.12, 18.15, 16.79, 14.25, 12.83}, 

          		{0.99, 26.16, 31.82, 29.09, 26.33, 22.28, 17.82, 15.09}}}; 
    \)\)

ALMCritPoint functions

ALMCritPoint[n_, sig_] := 
  ALMCritPointTable[[Flatten[Position[ALMCritPointTable, 
      sig]][[1]],Flatten[Position[ALMCritPointTable, n]][[
    2]] ]]

\(\(ALMCritPoint[n_, sig_, method_, rowdim_] := 
	
      Which[method === Automatic, 
        OmnibusALMCritPointTable[[rowdim\ , \ 
          \(Flatten[Position[OmnibusALMCritPointTable, sig]]
              \)[[2]], 
          \(Flatten[Position[OmnibusALMCritPointTable, n]]
              \)[[3]]\ \ 
          ]], 
		method === Omnibus, 
		
        OmnibusALMCritPointTable[[rowdim, 
          \(Flatten[Position[OmnibusALMCritPointTable, sig]]
              \)[[2]], 
          \(Flatten[Position[OmnibusALMCritPointTable, n]]
              \)[[3]]\ \ 
          ]], 
		method === Skewness, 
        SkewnessALMCritPointTable[[rowdim, 
          \(Flatten[Position[SkewnessALMCritPointTable, sig]]
              \)[[2]], 
          \(Flatten[Position[SkewnessALMCritPointTable, n]]
              \)[[3]]\ \ 
          ]], 
		method === Kurtosis, 
        KurtosisALMCritPointTable[[rowdim, 
          \(Flatten[Position[KurtosisALMCritPointTable, sig]]
              \)[[2]], 
          \(Flatten[Position[KurtosisALMCritPointTable, n]]
              \)[[3]]\ 
          ]]]
	\)\)

Definition of the exported functions

normalityTestStatistic[]

Options[normalityTestStatistic]={Method->JarqueBera,Significance->0.1}

\(normalityTestStatistic[x_List, opts___] := 
	
      Module[{way, n, xbar, teststat, sig, ntest}, 
		
        If[Length[Dimensions[x]] == 1, 
		
          If[And\ @@\((\(NumericQ[#]&\)\ /@\ x)\)	, 
					
            way\  = \ 
              \((Method\  /. {opts})\) /. Options[normalityTestStatistic]; 

            			sig\  = \ 
              \((Significance /. \ {opts})\)\  /. 
                Options[normalityTestStatistic]; 
			n = N[Length[x]]; 

            			ntest\  = \ 
              \(If[n > 2000, ∞, 
                  Part[{10, 20, 35, 50, 75, 100, 150, 200, 300, 800}, 
                    Flatten[
                        Position[
                          Union[{10, 20, 35, 50, 75, 100, 150, 200, 300, 
                              800}, {n}], n]] - 1]]\)[\([1]\)]; 
			
            xbar\  = \ Mean[x]; 
			
            If[way === Urzua, 
				
              teststat = 
                \((\(Plus@@\((\(#^3\ &\)\ /@\((x - xbar)\))\)/n
                            \)\/\((Plus@@\((\(#^2\ &\)\ /@\((x - xbar)\))\)/n)
                              \)\^\(3\/2\))\)\^2\ 
                    ×\(\((n + 1)\) \((n + 3)\)\)\/\(6 \((n - 2)\)\) + 
                  \((\(Plus@@\((\(#^4\ &\)\ /@\((x - xbar)\))\)/n\)/
                            \((Plus@@\((\(#^2\ &\)\ /@\((x - xbar)\))\)/n)\)^2
                               - 3 \( n - 1\)\/\(n + 1\))\)^2
                      ×\(\(\((n + 1)\)\^2\) \((n + 3)\) 
                        \((n + 5)\)\)\/\(24\ n \((n - 2)\) \((n - 3)\)\); 

              					
              TableForm[{{"Test Stat", "N for crit", 
                    StringJoin["Crit.Value at ", ToString[sig]]}, {
                    teststat, ntest, ALMCritPoint[ntest, sig]}}], 

              									
              teststat = 
                n \((1\/6×\(\((
                            \(Plus@@\((\(#^3\ &\)\ /@\((x - xbar)\))\)/n\)/
                              \((Plus@@\((\(#^2\ &\)\ /@\((x - xbar)\))\)/n)
                                  \)^\((3\/2)\))\)\ \)^2 + 
                      1\/24×\((
                            \(\ Plus@@\((\(#^4\ &\)\ /@\((x - xbar)\))\)/n\)/
                                \((Plus@@\((\(#^2\ &\)\ /@\((x - xbar)\))\)/n)
                                    \)^2 - 3)\)^2)\)]; 
				
            TableForm[{{"Test Stat", "N for crit", 
                  StringJoin["Crit.Value at ", ToString[sig]]}, {
                  teststat, n, 
                  Quantile[
                    Statistics`NormalDistribution`ChiSquareDistribution[2], 
                    1 - sig]}}], \ Message[normalityTestStatistic::notnum]], 
          Message[normalityTestStatistic::dims, Length[Dimensions[x]]]]]\)

multinormalTestStatistic[]

Options[multinormalTestStatistic] = {Method -> Automatic, 
        Significance -> 0.9, Residuals -> False}

multinormalTestStatistic[x_?MatrixQ, opts___]:=If[And@@(NumericQ[#1]&)/@Flatten[x],If[Dimensions[x][[1]] < 6
                ,Module[{n, xbar, teststat, sig, ntest, way, 
                    𝕊, 𝒮, 
                    𝒢, 𝒟, 𝕪},way = 
                      Method /. {opts} /. 
                        Options[multinormalTestStatistic];sig = 
                      Significance /. {opts} /. 
                        Options[multinormalTestStatistic];n = N[
                        Dimensions[x][[2
                          ]]];dims = 
                      Dimensions[x][[1
                        ]];ntest = 
                      If[n > 2000, ∞, 
                        {10, 20, 50, 100, 200, 800}
                              [[Flatten[
                                Position[{10, 20, 50, 100, 200, 800} 
                                    ⋃ {n}, n]] - 1
                              ]][[1
                          ]]];xbar = (Mean[#1]&)/@x;𝕊 = 
                      (1/n)(
                        Table[x[[i]] - 
                              xbar[[i
                                ]], {i, 1, 
                              dims}].Transpose[
                            Table[x[[i
                                  ]] - 
                                xbar[[i
                                  ]], {i, 1, dims}]])
                        ;𝒢 = 
                      Transpose[Eigenvectors[𝕊]];𝒟 = 
                      DiagonalMatrix[Eigenvalues[𝕊]];\(𝒮 = 
                      𝒢.
                        \((\@#1&)\)/@Inverse[𝒟].Transpose[
                          𝒢]\);𝕪 = 
                      𝒮.Table[
                          x[[i]] - 
                            xbar[[i]], {
                            i, 1, dims}];Which[way === Automatic, 
                      teststat = 
                        ((Plus@@Table[
                                  (((Plus@@(((#(1^3)&)/@
                                        𝕪[[i
                                        ]])/n)))^2), {i, 
                                    1, dims}] (n + 1) (n + 3))/(6
                               (n - 2))) + 
                          Plus@@Table[
                              (((((Plus@@(#((1^4)/n)&)/@
                                        𝕪[[i
                                        ]] - 
                                        ((3 (n - 1))/(n + 1))))^2) 
                                  ((((n + 1))^2) (n + 3) (n + 5))
                                    )/(24 (n (n - 2)) 
                                  (n - 3))), {i, 1, dims}]; , 
                      way === Omnibus, 
                      teststat = 
                        ((Plus@@Table[
                                  (((Plus@@
                                        (((#(1^3)&)/@
                                        𝕪[[i
                                        ]])/n)))^2), {i, 
                                    1, dims}] (n + 1) (n + 3))/(6
                               (n - 2))) + 
                          Plus@@Table[
                              (((((Plus@@(#((1^4)/n)&)/@
                                        𝕪[[i
                                        ]] - 
                                        ((3 (n - 1))/(n + 1))))^2) 
                                  ((((n + 1))^2) (n + 3) (n + 5))
                                    )/(24 (n (n - 2)) 
                                  (n - 3))), {i, 1, dims}]; , 
                      way === Skewness, 
                      teststat = 
                        ((Plus@@
                              Table[(((
                                    Plus@@
                                        (((#(1^3)&)/@
                                        𝕪[[i
                                        ]])/n)))^2), {i, 
                                  1, dims}] (n + 1) (n + 3))/(6 
                            (n - 2))); , way === Kurtosis, 
                      teststat = 
                        Plus@@Table[
                            (((((Plus@@(#((1^4)/n)&)/@
                                        𝕪[[i
                                        ]] - 
                                      ((3 (n - 1))/(n + 1))))^2) 
                                ((((n + 1))^2) (n + 3) (n + 5))
                                  )/(24 (n (n - 2)) 
                                (n - 3))), {i, 1, dims}]; ];({{ToString[way]<>"  Test Stat", "N for crit", "Crit.Value at "<>ToString[sig]}, {teststat, ntest, ALMCritPoint[ntest, sig, way, dims]}})],Message[multinormalTestStatistic::"nocrit"]],Message[multinormalTestStatistic::"notnum"]]

multinormalTestStatistic[(x_)?MatrixQ, opts___] := 
  If[And @@ (NumericQ[#1] & ) /@ Flatten[x], 
   If[Dimensions[x][[1]] < 6, 
    Module[{n, xbar, teststat, sig, ntest, way, 
      𝕊, 𝒮, 𝒢, 𝒟, 𝕪}, 
     way = Method /. {opts} /. 
        Options[multinormalTestStatistic]; 
     sig = Significance /. {opts} /. 
        Options[multinormalTestStatistic]; 
     n = N[Dimensions[x][[2]]]; 
     dims = Dimensions[x][[1]]; 
     ntest = If[n > 2000, Infinity, 
        {10, 20, 50, 100, 200, 800}[[Flatten[Position[Union[{10, 20, 50, 100, 200,800}, {n}], n]] - 1]][[1]]]; 
      xbar = (Mean[#1] & ) /@ x; 
      𝕊 = Table[x[[i]] - xbar[[i]], {i, 1, dims}] . 
       Transpose[Table[x[[i]] - xbar[[i]], {i, 1, dims}]]/n; 
      𝒢 = Transpose[Eigenvectors[𝕊]]; 
      𝒟 =  DiagonalMatrix[Eigenvalues[𝕊]]; 
𝒮 = 𝒢 .(Sqrt[#1] & ) /@ Inverse[𝒟] . 
        Transpose[𝒢]; 
      𝕪 = 
       𝒮 . 
        Table[x[[i]] - xbar[[i]], {i, 1, dims}]; 
      Which[way === Automatic, 
       teststat = 
         Plus @@ Table[(Plus @@ (#1^3 & ) /@ 𝕪[[i]]/n
)^2, {i, 1, dims}]*(n + 1)*(n + 3)/(6*(n - 2)) + 
          Plus @@ Table[(Plus @@ 
            (#1^4/n & ) /@ 𝕪[[i]] \
- (3*(n - 1))/(n + 1))^2*
             ((n + 1)^2*(n + 3)*(n + 5))/
              (24*n*(n - 2)*(n - 3)), {i, 1, dims}]; , 
       way === Omnibus, 
       teststat =  Plus @@ Table[(Plus @@ 
                 (#1^3 & ) /@ 𝕪[[i]]/n
)^2, {i, 1, dims}]*(n + 1)*(n + 3)/(6*(n - 2)) + 
          Plus @@ 
           Table[(Plus @@ 
                 (#1^4/n & ) /@ 𝕪[[i]] \
- (3*(n - 1))/(n + 1))^2*
             ((n + 1)^2*(n + 3)*(n + 5))/
              (24*n*(n - 2)*(n - 3)), {i, 1, dims}]; , 
       way === Skewness, 
       teststat = 
         Plus @@ 
           Table[(Plus @@ 
                (#1^3 & ) /@ 𝕪[[i]]/n)^2\
, {i, 1, dims}]*(n + 1)*(n + 3)/(6*(n - 2)); , 
       way === Kurtosis, 
       teststat = 
         Plus @@ 
          Table[(Plus @@ 
                (#1^4/n & ) /@ 𝕪[[i]] - 
               (3*(n - 1))/(n + 1))^2*
            ((n + 1)^2*(n + 3)*(n + 5))/
             (24*n*(n - 2)*(n - 3)), {i, 1, dims}]; ]; 
      TableForm[{{StringJoin[ToString[way], 
          "  Test Stat"], "N for crit", 
         StringJoin["Crit.Value at ", ToString[sig]]}, 
        {teststat, ntest, 
         ALMCritPoint[ntest, sig, way, dims]}}]], 
    Message[multinormalTestStatistic::nocrit]], 
   Message[multinormalTestStatistic::notnum]]

End the private context

On[General::spell]

End[ ]

Epilog

This section protects exported symbols and ends the package.

Protect exported symbol

Protect[ normalityTestStatistic, multinormalTestStatistic ]

End the package context

EndPackage[ ]

Examples, Tests

This reads in the package

Needs["EconGroup`NormalityTests`"]

testdata1 is a vector of uniformly distributed random numbers between zero and one. testdata2 is a 3-by-500 matrix of iid uniformly distributed random numbers. testdata3 is a vector of numbers drawn from the Normal(0,2) distribution. testdata4 is a 4 by 200 vector of iid Normal(0,2) random numbers. Therefore the tests should reject normality for testdata1 and testdata2, and not reject for testdata3 and testdata4.

testdata1 = Table[Random[], {500}];

testdata2  =  Table[Random[], {3}, {500}];

\(testdata3\  = \ Table[Random[NormalDistribution[0, 2]], {200}]; 
		
    testdata4\  = \ Table[Random[NormalDistribution[0, 2]], {4}, {200}]; \)

toobigdata  =   
      Table[Random[NormalDistribution[0, 2]], {8}, {50}];

normalityTestStatistic[testdata1, Method -> JarqueBera, 
      Significance -> 0.05]

normalityTestStatistic[testdata1, Method -> Urzua, Significance -> 0.01]

normalityTestStatistic[testdata3, Method -> Urzua, Significance -> 0.01]

multinormalTestStatistic[testdata2, Method -> Automatic, 
      Significance -> 0.9]

multinormalTestStatistic[testdata4, Method -> Automatic, 
      Significance -> 0.9]

multinormalTestStatistic[testdata2, Method -> Omnibus, 
      Significance -> 0.9]

multinormalTestStatistic[testdata4, Method -> Omnibus, 
      Significance -> 0.9]

multinormalTestStatistic[testdata2, Method -> Skewness, 
      Significance -> 0.9]

multinormalTestStatistic[testdata4, Method -> Skewness, 
      Significance -> 0.9]

multinormalTestStatistic[testdata2, Method -> Kurtosis, 
      Significance -> 0.9]

multinormalTestStatistic[testdata4, Method -> Kurtosis, 
      Significance -> 0.9]

multinormalTestStatistic[toobigdata, Method -> Kurtosis, 
      Significance -> 0.9]