File Exchange

## DagosPtest

version 1.1.0.0 (4.81 KB) by
D'Agostino-Pearson's K2 test for assessing normality of a data vector.

Updated 07 Apr 2015

The D'Agostino-Pearson's K2 test is used to assessing normality of data using skewness and kurtosis. It approximates to the chi-squared distribution.
File needs to input the data vector and significance level (default = 0.05).
It outputs whether or not the normality is met.

### Cite As

Antonio Trujillo-Ortiz (2021). DagosPtest (https://www.mathworks.com/matlabcentral/fileexchange/3954-dagosptest), MATLAB Central File Exchange. Retrieved .

BBB

I wanted to ask a question. Is the Probability associated to the chi-squared statistic the p value?

Hi Todd. For a little more than two years I retired from all academic activity. I hope you find the help you need. Antonio.

Hiroshige Tateuchi

Hello, thank you for the code!!

I'm writing with a bug. The 200-value dataset below --- from a bimodal distribution --- yields a complex value for K2, because the L variable is negative. Is there a way to fix this problem?

Todd

[ 3.97389943, 3.16068114, 3.98833321, 3.35038539, 2.77199624,
3.1077107 , 3.52312816, 5.64458375, 2.35542437, 1.57573701,
0.64938706, 2.90495361, 0.65648373, 5.45746016, 2.58102509,
4.43263097, 2.31778133, 4.09786433, 3.66600081, 3.03726854,
1.99794933, 2.8566434 , 3.00864345, 4.00493716, 1.66809816,
2.42671159, 4.99226061, 3.19865979, 1.8498399 , 0.6151846 ,
2.40865147, 4.60087687, 4.39677856, 4.42335974, 3.92638335,
1.99179439, 5.48816136, 4.71786629, 1.91116912, 3.13267449,
1.84710365, 3.52914397, 3.32374005, 3.1147915 , 4.30585716,
3.65099521, 4.32068054, -0.51442025, 3.34922318, 4.4689909 ,
3.43892549, 0.09896518, 2.79696348, 4.66440582, 4.09646735,
4.25016972, 2.27763863, 3.28082617, 3.94789255, 3.3893917 ,
3.57914279, 4.3107011 , 1.99523046, 4.62824664, 3.74195928,
1.50797281, 2.29775577, 2.20766288, 4.34811905, 3.46836402,
2.57359717, 3.20909017, -2.12562798, 2.33463267, 4.97852651,
1.63774949, 2.5620736 , 1.99396633, 4.54322929, 2.90947618,
0.5564791 , 0.74696893, -0.15852687, 2.49151113, 1.93833968,
-1.41699101, 2.13826813, 2.10699096, 2.37207834, 4.21897697,
1.59090651, 4.25715994, 2.76794402, 2.98965625, 2.12238363,
1.18487667, 2.11005505, 4.4641077 , 1.14986732, 1.5784762 ,
-5.28431647, -2.48295135, -1.57683531, -3.68614225, -1.29540564,
-3.38919883, -1.76293987, -3.42984066, -3.53213455, -2.11187911,
-2.50970838, -2.07815081, -4.43436471, -4.1746416 , -2.68480796,
-1.39397889, -1.34851402, -3.21028088, -2.17297144, -1.66198832,
-1.53895371, -5.8585136 , -3.73792837, -2.31305216, -2.73864316,
-3.59356803, -3.4520476 , -4.18196063, -3.42639527, -2.47755227,
-2.27373851, -1.59324474, -3.96791213, -2.23059505, -2.83465777,
-3.6976041 , -3.99348538, -4.32623854, -1.15255561, -2.77765984,
-3.22229936, -2.03070137, -3.89218256, -1.32159805, -2.90011379,
-2.12382029, -2.25277091, -3.16355575, -3.55434774, -4.5809681 ,
-2.69795222, -2.06408374, -2.35524068, -2.27334046, -3.89458656,
-2.80865827, -3.47869569, -2.58285887, -3.38174965, -3.03123007,
-3.9723663 , -4.15958181, -4.04648105, -2.79884217, -3.59059149,
-0.221248 , -4.64314158, -3.89780181, -2.74902277, -4.02168698,
-2.02231024, -2.81402882, -4.0043932 , -2.21048121, -2.67549988,
-2.20535117, -3.49105581, -2.48079388, -4.31722891, -1.85643216,
-1.73262851, -3.18202607, -2.06526767, -2.19015497, -2.11280065,
-1.07797387, -1.25632177, -2.76799184, -3.42492089, -1.60443977,
-4.69284698, -2.93814968, -3.76315288, -3.11308936, -4.5720642 ,
-2.48791319, -2.61938611, -3.04664167, -0.97634754, -0.61795901]

Hi Alessandro,

Thank you for your interest in our files and for your question. In fact, despite not calling the value of kurtosis, but only skewness, the machine was written for the user who wanted to consult it and be useful for any other procedure.

Antonio

Alessandro Masullo

Hi,
Why is the measurement of the kurtosis, saved in the variable eg2, not used in the function?

Dear A.M. Winkler. Thanks for your valuable comment to improve this code. It was taken into account, and the bug was removed.

Antonio Trujillo-Ortiz

A. M. Winkler

Hi,

This is a nice tool. However, I'm afraid there may be a small, but important error in the code. On the expression that defines H, line 117:

H = ((n-2)*(n-3)*abs(g2))/((n+1)*(n-1)*sqrt(G));

H = ((n-2)*(n-3)*g2)/((n+1)*(n-1)*sqrt(G));

There is no need to use abs() here, as it will remove the sign and make the test produce incorrect results in approximately 50% of the cases.

If in doubt, please see the Equation 16 on D'Agostino RB, Belanger A & D'Agostino Jr RB, 1990. The American Statistician, 44(4), pp.316-21, and also the Equation 4 on D'Anscombe FJ & Glynn WJ, 1983. Biometrika, 70(1), p.227-34. This second paper is where the actual equation is coming from.

The correct results for your example are, therefore, K^2 = 4.3931, with a p-value of 0.1112.

Hope this helps!

A.

Joseph Boomer

Thanks for implementing this function. it helped me a lot.

Leandro Navarro Pablo

Thanks a lot. I have implemented it in my scripts and works nicely.

enrique buendia

is x2=2.284957205
not x2=3.1397

C Lynam

Works perfectly. nb, Calls on a few other files such as chi2cdf, distchck and chi2test.

Faraaz Yusufi

I read about this test in Zar's book and wanted to use it in matlab. Thanks for implementing this in matlab, it works fine and is very useful.

##### MATLAB Release Compatibility
Created with R11
Compatible with any release
##### Platform Compatibility
Windows macOS Linux