{"id":958,"date":"2015-08-15T14:20:21","date_gmt":"2015-08-15T13:20:21","guid":{"rendered":"http:\/\/pcool.dyndns.org:8080\/statsbook\/?page_id=958"},"modified":"2025-07-02T23:34:00","modified_gmt":"2025-07-02T22:34:00","slug":"tests-for-normality","status":"publish","type":"page","link":"https:\/\/pcool.dyndns.org\/index.php\/tests-for-normality\/","title":{"rendered":"Tests for Normality"},"content":{"rendered":"\n<p>If we want to use a t-test to analyse our data, it is necessary to demonstrate the data are <a href=\"https:\/\/pcool.dyndns.org\/index.php\/normal-distribution\/\" data-type=\"page\" data-id=\"578\">Normally distributed<\/a>. Many tests for Normality have been described and it is not in the scope of this book to discuss them all. However, four different tests will be discussed:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Histogram<\/li>\n\n\n\n<li>Quantile-Quantile plots<\/li>\n\n\n\n<li>Shapiro-Wilk test<\/li>\n\n\n\n<li>Kolmogorov-Smirnov test<\/li>\n<\/ul>\n\n\n\n<p>Two data sets will be used in the discussion of all four Normality tests:<\/p>\n\n\n\n<p><a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/data_files\/height10.rda\" target=\"_blank\" rel=\"noreferrer noopener\">height10<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/data_files\/tibfracture10.rda\" target=\"_blank\" rel=\"noreferrer noopener\">tibfracture10<\/a><\/p>\n\n\n\n<p>After downloading the data, they can be shown in the R console by:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>height10$height<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp;&#91;1] 184 146 169 185 160 173 179 171 160 150<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>tibfracture10$healingtime<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp;&#91;1] 24 55 19 20 36 11 25 18 10 16&nbsp;<\/em><\/span><\/code><\/pre>\n\n\n\n<p>Descriptives can be obtained by:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f00a0a\" class=\"has-inline-color\">summary(height10$height)\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#1f0af0\" class=\"has-inline-color\">   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. \n  146.0   160.0   170.0   167.7   177.5   185.0 <\/mark><\/em>\n<span style=\"color: #ff0000;\"><em>sd(height10$height)<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&#91;1] 13.48291<\/em><\/span><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f00a0a\" class=\"has-inline-color\">\nsummary(tibfracture10$healingtime)\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#170af0\" class=\"has-inline-color\">   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. \n  10.00   16.50   19.50   23.40   24.75   55.00 <\/mark><\/em>\n<span style=\"color: #ff0000;\"><em>sd(tibfracture10$healingtime)<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&#91;1] 13.36829<\/em><\/span><\/code><\/pre>\n\n\n\n<p>The mean and median for height are close together (167.7 and 170 respectively), suggesting that the heights may conform a Normal distribution. However, the mean and median for the fracture healing times are further apart (23.4 and 19.5 respectively) making it less likely that these data can be modelled with a Normal distribution.<\/p>\n\n\n\n<p><strong>Graphical (histogram)<\/strong><\/p>\n\n\n\n<p>A quick and easy way to check if data conform a normal distribution is to plot a <a href=\"https:\/\/pcool.dyndns.org\/index.php\/histogram\/\" data-type=\"page\" data-id=\"538\">histogram<\/a>. This can be done in R with the hist() function:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#fc0606\" class=\"has-inline-color\">hist(height10$height)<\/mark><\/em><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"619\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/07\/histo_height-1024x619.jpeg\" alt=\"\" class=\"wp-image-4821\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/07\/histo_height-1024x619.jpeg 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/07\/histo_height-300x181.jpeg 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/07\/histo_height-768x464.jpeg 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/07\/histo_height-1536x929.jpeg 1536w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/07\/histo_height.jpeg 1692w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f40505\" class=\"has-inline-color\">hist(tibfracture10$healingtime)<\/mark><\/em><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"619\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/07\/hist_healing_time-1024x619.jpeg\" alt=\"\" class=\"wp-image-4822\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/07\/hist_healing_time-1024x619.jpeg 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/07\/hist_healing_time-300x181.jpeg 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/07\/hist_healing_time-768x464.jpeg 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/07\/hist_healing_time-1536x929.jpeg 1536w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/07\/hist_healing_time.jpeg 1692w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>It can be seen that neither histogram particularly looks like a bell shaped curve. The healing time histogram looks very right skew (mean larger than median). Although the height histogram doesn&#8217;t look like a bell shape, there are only 10 patients and with more patients it may become bell shaped.<\/p>\n\n\n\n<p><strong>Graphical normality test (quantile-quantile plot)<\/strong><\/p>\n\n\n\n<p>This graphical test is probably the easiest way to test for Normality. However, it is a graphical (visual assessment) test and a p value is not obtained. The method creates a plot from the ranked samples of our data against a similar number of ranked theoretical samples from a Normal distribution. If it shows a straight line, the data is consistent with a Normal distribution. Otherwise, if the data deviates from a straight line, the distribution is not Normal. <\/p>\n\n\n\n<p>In the R console enter:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>qqnorm(height10$height)<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>qqline(height10$height,lty=2)<\/em><\/span><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/qqlotheight-1024x768.png\" alt=\"\" class=\"wp-image-3548\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/qqlotheight-1024x768.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/qqlotheight-300x225.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/qqlotheight-768x576.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/qqlotheight.png 1355w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><a href=\"http:\/\/pcool.dyndns.org:8080\/statsbook\/wp-content\/uploads\/qqlotheight.png\"><\/a><\/p>\n\n\n\n<p>The first command creates the plot and the second command draws the reference line. The parameter &#8216;lty=2&#8217; is optional and creates a dotted line instead of an uninterrupted line. The data points on the qqplot are near enough the straight line and it is therefore reasonable to assume the data can be modelled with a Normal distribution.<\/p>\n\n\n\n<p>The same for the tibial fracture healing times:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>qqnorm(tibfracture10$healingtime)<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>qqline(tibfracture10$healingtime,lty=2)<\/em><\/span><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/qqplothealingtime-1024x768.png\" alt=\"\" class=\"wp-image-3549\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/qqplothealingtime-1024x768.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/qqplothealingtime-300x225.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/qqplothealingtime-768x576.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/qqplothealingtime.png 1355w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The second plot shows that the data points for tibial fracture healing time are deviating from the straight line. The fracture healing time therefore does not conform a Normal distribution (using the quantile-quantile plot method).<\/p>\n\n\n\n<p><strong>Shapiro-Wilk Normality test<\/strong><\/p>\n\n\n\n<p>The Shapiro-Wilk test estimates if data are consistent with a normal distribution. It is particular useful in smaller sample sizes (&lt;2000). The null hypothesis is that the data are consistent with a normal distribution. The alternate hypothesis is that the data are not normally distributed.<\/p>\n\n\n\n<p>To perform a  Shapiro-Wilk test in R:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>shapiro.test(height10$height)<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp;&nbsp; &nbsp;Shapiro-Wilk normality test<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>data:&nbsp; height10$height<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>W = 0.9444, p-value = 0.6033<\/em><\/span>\n\n<span style=\"color: #ff0000;\"><em>shapiro.test(tibfracture10$healingtime)<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp;&nbsp; &nbsp;Shapiro-Wilk normality test<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>data:&nbsp; tibfracture10$healingtime<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>W = 0.8396, p-value = 0.04361<\/em><\/span><\/code><\/pre>\n\n\n\n<p>The p-value of the Shapiro-Wilk test for the height variable is 0.603 and not statisticall significant. Therefore, there is no reason to reject the <a href=\"https:\/\/pcool.dyndns.org\/index.php\/hypothesis\/\" data-type=\"page\" data-id=\"942\">null hypothesis<\/a> and it is concluded that it is reasonable to regard the height data as Normally distributed.<\/p>\n\n\n\n<p>However, the p-value for the healing time is 0.044, which is significant. Therefore, the null hypothesis is rejected in favour of the alternate hypothesis. It is concluded the data can&#8217;t be modelled with a Normal distribution. Consequently, the t-test should not be used for analysis, but <a href=\"https:\/\/pcool.dyndns.org\/index.php\/non-parametric-tests\/\" data-type=\"page\" data-id=\"594\">non-parametric analysis<\/a> should be used instead.<\/p>\n\n\n\n<p><strong>Kolmogorov-Smirnov Normality test<\/strong><\/p>\n\n\n\n<p>The Kolmogorov-Smirnov \u2018goodness to fit\u2019 test examines whether two datasets differ significantly. It makes no assumption on the distribution of the data and is technically speaking a non-parametric test. It can also be used to demonstrate that the data fit other distributions (outside the scope of this book). However, because the Kolmogorov-Smirnov test is more general, it tends to be less powerful (larger numbers are required to note a difference). The test is especially useful in larger sample sizes (&gt; 50). The null hypothesis is that the data follow the specified distribution and the alternate hypothesis is that the data are not from the same distribution. To test whether the height data conform a Normal distribution, enter in the command window:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f60505\" class=\"has-inline-color\">ks.test(height10$height,\"pnorm\",mean=mean(height10$height),sd=sd(height10$height))\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#1305f5\" class=\"has-inline-color\">\n\tAsymptotic one-sample Kolmogorov-Smirnov test\n\ndata:  height10$height\nD = 0.13841, p-value = 0.9909\nalternative hypothesis: two-sided\n\nWarning message:\nIn ks.test.default(height10$height, \"pnorm\", mean = mean(height10$height),  :\n  ties should not be present for the one-sample Kolmogorov-Smirnov test<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>The Kolmogorov-Smirnov test compares the height data with a Normal distribution (&#8220;pnorm&#8221;) that has a mean and standard deviation that is the same as the height data (mean =mean(height10$height) and sd=sd(height10$height)). The p -value is 0.9909 and there is no reason to reject the null hypothesis (there is no difference between the height data and a Normal distribution with the same mean and standard deviation). It can be concluded that the height conforms a Normal distribution using the Kolmogorov-Smirnov test.<\/p>\n\n\n\n<p>The output does state that a correct p-value can&#8217;t be computed with ties (the same values in the data). This is because two of the ten patients have a height of 160 cm. This can easily be overcome by introducing a greater precision into the data<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>height=c(184,146,169,185,160,173,179,171,<strong>160.001,<\/strong>150)<\/em><\/span><\/code><\/pre>\n\n\n\n<p>Now, the test gives a more accurate p-value:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">ks.test(height,\"pnorm\",mean=mean(height),sd=sd(height))<\/span><\/em>\n<span style=\"color: #0000ff;\"><em>&nbsp;&nbsp; &nbsp;One-sample Kolmogorov-Smirnov test<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>data:&nbsp; height<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>D = 0.1384, p-value = 0.9769<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>alternative hypothesis: two-sided<\/em><\/span><\/code><\/pre>\n\n\n\n<p class=\"is-style-text-annotation is-style-text-annotation--1\">Please note that a new variable height has been declared that is different from the height variable in the height10 data frame. As a result, only height is entered as argument for the function and not height10$height.<\/p>\n\n\n\n<p>To test the fracture healing time data with the Kolmogorov-Smirnov test:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>ks.test(tibfracture10$healingtime,\"pnorm\",mean=mean(tibfracture10$healingtime),sd=sd(tibfracture10$healingtime))<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp;&nbsp; &nbsp;One-sample Kolmogorov-Smirnov test<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>data:&nbsp; tibfracture10$healingtime<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>D = 0.2524, p-value = 0.4723<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>alternative hypothesis: two-sided<\/em><\/span><\/code><\/pre>\n\n\n\n<p>On the basis of the Kolmogorov-Smirnov test, the null hypothesis (there is no difference between the healing time data and a Normal distribution with a the same mean and standard deviation) can&#8217;t be rejected. It may be concluded that the data can be reasonably modelled with a Normal distribution. However, the graphical method and the Shapiro-Wilk test have shown that the healing time is <em>does not  <\/em>conform a Normal distribution. This illustrates the lesser <a href=\"https:\/\/pcool.dyndns.org\/index.php\/power-analysis\/\" data-type=\"page\" data-id=\"597\">statistical power <\/a>of the Kolmogorov-Smirnov test, especially in smaller sample sizes.<\/p>\n\n\n\n<p>Overall, it can be concluded that it is reasonable to model height with a Normal distribution, but not the healing time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If we want to use a t-test to analyse our data, it is necessary to demonstrate the data are Normally distributed. Many tests for Normality have been described and it is not in the scope of this book to discuss them all. However, four different tests will be discussed: Two data sets will be used [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"footnotes":""},"class_list":["post-958","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/comments?post=958"}],"version-history":[{"count":7,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/958\/revisions"}],"predecessor-version":[{"id":4829,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/958\/revisions\/4829"}],"wp:attachment":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/media?parent=958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}