Tuesday, February 27, 2018

(R) Wilcox Signed Rank Test (SPSS)

In this entry, we will be learning how to utilize the Wilcox Signed Rank Test. This article is the first article in a series of articles which will discuss non-parametric tests.

What is a non-parametric test?

A non-parametric test is a method of analysis which is utilized to analyze sets of data which do not comply with a specific distribution type. As a result of such, this particular type of test is by design, more robust.

Many tests require as a prerequisite, that the underlying data be structured in a certain manner. However, typically these requirements do not significantly cause test results to be adversely impacted, as many tests which are parametric in nature, have a good deal of robustness included within their models.

Therefore, though I believe that it is important to be familiar with tests of this particular type, I would typically recommend performing their parametric alternatives. The reason for this recommendation relates to the general acceptance and greater familiarity that the parametric tests provide.

Wilcox Signed Rank Test

The Wilcox Signed Rank Test provides a non-parametric alternative to both the One Sample Student’s T-Test, and the Paired Student’s T-Test. This test, shares a particular commonality with the other non-parametric tests which will be discussed in later articles, in that, it utilizes a ranking system to increase the robustness of measurements. The test is named for Frank Wilcoxon, the chemist and statistician who initially derived it.

Wilcox Signed Rank Test (One Sample)

Example:

A factory employee believes that the cakes produced within his factory are being manufactured with excess amounts of corn syrup, thus altering the taste. 10 cakes were sampled from the most recent batch and tested for corn syrup composition. Typically, each cake is measured to contain a median value of 20% corn syrup. Utilizing a 95 % confidence interval, can we assume that the new batch of cakes contain more than a median measurement of 20% corn syrup?

The levels of the samples were:

.27, .31, .27, .34, .40, .29, .37, .14, .30, .20

Our hypothesis test will be:

H0: m = .2
HA: m > .2

The t-test equivalent of this hypothesis would be:

H0: u = .2
HA: u > .2

(If we were measuring mean values)

The key difference being that Wilcox Signed Rank Test is testing median values, while the t-test is testing mean values.

With our hypothesis created, we can assess that mu = .2, and that this test will be right tailed.

Within the R platform, the code required to perform this analysis is as follows:

# Wilcox Signed Rank Test (One Sample) #

N <- c(.27, .31, .27, .34, .40, .29, .37, .14, .30, .20)

wilcox.test(N, alternative="greater", mu= .2, conf.level = 0.95)

# " alternative = " Specifies the type of test that R will perform. "greater" indicates a right tailed test. "left" indicates a left tailed test."two.sided" indicates a two tailed test. #


Which produces the output:

Wilcoxon signed rank test with continuity correction

data: N
V = 44, p-value = 0.006386
alternative hypothesis: true location is greater than 0.2


Warning messages:
1: In wilcox.test.default(N, alternative = "greater", mu = 0.2, conf.level = 0.95) :
cannot compute exact p-value with ties
2: In wilcox.test.default(N, alternative = "greater", mu = 0.2, conf.level = 0.95) :
cannot compute exact p-value with zeroes


You can ignore the error messages. Due to two values being similar within our data set, R could not assign the values separate ranks. Since ranking in a primary component of the model’s analysis, the R console is making you aware that these similarities exist. Also, since the Wilcox Signed Rank Test relies on the differences of two data values to derive these ranks, you are being informed that there is no secondary values from which to create these values. To understand exactly what this means, you will first have to learn how to derive the results of this test by hand.

V = The sum of ranks assigned to the differences of positive values derived from the initial values of the data. This would be the value of the T+ variable if calculating the test by hand. This value provides no additional significance pertaining to analysis.

Since the p-value is less than .05, we conclude that at a 95% confidence interval, that the cakes that are being produced contain an excess amount of corn syrup.

The t-test equivalent of this analysis would resemble:

(If we were measuring mean values)

N <- c(.27, .31, .27, .34, .40, .29, .37, .14, .30, .20)

t.test(N, alternative = "greater", mu = .2, conf.level = 0.95)

# " alternative = " Specifies the typer of test that R will perform. "greater" indicates a right tailed test. "left" indicates a left tailed test."two.sided" indicates a two tailed test. #


Which would produce the output:

data: N
t = 3.6713, df = 9, p-value = 0.002572
alternative hypothesis: true mean is greater than 0.2
95 percent confidence interval:
0.244562 Inf
sample estimates:
mean of x
0.289


From observing the output of both tests, you can witness the slight differentiation of p-values provided by the two analysis methods: p-value = 0.006386 (Wilcox) vs. 0.002572 (T-Test).

