Nonparametric Testing in Excel PDF
Nonparametric Testing in Excel PDF
Nonparametric Testing
in Excel
The Excel Statistical Master
By Mark Harmon
Copyright 2011 Mark Harmon
No part of this publication may be reproduced
or distributed without the express permission
of the author.
[email protected]
www.ExcelMasterSeries.com
ISBN: 978-0-9833070-4-4
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 1
Table of Contents
(Click On Chapters To Go To Them)
Nonparametric Tests - When To Use Them.6
The Mann-Whitney U Test Done in Excel..7
Step 1 - Combine all samples into 1 group.8
Step 2 - Rank All Samples...9
Step 3 - Put Samples Back In Original Groups.9
Step 4 - Count the Rankings For Each Group.10
Step 5 - Calculate the U Statistic.10
Step 6 - Calculate the Mean, U , and Standard Deviation, U..11
Step 7 - Calculate the Z Score..11
Step 8 - Compare this Z Score to Z Critical..11
The Kruskal-Wallis Test - Done in Excel..12
Step 1 - Combine all samples into 1 group..13
Step 2 - Rank All Samples.14
Step 3 - Put samples back in original groups.15
Step 4 Calculate the Following Metrics.16
Step 6 Calculate H Critical..17
The Wilcoxon Rank Sum Test.18
Test Procedures in Excel..19
Wilcoxon Rank Sum Test for Small Samples in Excel..20
Step 1 - Count the samples in Each Group..21
Step 2 - Rank all samples according to sample size in Excel.21
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 2
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 3
Step 1 - Calculate Differences Between Before and After Data For Each Pair...45
Step 2 - Take the Absolute Value of that Difference..46
Step 3 - Rank of the Differences and Record the Sign of Each Difference.47
Step 4 - Combine the Rank of Each Difference With the Sign of the Difference48
Step 5 - Calculate the Test Statistic W..48
Wilcoxon Signed-Rank Test in Excel For Large Samples50
1) Before and After Sales Data52
2) Calculate Differences Between Before and After Data For Each Pair..53
3) Calculate the Absolute Value of the Difference and Then the Rank and Sign of that Difference.54
4) Combine the Rank and Sign of Each Difference55
5) Calculate the Sums of All Ranks56
6) Calculate the Test Statistic W.57
Calculate the Z Score for Test Statistic T.57
Calculate the p Value That Corresponds With That Z Score...59
Statistical Mistakes You Dont Want To Make.61
1) Assuming that correlation equals causation..61
2) Not graphing and eyeballing the data prior to performing regression analysis61
3) Not doing correlation analysis on all variables prior to performing regression...61
4) Adding a large number of new input variables into a regression analysis all at once62
5) Applying input variables to a regression equation that are outside of the value of the original input
variables that were used to create the regression equation62
6) Not examining the residuals in regression..62
7) Only evaluating r square in a regression equation62
8) Not drawing a representative sample from a population.63
9) Drawing a conclusion without applying the proper statistical analysis..63
10) Drawing a conclusion before a statistically significant result has been reached..63
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 4
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 5
Nonparametric tests are often used as shortcut replacements for more complicated parametric tests. You can
usually get a quick answer that requires little calculation by running a nonparametric test.
Nonparametric tests are often used when the data is ranked but cannot be quantified. For example, how would
you quantify consumer rankings such as very satisfied, moderately satisfied, just satisfied, less than satisfied,
dissatisfied?
Nonparametric tests can be applied when there are a lot of outliers that might skew the results. Nonparametric
tests often evaluate medians rather than means and therefore if the data have one or two outliers, the outcome
of the analysis is not affected.
Nonparametric tests come in especially handy when dealing with non-numeric data, such as having customers
rank products or attributes according to preference.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 6
Procedures
Objective: To determine if these two groups come from different populations
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 7
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 8
Step 2 - Rank All Samples. Sort the sample by the value of each sample and rank them
in order of sample value.
Step 3 - Put Samples Back In Original Groups Sort by the A and B column
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 9
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 10
U = N1 * N2 / 2 = 24.5
U = SQRT [ ( N1 * N2 * ( N1 + N2 + 1) ) / 12 ] = 7.826
Rule
The Result if Significant If | Z Score | > | Z Critical |
So The Result Is Not Statistically Significant and We Cannot State With 95% Certainty That There is a
Difference Between The Two Groups for Either a One-Tailed Test Or a Two-Tailed Test.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 11
Procedures
Objective: To determine if these three groups come from different populations
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 12
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 13
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 14
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 15
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 16
Rule
The Result if Significant If H Statistic > H Critical
In This Case, H Statistic > H Critical
So The Result Is Statistically Significant and We Can State Within 95% That There is Difference Between
The Groups, Or, Equivalently, They Come From Different Populations.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 17
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 18
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 19
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 20
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 21
Step 3 - Combine All Samples and Rank Them. If any samples have the same
values, assign them the rank that would be the average of the two ranks if they weren't equal.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 22
Step 5 - Calculate the Sum of the Ranks (N1 and N2) For Each
Sample Group
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 23
Step 7 - Use the Wilcoxon Rank Sum Small Sample Chart to Evaluate R to
Determine Whether R Falls Within or Outside the Lower and Upper Critical
Values for the Given n1 and n2:
Below is the chart that is referenced. The green cells represent the n1, n2, and upper and lower limits for that
n1 and n2.
The chart on the previous page is a standard Critical Value chart for the Wilcoxon Small Sample Rank Sum
Test.
If R = 40, N1 = 7, and N2 = 6, then R is between the upper and lower critical values for both = 0.025 (Critical
Values = 28 and 56) and = 0.05 (Critical Values = 30 and 54). That is shown on the above chart.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 24
We therefore do not reject the Null Hypothesis, which states that there is no difference between the two sample
groups.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 25
Problem: We have collected sales data from the last 14 Tuesdays and the last 12 Wednesdays. We want to
determine if Tuesday sales have been different from Wednesday sales over the last month and a half. Calculate
with at least 95% certainty whether there is a difference between the two groups.
The data in either group does not appear to be normally distributed. In this case we will have to use a
nonparametric test to determine whether the groups are different. The Wilcoxon Rank Sum Test for Large
Samples is ideal for this situation.
For large samples, you will calculate n1, n2, N1, N2, and R as before.
Here are the data samples for each of the two groups:
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 26
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 27
Step 3 - Combine All Samples and Rank Them. If any samples have the same
values, assign them the rank that would be the average of the two ranks if they weren't equal.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 28
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 29
Step 5 - Calculate the Sum of the Ranks (N1 and N2) For Each
Sample Group
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 30
Z Score Calculation
Calculate r and r
r = [ n1 * ( n1 + n2 + 1 ) ] / 2
r = SQRT [ ( n1 * n2 * ( n1 + n2 + 1 ) ) / 12 ]
r = [ 14 * ( 14 + 12 + 1 ) ] / 2 = 189
r = SQRT [ ( 14 * 12 * ( 14 + 12 + 1 ) ) / 12 ]
Copyright 2011
= 19.44
http://excelmasterseries.com/New_Manuals.php
Page 31
Calculate Z Critical
Zcrit = NORMSINV ( 1 - / 2 ) For example, for = 0.05 and two-tailed test
Rule
Reject H0 if | Z | > | Z Critical | for the given and correct number of tails
In this case, |Z| is less than | Z Critical | so we do not reject the Null Hypothesis. We state that we are 95%
certain that the two sample groups were taken from the same population.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 32
Procedures
Objective: To determine if there is a correlation between these two sets of numbers:
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 33
Step 2 - Calculate the Difference Between Ranks 1 and 2, and Then Square
That Difference.
(d^2) = 18
n = Number of Samples = 7
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 34
0.6786
Rule:
rs is statistically significant if the following p Value is less than :
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 35
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 36
Step 2 - Sort Both Columns By the Original Data Column (Right Column)
and Assign a Numerical Rank (New Left Yellow-Highlighted Column)
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 37
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 38
Procedures
Objective: To determine whether Before and After data are different.
Small samples - less than 25 samples
For Case 1 above, in the event of testing to determine whether a population median is equal to, less than, or
greater to a specific number, subtract the sample from the fixed number.
For Case 2 above, in the event of testing to determine whether there is a difference between before and after
measurements, subtract the before-measurement from the after-measurement.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 39
Small Sample Exercise: Determine Whether the Before and After Data is Different:
Here is the original Before and After Data:
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 40
Step 1 - Take the Difference Between Each Before and After Data Point.
Step 2 - Record Whether That Difference Is Positive or Negative.
Step 3 - Record the Total Number of Positive and Negative Results.
The p value is the total area under the outer 2 tails in a 2-tailed test
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 41
Rule
The Result is Significant if p Value <
If 95% certainty is required, then = 0.05
In This Case, the Result Is Significant and We Can State That There Is a Difference Between the Before
and After Numbers.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 42
Rule
The Result if Significant If | Z Score | > | Z Critical |
For Example:
X=3
N=9
Z Score = [ (X + 0.5 ) (N 2) ] / [ SQRT(N) / 2 ] = -2.33
If We Require a 95% Degree of Certainty, Then = 0.05
For a one-tailed test, Z Critical = NORMSINV() = -1.64
For a two-tailed test, Z Critical = NORMSINV(/2) = -1.96
In this case, we can state with at least 95% certainty that the result is significant and that there is a
difference between Before and After data for both the one-tailed and two-tailed tests.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 43
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 44
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 45
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 46
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 47
Step 4 - Combine the Rank of Each Difference With the Sign of the
Difference
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 48
Rule
Reject the Null Hypothesis if Test Statistic W is greater than or equal to W Critical
Below is a standard chart containing W Critical Values we need:
W Critical for n = 9 (9 pairs of sample data) for a one-tailed test in which alpha = 0.05 equals 8.
Since Test Statistics W (1) is less than W Critical (8), we reject the Null Hypothesis and state with at least 95%
certainty that adding a bonus eBook to the offering on each landing page does increase the average sales from
each landing page.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 49
Wilcoxon Signed-Rank
Test in Excel for
Large Samples
The Wilcoxon Signed-Rank Test is used as an alternate to the Paired Student's t Test when the underlying
population cannot be determined to be normally distributed. This test is used to determine whether there is a
difference between paired samples. The most widely used application of the Wilcoxon Signed-Rank Test is to
determine whether there really is a difference between before and after data. In this article, we will show how to
use the Wilcoxon Signed-Rank Test in Excel to determine whether sales really did increase across a group of
landing pages after a free bonus was added to the offer on each landing page.
Unlike another similar nonparametric test - the Paired Sample Sign Test - this test considers the magnitude of
differences between the paired samples.
The Wilcoxon Signed-Rank Test is performed very differently for large samples than it is for small
samples. Large samples mean sample groups with more than 30 pairs of sample data.
The Null Hypothesis for the Wilcoxon Signed-Rank Test states that there is no difference between the paired
samples. For example, this Null Hypothesis might state that there is no difference between before and after
data, if each pair represents a before and after measurement of one sampled object.
The Alternate Hypothesis states that there is a difference between the paired samples.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 50
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 51
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 52
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 53
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 54
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 55
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 56
Since sample size is greater than 30, the distribution of Test Statistic T can be approximated by the
Normal Distribution.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 57
The Mean of the Normal Distribution curve used to estimate the distribution of Test Statistic W (W) is
determined by the Null Hypothesis. The Null Hypothesis states that there is no difference between the before
and after sales. Put another way, the Null Hypothesis states that the difference between the before and after
sales equals zero. Therefore the mean of Test Statistic W and the Normal Distribution curve that is used to
approximate its distribution also equals zero. So;
W = 0
The standard deviation of Test Statistic W and therefore of the Normal Distribution curve that is used to
approximate the distribution of Test Statistic W is found by the following formula:
n equals the number of before-and-after pairs of sample data whose difference does not equal zero. In this
case n = 32.
W can be derived from the fact that for any particular value of n, it can be shown that
Since n = 32
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 58
We can now map the Normal Distribution curve that is used to approximate the distribution of Test Statistic W
as follows:
0.5)
/ W
The Z Score above includes a continuity correction, to account for the fact that we use a continuous probability
function (the Normal Distribution) and our test value is based on discrete (ordinal, ranked) data. If the difference
W - W is negative the continuity correction is +0.5 (this is the case when W is less than; W). If the difference
W - W is positive the correction is -0.5 (this is the case when W is greater than W).
Z Score = ( W -
0.5)
/ W
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 59
Rule:
Reject the Null Hypothesis if the p Value Test Statistic W is less than , which is the Level of
Significance.
Since we require 95% certainty in our test, = 0.05.
We do not reject the Null Hypothesis in this case because the p Value of Test Statistic W is significantly greater
than .
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 60
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 61
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 62
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 63
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 64
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 65
A statistical theory called the Central Limit Theory states that the means of samples (at least 30 samples and
each sample having at least 2 data points that are averaged to get a mean, which will be the value of the
sample) will be Normally distributed, no matter how the underlying population is distributed. You can then
perform statistical analysis on that group using the normal distribution-based techniques.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 66
2) Data has been affected by more than one process It is very important to
understand all of the factors that can affect data sample measurement. Variations to process inputs might skew
what would otherwise be normally-distributed output data. Input variation might be caused by factors such as
shift changes, operator changes, or frequent changes in the underlying process. A common symptom that the
output is being affected by more than one process is the occurrence of more than one mode (most commonly
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 67
occurring value) in the output. In such a situation, you must isolate each input variation that is affecting the
output. You must then isolate the overall effect which that variation had on the output. Finally, you must remove
that input variations effect from output measurement. You may find that you now have normally-distributed
data.
3) Not enough data A normal process will not look normal at all until enough samples have been
collected. It is often stated that 30 is the where a large sample starts. If you have collected 50 or fewer
samples and do not have a normally-distributed sample, collect at least 100 samples before re-evaluating the
normality of the population from which the samples are drawn.
4) Measuring devices that have poor resolution Devices with poor resolution
may round off incorrectly or make continuous data appear discrete. You can, of course, use a more accurate
measuring device. A simpler solution is to use a much larger sample size to smooth out sharp edges.
6) Data approaching zero or a natural limit If the data has a large number of
value than are near zero or a natural limit, the data may appear to be skewed. In this case, you may have to
adjust all data by adding a specific value to all data being analyzed. You need to make sure that all data being
analyzed is raised to the same extent.
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 68
Copyright 2011
http://excelmasterseries.com/New_Manuals.php
Page 69