The Kruskal-Wallis Test is a popular nonparametric test to examine whether two samples originate from an identical distribution or not. A normal distribution is not assumed, and the groups in question may have different sample sizes. Thus, this test is used when the assumptions of ANOVA have not been met. In this particular example, we choose to divide our sample into two separate populations:
- Stocks that do not pay dividends; denoted by a number 0.
- Stocks that pay dividends; denoted by a number 1.
In addition to categorising by dividends, we also wish to take into account each observation’s stock return and market capitalisation. Our null and alternative hypotheses are as follows:
Null Hypothesis:
Samples are assumed to originate from the same distribution.
Alternative Hypothesis:
Samples are assumed to originate from different distributions.
In running the Kruskal-Wallis Test, we are looking to see if stock returns and market capitalisation have identical or different distributions across companies that pay dividends versus companies that do not pay dividends. To run the Kruskal-Wallis Test in R Studio, we first import our txt. dataset entitled “ols_stock.csv” by selecting “Tools” -> “Import Dataset” -> “From Text File”:
We then use the kruskal.test() command to compare our respective variables using the above criteria.
When comparing the distributions for stock returns and market capitalisation across our two groups of stocks, we see that we have a very low p-value in both cases that is highly significant at the 5% level.
> kruskal.test(stock_return ~ dividend, data = ols_stock) Kruskal-Wallis rank sum test data: stock_return by dividend Kruskal-Wallis chi-squared = 36, df = 1, p-value = 1.973e-09 > > kruskal.test(marketcap ~ dividend, data = ols_stock) Kruskal-Wallis rank sum test data: marketcap by dividend Kruskal-Wallis chi-squared = 29.378, df = 1, p-value = 5.955e-08
Therefore, we reject the null hypothesis as the findings support that the underlying distributions across both groups are significantly different. Therefore, the Kruskal-Wallis test indicates that stock returns and the market capitalisation of stocks that pay dividends are statistically different from the ones that do not.