Wilcox Signed Rank Test (Two Sample)

As mentioned previously, the Wilcox Signed Rank Test is the non-parametric alternative to the Paired Student’s T-Test.

Example:

A watch manufacturer believes that by changing to a new battery supplier, that the watches that are shipped which include an initial battery, will maintain longer lifespan. To test this theory, twelve watches are tested for duration of lifespan with the original battery.

The same twelve watches are then re-rested for duration with the new battery.

Can the watch manufacturer conclude, that the new battery increases the duration of lifespan for the manufactured watches? (We will assume an alpha value of .05).

For this, we will utilize the code:

N1 <- c(376, 293, 210, 264, 297, 380, 398, 303, 324, 368, 382, 309)
N2 <- c(337, 341, 316, 351, 371, 440, 312, 416, 445, 354, 444, 326)

wilcox.test(N2, N1, alternative = "greater", paired=TRUE, conf.level = 0.95 )


Which produces the output:

Wilcoxon signed rank test

data: N2 and N1
V = 66, p-value = 0.01709
alternative hypothesis: true location shift is greater than 0


With a p-value of 0.01709 (0.01709 < .05), we can conclude that, at a 95% confidence interval, that the new battery increases the duration of lifespan for the manufactured watches.

The t-test equivalent of this analysis would resemble:

(If we were measuring mean values)

N1 <- c(376, 293, 210, 264, 297, 380, 398, 303, 324, 368, 382, 309)
N2 <- c(337, 341, 316, 351, 371, 440, 312, 416, 445, 354, 444, 326)

t.test(N2, N1, alternative = "greater", paired=TRUE, conf.level = 0.95 )


Which would produce the output:

Paired t-test

data: N2 and N1
t = 2.4581, df = 11, p-value = 0.01589
alternative hypothesis: true difference in means is greater than 0
95 percent confidence interval:
12.32551 Inf
sample estimates:
mean of the differences
45.75


From observing the output of both tests, you can witness the slight differentiation of p-values provided by the two analysis methods: p-value = 0.01709 (Wilcox) vs. 0.01589 (T-Test).

Below are the steps necessary to perform the above analysis within the SPSS platform.

Wilcox Signed Rank Test (One Sample) Example:

For the first example, we will assume that the individuals conducting the research are searching for a general fluctuation in the data. The reason for this change in methodology, is due to the limitations of the SPSS platform. SPSS cannot perform Wilcox Signed Rank Tests for a single tailed hypothesis. Therefore, to illustrate for functionality, our example will be two tailed.

Below is our example data set:


From the “Analyze” menu, select “Nonparametric Tests”, then select “One Sample”.




The following menu should appear:


With the “Fields” tab selected, click the center arrow to move the variable “N1” into the “Test Fields” area. Once this has been completed, click on the “Settings” tab.


Once the “Settings” tab has been selected, click on the button located next to “Customize Tests”. Once this option has been specified, click on the box located next to “Compare median to hypothesized (Wilcox signed-rank test)”. Enter the “Hypothesized median” value of .02 into the adjacent box. After this step has been completed, click “Run”.

This should generate the output below:


Given in this diagram is the null hypothesis, the type of test that was conducted, the p-value coinciding with our test results (Sig.), and the decision which pertains to the p-value of the hypothesis.

In the case of our example, the null hypothesis is being rejected as our p-value is equal to .011.

Wilcox Signed Rank Test (Two Sample) Example:

For the second example, we will again assume that the individuals conducting the research are searching for a general fluctuation in the data. The reason for this change in methodology, is due to the limitations of the SPSS platform. SPSS cannot perform Wilcox Signed Rank Tests for a single tailed hypothesis. Therefore, to illustrate for functionality, our example will be two tailed.

Below is our sample data set:


To begin analysis, from the “Analyze” menu, select “Nonparametric Tests”, then select “Legacy Dialogs”, followed by “2 Related Samples”.


This should cause the menu below to appear:


Through the utilization of the center arrow button, move both variables to their appropriate pair destination on the right side of the screen. Once this has been completed, click “OK”. Performing this sequence of actions will create model output.


The figure contained in the “Test Statistics” which is labeled “Asymp. Sig. (2-tailed)” is the figure that we will be investigating. It is worth mentioning, that the Wilcox Signed Rank Test is calculated slightly differently in SPSS, as compared to R. The differentiation between the methodologies of calculation becomes apparent when there are ties amongst ranks, or when zero values are contained with the calculation used to generate the analysis.

With a p-value that is less than .05 (0.034 < .05), we can conclude that at a 95% confidence interval, that the new battery is impacting the duration of lifespan for the manufactured watches.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.