  {"id":3292,"date":"2023-01-02T14:40:00","date_gmt":"2023-01-02T13:40:00","guid":{"rendered":"https:\/\/www.gironi.it\/blog\/?p=3292"},"modified":"2024-10-17T14:43:40","modified_gmt":"2024-10-17T13:43:40","slug":"non-parametric-tests-the-wilcoxon-test-for-non-normal-data","status":"publish","type":"post","link":"https:\/\/www.gironi.it\/blog\/en\/non-parametric-tests-the-wilcoxon-test-for-non-normal-data\/","title":{"rendered":"Non-Parametric Tests: The Wilcoxon Test for Non-Normal Data"},"content":{"rendered":"\n<p>The <strong>Wilcoxon test<\/strong> is a <strong><a href=\"https:\/\/www.gironi.it\/blog\/test-statistici-parametrici-e-non-parametrici\/\" target=\"_blank\" data-type=\"post\" data-id=\"2306\" rel=\"noreferrer noopener\">non-parametric test<\/a><\/strong> used to compare two independent samples, or a sample with a known reference value. <br><strong>The test is used when the data do not follow a <a href=\"https:\/\/www.gironi.it\/blog\/la-distribuzione-normale\/\" target=\"_blank\" data-type=\"post\" data-id=\"916\" rel=\"noreferrer noopener\">normal distribution<\/a>, or when the distribution parameters are unknown.<\/strong><\/p>\n\n\n<!--more-->\n\n\n<p>The Wilcoxon test involves <strong>ranking the data from both samples<\/strong>, and then <strong>assigning a score to each value based on its position in the ranking<\/strong>. The scores are then summed for each sample, and the difference between the sum of scores of the two samples is compared to a known reference value, using the Wilcoxon distribution. <br>Based on the result of the comparison, one can decide whether to accept or reject the null hypothesis.<\/p>\n\n\n<p>The Wilcoxon test is often used to compare the values of a continuous variable between two groups. There is also a version of the test called the Wilcoxon-Mann-Whitney test, which is used when comparing two groups with an ordinal or categorical variable.<\/p>\n\n\n<h2 class=\"wp-block-heading\">A Practical Example of the Wilcoxon Test in R<\/h2>\n\n\n<p>In this example, I will generate sample data for two groups, <code>group1<\/code> and <code>group2<\/code>, using the <code>rnorm()<\/code> function to generate random numbers that follow a normal distribution with a mean of 100 and standard deviation of 15 for the first group, and a mean of 110 and standard deviation of 15 for the second group.<\/p>\n\n\n<p>I use the wilcox.test() function to perform the Wilcoxon test, and specify the alternative hypothesis as &#8220;<em>two.sided<\/em>&#8221; to test whether the two groups have significantly different means.<\/p>\n\n\n<p>The test results are printed on the screen and include the test statistic value, the p-value, and the test conclusion. Based on the p-value, one can decide whether to accept or reject the null hypothesis.<\/p>\n\n\n<pre class=\"wp-block-preformatted\"># Create sample data\nset.seed(123)\ngroup1 &lt;- rnorm(100, mean = 100, sd = 15)\ngroup2 &lt;- rnorm(100, mean = 110, sd = 15)\n\n# Perform the Wilcoxon test\nwilcox_test &lt;- wilcox.test(group1, group2, alternative = \"two.sided\")\n\n# Display the test results\nprint(wilcox_test)\n<\/pre>\n\n\n<p class=\"has-light-gray-background-color has-background\">The most commonly used significance level is 5% or 0.05. This means that a threshold of 5% is established, above which the observed effect is considered random, and below which the observed effect is considered statistically significant. In other words, if the p-value obtained from the test is less than 0.05, the null hypothesis is rejected, and it is concluded that there is a significant difference between the samples.<\/p>\n\n\n<p>It&#8217;s important to note that these threshold values are conventional and can be modified based on the specific needs of the study or the discipline in which one is working.<\/p>\n\n\n<h2 class=\"wp-block-heading\">Resources for Further Study<\/h2>\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.datanovia.com\/en\/lessons\/wilcoxon-test-in-r\/\" target=\"_blank\" rel=\"noreferrer noopener\">Wilcoxon Test in R &#8211; Datanovia<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.investopedia.com\/terms\/w\/wilcoxon-test.asp\" target=\"_blank\" rel=\"noreferrer noopener\">Wilcoxon Test: Definition in Statistics, Types, and Calculation &#8211; Investopedia<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The Wilcoxon test is a non-parametric test used to compare two independent samples, or a sample with a known reference value. The test is used when the data do not follow a normal distribution, or when the distribution parameters are unknown.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[161],"tags":[1208,301],"class_list":["post-3292","post","type-post","status-publish","format-standard","hentry","category-statistics","tag-non-parametric-test","tag-wilcoxon"],"lang":"en","translations":{"en":3292,"it":2655},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"paolo","author_link":"https:\/\/www.gironi.it\/blog\/author\/paolo\/"},"uagb_comment_info":70,"uagb_excerpt":"The Wilcoxon test is a non-parametric test used to compare two independent samples, or a sample with a known reference value. The test is used when the data do not follow a normal distribution, or when the distribution parameters are unknown.","_links":{"self":[{"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/posts\/3292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/comments?post=3292"}],"version-history":[{"count":1,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/posts\/3292\/revisions"}],"predecessor-version":[{"id":3293,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/posts\/3292\/revisions\/3293"}],"wp:attachment":[{"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/media?parent=3292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/categories?post=3292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/tags?post=3292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}